drei
drei copied to clipboard
Updating Effects + disableGamma for recent three.js versions
Context:
-
https://discourse.threejs.org/t/i-still-dont-get-how-unrealbloompass-works/57843/2
-
threeversion: r158 -
@react-three/dreiversion: v9.88.11
Problem description:
By default <Effects /> adds a GammaCorrectionShader. In recent versions of three.js it would be preferable to use OutputPass, and it may confuse users who intentionally use OutputPass or GammaCorrectionShader that they have to do disableGamma={true} to avoid redundancy.
Relevant code:
https://github.com/pmndrs/drei/blob/1169c02fcfd1151fa08effb4ca7215f91b140f53/src/core/Effects.tsx#L92-L93
Suggested solution:
Perhaps Effects.tsx could scan its passes, and append GammaCorrectionShader or OutputPass only if neither is present? Would it also be reasonable to replace GammaCorrectionShader with OutputPass in a future release?
I realize I haven't implemented OutputPass in pmndrs/three-stdlib yet. I'll do that now.
Is it breaking to switch from GammaCorrectionShader to OutputPass? We're not pulling from three.js so it would be strictly behavioral. I'd need to add fallbacks for older color-management/encoding workflows if we go this way.
The differences are:
- GammaCorrectionShader applies the Linear-sRGB to sRGB transform unconditionally
- OutputPass applies color space and tone mapping according to the current values of
renderer.outputColorSpaceandrenderer.toneMapping
Strictly that is a breaking change. The impact should be fairly limited in the newer three.js versions, where .outputColorSpace / .outputEncoding defaults to sRGB, as R3F has done by default for a while. OutputPass was added in r153, and I don't think it is currently compatible with three.js versions before r152.