Three js - Cloning a shader and changing uniform values

ⅰ亾dé卋堺 提交于 2019-12-03 11:33:45

The reason this doesn't work is the default Three.js lambert shader uses the preprocessor macro directive #ifdef to determine whether to use maps, envmaps, lightmaps, etc etc.

The Three.js WebGLRenderer sets the appropriate preprocessor directives (#define) to enable these pieces of the shaders based on whether certain properties exist on the material object.

If you're set on taking the approach of cloning & modifying the default shaders, you will have to set relevant properties on the material. For texture maps, the Three.js WebGLRenderer.js has this line:

parameters.map ? "#define USE_MAP" : ""

So try setting material.map = true; for your shader material.

Of course, if you know you're going to be writing your own shader and you don't need the dynamic inclusion of various shader snippets, you can just write the shader explicitly and you won't need to worry about this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!