Monday, 19 August 2013

Custom Normal plugin won't draw objects if previous material is BasicMaterial

Custom Normal plugin won't draw objects if previous material is BasicMaterial

I've been working on a deffered renderer for my application. In order for
my application to render correctly I need to draw position, depth and
normal maps of the scene. To render these 3 render targets I took the same
approach as was done for the depth pass plugin.
In the depth plugin, each of the objects to be rendered is replaced with a
depth material that draws the object onto the render target. I.e just
before rendering it does this:
if ( useSkinning )
material = useMorphing ? skinMorphMat : skinMat;
else if ( useMorphing )
material = morphMat;
else
material = mat;
I wanted to use the same method, but instead draw normal maps. To do this
I copied the 'normal' shader so that it supported animation and alpha
testing ( I cant use the normal map material as it doesn't support these
features - so I had to create a Shader Material with my new custom shader
).
However when I pass my ShaderMaterial to the renderer, nothing is drawn
when the object's previous material was a basic material. The reason for
this, as I understand it, is because when a basic material is applied on
an object the function 'bufferGuessNormalType' returns false and so the
mesh never has normals generated for it.
So is there a way to ensure that even if the previous material is basic,
normal are generated?

No comments:

Post a Comment