I'm maintaining a vertex shader encapsulated in a custom material class (inherited from ShaderMaterial
but now from MeshStandardMaterial
) which convert 3D coordinate to NDC as usual:
vec4 ndcPos = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
ndcPos /= ndcPos.w;
//...other transformations to ndcPos
then a set of transformations are applied to ndcPos
. As you can see they are applied in NDC space. I need to take the result coordinate back to camera (eye) space so I guess we need to inverse the steps, something like this:
vec4 mvPos = ndcPos * ndcPos.w;
mvPos *= inverse of projectionMatrix;
Expected result: mvPos
has only the modelView transformation applied.
Questions:
- Is that correct?
- How to compute inverse of
projectionMatrix
? It would be easy and low-cost passing thecamera.projectionMatrixInverse
as uniform to the vertex shader but I didn't find a way to do so in three.js: neither ancestor material classes, noronBeforeCompile
can access the camera.