Accessing viewMatrix in main program

Hi, I need to access viewMatrix in the main program to compute another matrix(called cameraToLightSpace) that transforms the point from camera to light space. I then pass cameraToLightSpace matrix to the shader, because making this computation in the shader would be more expensive. How do I access viewMatrix in the main program and also ensure it is updated each draw call?

The equation I am using for the computation:
cameraToLightSpace = lightProjectionMatrix * lightVIewMatrix * inverse(viewMatrix);

Also I am using glMatrix API for these matrix computation. Is there a more efficient way to do the same?

Are you looking for this?

// = camera.matrixWorldInverse
uniform mat4 viewMatrix;
1 Like

If you need the view matrix in JS, it’s Camera.matrixWorldInverse.


Yes, Thank you !

Thank You !