Skip to content

Commit 07c01a9

Browse files
committed
WebGLRenderer: Apply premultiplied alpha in sRGB space.
1 parent 10a6332 commit 07c01a9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/renderers/shaders/ShaderChunk/opaque_fragment.glsl.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ diffuseColor.a *= material.transmissionAlpha;
99
1010
#ifdef PREMULTIPLIED_ALPHA
1111
12-
gl_FragColor = vec4( outgoingLight * diffuseColor.a, diffuseColor.a );
12+
// Convert to sRGB, apply premultiplied alpha, convert back to linear.
13+
// This ensures correct blending in sRGB framebuffers.
14+
vec3 srgb = sRGBTransferOETF( vec4( outgoingLight, 1.0 ) ).rgb;
15+
srgb *= diffuseColor.a;
16+
gl_FragColor = vec4( sRGBTransferEOTF( vec4( srgb, 1.0 ) ).rgb, diffuseColor.a );
1317
1418
#else
1519

0 commit comments

Comments
 (0)