at this moment I am learning to do shadow mapping in webgl2.0, i was able to generate my first shadows in my 3D scene but I have a couple of doubts to clarify. This is the way im calculating my light space matrix:

const lightPos = vec3.create();
vec3.set(lightPos, 0, 6, 1);
const nearPlane = 1, farPlane = 20;
const projection = mat4.create();
mat4.ortho(projection, -10, 10, -10, 10, nearPlane, farPlane);
const lightView = mat4.create();
const center = vec3.create();
const up = vec3.create();
vec3.set(center, 0, 0, 0);
vec3.set(up, 0, 1, 0);
mat4.lookAt(lightView, lightPos, center, up);
const result = mat4.create();
mat4.mul(result, projection, lightView);

In this way the shadow map is rendered correctly, but the question is the following, if the position of my light is vec3.set(lightPos, 0, 6, 0), the shadow does not render, why is this happening? Theoretically I am positioning the light in the middle, directly 6 units above the scene, why is this happening? As far as I understood, 2 of the properties of the position vector of the light cannot be 0, but why?. I hope I explained myself well, the light is a directional light and the library that im using for the math is gl-matrix, if you need anything else let me know, thanks in advance.

  • $\begingroup$ There is absolutely no reason why a light source can't be axis aligned. Looking directly down any axis. $\endgroup$
    – pmw1234
    Feb 25, 2023 at 22:43
  • $\begingroup$ Exacly, but the shadow map is all white when i put the light in that position $\endgroup$ Feb 27, 2023 at 2:47
  • $\begingroup$ So 2 of the position vectors of the light can be zero hence looking directly down an axis. In light space it tends to be better to have an axis aligned light. $\endgroup$
    – pmw1234
    Feb 27, 2023 at 10:43

1 Answer 1


I might be wrong here, but the "up" vector must be linearly independent of the light direction in order to create a proper 3-dimensional light space. When the light position is $(0,6,0)$, the light direction becomes $(0,-6,0)$ which is parallell with the "up" vector $(0,1,0)$. Note that the cross-product between two parallell vectors maps to the zero vector, so the resulting light space becomes 1 dimensional.

  • $\begingroup$ When creating an orthogonal 3D space, you need to specify two vectors that are linearly independent (technically there is a hidden assumption here as well). If you ask someone to create a 3D coordinate system where the only information is that the z-direction is your light direction, there is an infinite amount of answers. $\endgroup$
    – Mathis
    Mar 6, 2023 at 15:36
  • 1
    $\begingroup$ Actually I read your post to quickly and agree with what it says I deleted the comment. (I agree there is an infinite number of possible answers I was just giving an example of one) $\endgroup$
    – pmw1234
    Mar 6, 2023 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.