Fix T85720 EEVEE: Contact shadows do not appear when enabling SSR

Contact shadows needed correct `gl_FragCoord.z` but this is not
correctly set for fullscreen passes. Need to pass depth using a global
variable until we get rid of `cl_eval.tracing_depth`.
This commit is contained in:
Clément Foucault 2021-02-22 16:59:18 +01:00
parent 1ec626f4bd
commit cd1a083984
Notes: blender-bot 2023-02-14 09:48:25 +01:00
Referenced by issue #85908, EEVEE 2.93 Incorrect glossy values
Referenced by issue #85720, EEVEE screen space reflections dont mix properly
2 changed files with 10 additions and 1 deletions

View File

@ -196,6 +196,9 @@ struct ClosureOutput {
vec3 radiance;
};
/* Workaround for screenspace shadows in SSR pass. */
float FragDepth;
ClosureEvalCommon closure_Common_eval_init(ClosureInputCommon cl_in)
{
ClosureEvalCommon cl_eval;
@ -208,11 +211,15 @@ ClosureEvalCommon closure_Common_eval_init(ClosureInputCommon cl_in)
cl_eval.Ng = safe_normalize(cross(dFdx(cl_eval.P), dFdy(cl_eval.P)));
cl_eval.vNg = transform_direction(ViewMatrix, cl_eval.Ng);
/* TODO(fclem) See if we can avoid this complicated setup. */
#ifdef STEP_RESOLVE /* SSR */
cl_eval.tracing_depth = FragDepth;
#else
cl_eval.tracing_depth = gl_FragCoord.z;
#endif
/* Constant bias (due to depth buffer precision) */
/* Magic numbers for 24bits of precision.
* From http://terathon.com/gdc07_lengyel.pdf (slide 26) */
cl_eval.tracing_depth -= mix(2.4e-7, 4.8e-7, gl_FragCoord.z);
cl_eval.tracing_depth -= mix(2.4e-7, 4.8e-7, cl_eval.tracing_depth);
/* Convert to view Z. */
cl_eval.tracing_depth = get_view_z_from_depth(cl_eval.tracing_depth);

View File

@ -569,6 +569,8 @@ void main()
discard;
}
FragDepth = depth;
viewPosition = get_view_space_from_depth(uvcoordsvar.xy, depth);
worldPosition = transform_point(ViewMatrixInverse, viewPosition);