Tone mapping/color issues with custom ShaderMaterial

I’ve got a basic code sandbox that demonstrates the issue I’m having here:
https://codesandbox.io/p/sandbox/n9jshy

The colors of the equirectangular projection seem to be off from the original scene. They seem darker/more saturated compared to the original scene. You can really see this in the orange, purple, and green cube faces.

I’m assuming this has something to do with the fact that the projected image is being applied as a texture to a plane and rendered again on the plane mesh. Or maybe the problem is related to the shader? Is there a more direct way that I could be writing the equirectangular projection directly to the canvas instead of mapping it on to a plane first?

Any insight here would be appreciated!

After assigning gl_FragColor you’ll need the following two lines in your ShaderMaterial fragment shader:

#include <tonemapping_fragment>
#include <colorspace_fragment>

These handle conversion to the canvas color space and tone mapping (if any).

EDIT: Updated to fix the order of the shader includes.

1 Like

That works perfectly! Thank you!

This does seem to cause a problem if the toneMapping changes on the renderers though. It’s almost like the tone mapping gets applied twice.

It looks like this can be fixed by changing the order of these includes:

#include <tonemapping_fragment>
#include <colorspace_fragment>
1 Like

Oops, yes you’re correct – the tonemapping chunk should come first thanks.