I couldn’t find an example in the official example where the specified texture is empty. I tried to modify the setTexture parameter to null or ‘’ in the official example myself, but it didn’t work. How do I write it
You can’t unbind a texture: if a shader expects a texture, you must provide one. If you don’t need the texture anymore, it means the shader code should be updated, because you can’t use texture(sampler, uvCoordinates)
anymore and must replace it with something else.
May I ask how I can determine in the shader whether to fill the texture with another attribute when it is empty, or to replace it with another element at the input level when the texture is empty
You can use define to do it. When you set texture, you add texture define, when you remove texture, remove define at same time.
vec3 xxxColor = vec3(1.);
#ifdef XXX
xxxColor = texture2D(xxxSampler,uv).rgb;
#endif
Here’s an example:
After 3s, the HAS_TEXTURE
define is removed and the fragment shader code won’t use the texture anymore.