Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So, the solution was to convert the light-to-fragment vector to a depth value, instead of converting the depth read from the cubemap into a distance.</p> <p>Here is the modified shader code:</p> <pre><code>float VectorToDepthValue(vec3 Vec) { vec3 AbsVec = abs(Vec); float LocalZcomp = max(AbsVec.x, max(AbsVec.y, AbsVec.z)); const float f = 2048.0; const float n = 1.0; float NormZComp = (f+n) / (f-n) - (2*f*n)/(f-n)/LocalZcomp; return (NormZComp + 1.0) * 0.5; } float ComputeShadowFactor(samplerCubeShadow ShadowCubeMap, vec3 VertToLightWS) { float ShadowVec = texture(ShadowCubeMap, vec4(VertToLightWS, 1.0)); if (ShadowVec + 0.0001 &gt; VectorToDepthValue(VertToLightWS)) return 1.0; return 0.0; } </code></pre> <p>Explaination on <code>VectorToDepthValue(vec3 Vec)</code> :</p> <p><code>LocalZComp</code> corresponds to what would be the Z-component of the given <code>Vec</code> into the matching frustum of the cubemap. It's actually the largest component of <code>Vec</code> (for instance if Vec.y is the biggest component, we will look either on the Y+ or the Y- face of the cubemap).</p> <p>If you look at this <a href="http://en.wikipedia.org/wiki/Z-buffering#Mathematics">wikipedia article</a>, you will understand the math just after (I kept it in a formal form for understanding), which simply convert the <code>LocalZComp</code> into a normalized Z value (between in [-1..1]) and then map it into [0..1] which is the actual range for depth buffer values. (assuming you didn't change it). <code>n</code> and <code>f</code> are the near and far values of the frustums used to generate the cubemap.</p> <p><code>ComputeShadowFactor</code> then just compare the depth value from the cubemap with the depth value computed from the fragment-to-light vector (named <code>VertToLightWS</code> here), also add a small depth bias (which was missing in the question), and returns 1 if the fragment is not occluded by the light.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload