zadvorsky / three.bas

THREE.JS Buffer Animation System

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Shadows and defines (bug?)

taseenb opened this issue · comments

I am using StandardAnimationMaterial and found a problem with shadows BAS.Utils.createDepthAnimationMaterial and BAS.Utils.createDistanceAnimationMaterial.
Custom #define are not added to the shader, so i get the error: 'SIZE' : undeclared identifier.

If I fix the "defines", by adding them manually, i get 'objectNormal' : undeclared identifier. I know objectNormal is a Three.js shader chunk, so I suppose it's not imported for some reason.

NOTE: this only happens if i add a light and set castShadow to true and the renderer has shadowMap enabled. Otherwise everything works fine (but no shadows!).

I have added defines to BAS.Utils.createDepthAnimationMaterial and BAS.Utils.createDistanceAnimationMaterial. Up in version 2.0.2.

Not sure about the objectNormal error. Were you replacing the defines object after creating the shadow materials?

Thanks. I tried it and that actually fixed the issue with the defines, but i still don't understand what happens with transformedNormal and objectNormal. I don't know how the chunks get imported, but when I try to add a value to one of those, i get an undeclared error, and if i create them myself, i get a redefinition error! Maybe something related to the imports?

I just checked the generated vertex shader and noticed that when USE_SHADOWMAP is NOT defined this chunk (for example) is included:

177: #ifdef USE_SHADOWMAP
178: 	#if 1 > 0
179: 		uniform mat4 directionalShadowMatrix[ 1 ];
180: 		varying vec4 vDirectionalShadowCoord[ 1 ];
181: 	#endif
182: 	#if 0 > 0
183: 		uniform mat4 spotShadowMatrix[ 0 ];
184: 		varying vec4 vSpotShadowCoord[ 0 ];
185: 	#endif
186: 	#if 0 > 0
187: 		uniform mat4 pointShadowMatrix[ 0 ];
188: 		varying vec4 vPointShadowCoord[ 0 ];
189: 	#endif
190: #endif

When USE_SHADOWMAP is defined that chunk is not there (and other parts seem missing, the file is shorter with shadow maps enabled, which seems weird?).

To answer your question, I create the StandardAnimationMaterial with the defines already, and don't change anything after (apart from creating the shadow material).

This is the line missing when USE_SHADOWMAP is defined:

vec3 objectNormal = vec3( normal );

https://github.com/mrdoob/three.js/blob/master/src/renderers/shaders/ShaderChunk/beginnormal_vertex.glsl

and this:

vec3 transformedNormal = normalMatrix * objectNormal;

#ifdef FLIP_SIDED

	transformedNormal = - transformedNormal;

#endif

https://github.com/mrdoob/three.js/blob/master/src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl

Could you provide a link to where this occurs? Will be easier for me to debug.

I modified your Standard Material example w shadows in my fork: https://github.com/taseenb/three.bas/blob/master/examples/materials_standard/main.js

Going to close this to clean up the old open issues.