Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ol> <li><p>Using the light-to-vertex vector as you assumed should indeed be the correct vector to use as texture coordinate.</p></li> <li><p>You can also just store a linear depth into the depth texture, by simply writing the distance of the vertex to the light source (divided by some known maximum light influence distance to transform it into [0,1]) into <code>gl_FragDepth</code> in the first 6 passes, istead of the vertex's projected depth. This way you can just use the vertex's distance to the light in the depth comparison without the need to project anything into light-space. This way you don't need to keep track of 6 different matrices and select the correct one to use for each vertex or fragment.</p></li> </ol> <p><strong>EDIT:</strong> It seems you cannot write into <code>gl_FragDepth</code> in ES, which makes rendering your own depth a bit more complicated. Just rendering into a normal texture won't do as the 8-bits of precision per channel are just too small in practice.</p> <p>But you should be able to linearize the depth in the vertex shader, by just storing the vertex-to-light distance in the vertex's z component (transformed into [-1,1]) multiplied by it's w-component, which is then later divided by w and transformed into [0,1] by the rasterizer to gain the fragment's depth:</p> <pre><code>uniform mat4 lightModelView; uniform mat4 lightProjection; unfiorm float maxLightDistance; attribute vec4 vertex; void main() { vec4 lightSpaceVertex = lightModelView * vertex; float lightDistance = length(lightSpaceVertex.xyz) / maxLightDistance; gl_Position = lightProjection * lightSpaceVertex; gl_Position.z = (2.0*lightDistance-1.0) * gl_Position.w; } </code></pre> <p>It may be optimizable by just changing the light's projection matrix accordingly, but this code (in conjunction with a simple pass-through fragment shader) should store the linear light-to-vertex distance into the depth buffer, if I'm not on a completely wrong track here. It just multiplies the vertex's z by it's w and should therefore counter the perspective division step which would result in a non-linear depth value (and it also counters the transformation from [-1,1] to [0,1], of course).</p> <p><strong>EDIT:</strong> According to your new problems: First of all, I hope your light is located at (eyeX, eyeY, eyeZ) as the camera for the shadow map generation has to be located at the light's position, of course. If (eyeX, eyeY, eyeZ) is actually the position of your (normal) scene camera, then this is of course wrong and you should use (lightX, lightY, lightZ) instead.</p> <p>Next, you should of course use a FoV (field of view) of exactly 90 degrees for the light's views, so the projection matrix should be generated somehow similar to this:</p> <pre><code>glFrustum(-near, near, -near, near, near, far); </code></pre> <p>or this:</p> <pre><code>gluPerspective(90, 1, near, far); </code></pre>
    singulars
    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.
 

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