How to change fragmentShader of ShaderMaterial?

How to efficiently change fragmentShader of an already created ShaderMaterial?
More specifically, a #define or a const of the fragmentShader. ( the #define or const is used in for loop)
Must I create a new ShaderMaterial?

Well, you just modify the fragment shader source and then set needsUpdate to true. Can you give this a try?

2 Likes

It’s OK. Thanks!

mtl.fragmentShader=mtl.fragmentShader.replace('const int XXX=50;','const int XXX=10;');
mtl.needsUpdate=true;