Skip to content

Commit

Permalink
fix(Material): sRGB decoding for VideoTexture .emissiveMap (#29657)
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy authored Oct 15, 2024
1 parent a9f7169 commit 752400c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ vec4 LinearTransferOETF( in vec4 value ) {
return value;
}
vec4 sRGBTransferEOTF( in vec4 value ) {
return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a );
}
vec4 sRGBTransferOETF( in vec4 value ) {
return vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ export default /* glsl */`
vec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv );
#ifdef DECODE_VIDEO_TEXTURE_EMISSIVE
// use inline sRGB decode until browsers properly support SRGB8_ALPHA8 with video textures (#26516)
emissiveColor = sRGBTransferEOTF( emissiveColor );
#endif
totalEmissiveRadiance *= emissiveColor.rgb;
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/renderers/shaders/ShaderChunk/map_fragment.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export default /* glsl */`
// use inline sRGB decode until browsers properly support SRGB8_ALPHA8 with video textures (#26516)
sampledDiffuseColor = vec4( mix( pow( sampledDiffuseColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), sampledDiffuseColor.rgb * 0.0773993808, vec3( lessThanEqual( sampledDiffuseColor.rgb, vec3( 0.04045 ) ) ) ), sampledDiffuseColor.w );
sampledDiffuseColor = sRGBTransferEOTF( sampledDiffuseColor );
#endif
diffuseColor *= sampledDiffuseColor;
Expand Down
1 change: 1 addition & 0 deletions src/renderers/webgl/WebGLProgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
parameters.numLightProbes > 0 ? '#define USE_LIGHT_PROBES' : '',

parameters.decodeVideoTexture ? '#define DECODE_VIDEO_TEXTURE' : '',
parameters.decodeVideoTextureEmissive ? '#define DECODE_VIDEO_TEXTURE_EMISSIVE' : '',

parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
parameters.reverseDepthBuffer ? '#define USE_REVERSEDEPTHBUF' : '',
Expand Down
5 changes: 4 additions & 1 deletion src/renderers/webgl/WebGLPrograms.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
toneMapping: toneMapping,

decodeVideoTexture: HAS_MAP && ( material.map.isVideoTexture === true ) && ( ColorManagement.getTransfer( material.map.colorSpace ) === SRGBTransfer ),
decodeVideoTextureEmissive: HAS_EMISSIVEMAP && ( material.emissiveMap.isVideoTexture === true ) && ( ColorManagement.getTransfer( material.emissiveMap.colorSpace ) === SRGBTransfer ),

premultipliedAlpha: material.premultipliedAlpha,

Expand Down Expand Up @@ -558,8 +559,10 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
_programLayers.enable( 18 );
if ( parameters.decodeVideoTexture )
_programLayers.enable( 19 );
if ( parameters.alphaToCoverage )
if ( parameters.decodeVideoTextureEmissive )
_programLayers.enable( 20 );
if ( parameters.alphaToCoverage )
_programLayers.enable( 21 );

array.push( _programLayers.mask );

Expand Down

0 comments on commit 752400c

Please sign in to comment.