Feedback

What's your question?

By: [ Editor ] Asked

How can I make a maya shader that renders object space normals?

I need to record the normal direction of faces on a mesh in object space. Is there a native maya shader that would capture this information in a render?

Thanks for looking

Add comment viewed 536 times Latest activity 8 months ago

or Cancel

1 answer

  • 1

julian [ Admin ]

This should work:

  1. create a multMatrix node
  2. connect the camera.worldMatrix to multMatrix.matrixIn[ 0 ]
  3. connect your object.worldInverseMatrix to multMatrix.matrixIn[ 1 ]
  4. create a pointMatrixMult node and a samplerInfo node
  5. connect the multMatrix.matrixSum to pointMatrixMult.inMatrix
  6. connect the samplerInfo.normalCamera to pointMatrixMult.inPoint
  7. set pointMatrixMult.vectorMultiply on
  8. create a surfaceShader
  9. connect pointMatrixMult.output to the surfaceShader.outColor attribute
  10. attach the shader

It might not look right in the viewport, but when you render you should see that where the surface normal is facing the object's local X it will be red, local Y will be green, local Z will be blue. It will work where ever you put the camera or the object.

If you want the RGB aligned to XYZ world space, just plug the camera worldMatrix straight into the pointMatrixMult node.

The normals in negative XYZ will have negative RGB values, so you probably want to normalize the colors. You can make an expression:

surfaceShader1.outColorR = ((pointMatrixMult.outputX * 0.5) + 0.5);

and the same for green and blue...

normal shader graph

NN comments
leigh
-

Thats great Julian, thank you for taking the time with such a comprehensive answer, much appreciated

manny
-

This is awesome Julian. But it doesn’t seem like Mental Ray knows what to do with this network. :(

manny
-

Julian, I just tried to convert this to a file texture and the results weren’t correct. Any ideas why?

or Cancel