1
$\begingroup$

I'm trying to do shadow mapping but this is what is being rendered - looks like the shadow is on the cube in front of the wall as opposed to the shadow being cast on the wall.

The light is positioned looking straight down the z-axis, which is also where the surface and cube are positioned.

Does this look obvious as to what I'm doing wrong?

Here are my "regular" vertex and fragment shaders

// Vertex shader
        void main() {

            // world projection of vertex
            gl_Position = u_viewProjectionMatrix * u_worldMatrix * a_position;

            // surface to light vector - passed to frag shader and interpolated for each
            v_positionFromLight = u_lightViewProjectionMatrix * u_worldMatrix * a_position;

            // pass through to the fragment shader
            v_normal = mat3(u_worldMatrix) * a_normal;
        }

// Fragment shader
    void main() {
            // determine our shadows - base lighting
            vec3 shadowCoord = (v_positionFromLight.xyz / v_positionFromLight.w) / 2.0 + 0.5;
            vec4 rgbaDepth = texture(u_texture, shadowCoord.xy);
            float visibility = (shadowCoord.z > rgbaDepth.r + 0.005) ? 0.6 : 1.0;

            // determine light over normals
            // vec3 normal = normalize(v_normal);

            // float light = dot(normal, normalize(vec3(0, 0, 100)));
            vec4 color = vec4(.5, .25, .5, 1);
            outColor = vec4( color.rgb * visibility, color.a );
        }

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.