Skip to content

Commit 6c62b9c

Browse files
authored
VideoTexture: Restore inline sRGB decode. (#26521)
1 parent 42beb76 commit 6c62b9c

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
export default /* glsl */`
22
#ifdef USE_MAP
33
4-
diffuseColor *= texture2D( map, vMapUv );
4+
vec4 sampledDiffuseColor = texture2D( map, vMapUv );
5+
6+
#ifdef DECODE_VIDEO_TEXTURE
7+
8+
// use inline sRGB decode until browsers properly support SRGB8_APLHA8 with video textures
9+
10+
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 );
11+
12+
#endif
13+
14+
diffuseColor *= sampledDiffuseColor;
515
616
#endif
717
`;

src/renderers/shaders/ShaderLib/background.glsl.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ void main() {
2121
2222
vec4 texColor = texture2D( t2D, vUv );
2323
24+
#ifdef DECODE_VIDEO_TEXTURE
25+
26+
// use inline sRGB decode until browsers properly support SRGB8_APLHA8 with video textures
27+
28+
texColor = vec4( mix( pow( texColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), texColor.rgb * 0.0773993808, vec3( lessThanEqual( texColor.rgb, vec3( 0.04045 ) ) ) ), texColor.w );
29+
30+
#endif
31+
2432
texColor.rgb *= backgroundIntensity;
2533
2634
gl_FragColor = texColor;

src/renderers/webgl/WebGLProgram.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,8 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
765765

766766
parameters.useLegacyLights ? '#define LEGACY_LIGHTS' : '',
767767

768+
parameters.decodeVideoTexture ? '#define DECODE_VIDEO_TEXTURE' : '',
769+
768770
parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
769771
( parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
770772

src/renderers/webgl/WebGLPrograms.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BackSide, DoubleSide, CubeUVReflectionMapping, ObjectSpaceNormalMap, TangentSpaceNormalMap, NoToneMapping, NormalBlending, LinearSRGBColorSpace } from '../../constants.js';
1+
import { BackSide, DoubleSide, CubeUVReflectionMapping, ObjectSpaceNormalMap, TangentSpaceNormalMap, NoToneMapping, NormalBlending, LinearSRGBColorSpace, SRGBColorSpace } from '../../constants.js';
22
import { Layers } from '../../core/Layers.js';
33
import { WebGLProgram } from './WebGLProgram.js';
44
import { WebGLShaderCache } from './WebGLShaderCache.js';
@@ -335,6 +335,8 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
335335
toneMapping: toneMapping,
336336
useLegacyLights: renderer._useLegacyLights,
337337

338+
decodeVideoTexture: HAS_MAP && ( material.map.isVideoTexture === true ) && ( material.map.colorSpace === SRGBColorSpace ),
339+
338340
premultipliedAlpha: material.premultipliedAlpha,
339341

340342
doubleSided: material.side === DoubleSide,
@@ -536,6 +538,8 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
536538
_programLayers.enable( 17 );
537539
if ( parameters.pointsUvs )
538540
_programLayers.enable( 18 );
541+
if ( parameters.decodeVideoTexture )
542+
_programLayers.enable( 19 );
539543

540544
array.push( _programLayers.mask );
541545

src/renderers/webgl/WebGLTextures.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
748748
glFormat = utils.convert( texture.format, texture.colorSpace );
749749

750750
let glType = utils.convert( texture.type ),
751-
glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace );
751+
glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace, texture.isVideoTexture );
752752

753753
setTextureParameters( textureType, texture, supportsMips );
754754

@@ -2027,7 +2027,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
20272027
const format = texture.format;
20282028
const type = texture.type;
20292029

2030-
if ( texture.isCompressedTexture === true || texture.format === _SRGBAFormat ) return image;
2030+
if ( texture.isCompressedTexture === true || texture.isVideoTexture === true || texture.format === _SRGBAFormat ) return image;
20312031

20322032
if ( colorSpace !== LinearSRGBColorSpace && colorSpace !== NoColorSpace ) {
20332033

0 commit comments

Comments
 (0)