Texture in ShaderMaterial is always black

Here ist my example: strange-shaw-w5pee7 - CodeSandbox

My goal, I want to use the ShaderMaterial to remove the red and blue color channel and only show the green one. This is a small example, as my actual goal is to combine the different color channels of multiple textures.

As you can see, the image loads find, but in the shader, I get zeros for all values, therefore the purple result (only red and blue). Any idea why?

Cheers, Michael

If you modify the code so that the texture object updates immediately, you’ll get a cross-origin error. I’m not sure why it doesn’t show this error immediately, but it may be related.


Usually, setting baseImage.crossOrigin = "anonymous"; should fix this, but I think your host won’t allow this, since the onerror event is triggered when you try this.


Thank you! That was actually the issue, I changed my example according to your comments and with a different image that allows this, it works now.

1 Like