- Home /
Grabpass refraction masking
Hey everyone,
I am trying to solve the grabpass front object issue with some depth masking but I am facing some difficulties in forward rendering. Here are some interesting parts : Code (CSharp):
// Vertex function
UNITY_INITIALIZE_OUTPUT(Input, o);
float4 pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.depthCoord = ComputeScreenPos(pos);
COMPUTE_EYEDEPTH(o.depthCoord.z);
o.grabCoord = ComputeGrabScreenPos(pos);
// Surface function
// Offset
half2 offset = o.Normal * _Refraction * _Grab_TexelSize.xy;
// Masking
IN.depthCoord.xy = offset * IN.depthCoord.z + IN.depthCoord.xy;
half mask = step(IN.depthCoord.z, LinearEyeDepth(SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(IN.depthCoord))));
// Refraction
offset *= mask;
IN.grabCoord.xy = offset * IN.grabCoord.z + IN.grabCoord.xy;
half3 refraction = tex2Dproj(_Grab, UNITY_PROJ_COORD(IN.grabCoord));
This works well in deferred rendering but in forward it fails as the grabpass y coordinates are inverted. Any idea on how to solve this easely ? I would like to avoid creating a full image effect shader mask.
Thank a lot !
Comment