Andrea Aloi
Andrea Aloi

Reputation: 991

gl_ModelViewMatrixInverseTranspose in threejs

In my attemp to write my own custom shader (I am using a THREE.ShaderMaterial), I need to set its WebGL's built-in gl_ModelViewMatrixInverseTranspose uniform (as seen on http://mew.cx/glsl_quickref.pdf). I noticed some uniforms are already automatically passed to the shader, for instance gl_ModelViewMatrix and gl_ProjectionMatrix are already accounted for, by threejs' modelViewMatrix and projectionMatrix respectively. gl_ModelViewProjectionMatrix, on the other hand, seems to be missing, but I noticed some examples where it can easily be computed inside the shader as projectionMatrix * modelViewMatrix. So my question is: am I to manually compute gl_ModelViewMatrixInverseTranspose inside my shader starting from modelViewMatrix (and if so, how?) or is there a unform (possibily merged inside my definition of THREE.ShaderMaterial with THREE.UniformsUtils.merge) that already handles it? Cheers.

Upvotes: 2

Views: 1361

Answers (1)

Anton
Anton

Reputation: 12435

In a Three.js shader the inverse transpose of modelViewMatrix is called normalMatrix.

It is automatically passed into the shaders so you don't need to do any work to get it.

// = inverse transpose of modelViewMatrix
uniform mat3 normalMatrix;

For reference here are the built-in uniform and attributes Three.js has.

Upvotes: 2

Related Questions