How to use ifdef in BABYLON.PBRCustomMaterial

//maskoffset
#ifdef uvOffsetZDir 
vec2 posUv= vec2(vPosition.z,vPosition.z+_Time);
#endif
#ifdef uvOffsetXDir 
vec2 posUv= vec2(vPosition.x,vPosition.x+_Time);
#endif
#ifdef uvOffsetYDir
vec2 posUv= vec2(vPosition.y,vPosition.y+_Time);    
#endif

These are three directions offset, but how can I trigger them? For example, I want to use only the X direction in the material? I don’t understand how ifdef works in shaders

You can’t use custom defines in a PBRCustomMaterial: you should use a material plugin instead. See:

Note that you could also use a uniform and use regular ifs testing to choose the right variant.

2 Likes

thank you very much

vec2 posXUv= vec2(vPosition.x,vPosition.x+_Time)*vec2(x);
vec2 posYUv= vec2(vPosition.y,vPosition.y+_Time)*vec2(y);
vec2 posZUv= vec2(vPosition.z,vPosition.z+_Time)*vec2(z);
vec2 posUv = posXUv+posYUv+posZUv;

I tried using 1 and 0 to control the output, and it feels better than if. Thank you very much for your answer