Browse Source

WebGLRenderer: Enable usage of `SRGB8_ALPHA8` again. (#22952)

* WebGLRenderer: Enable usage of SRGB8_ALPHA8 again.

* Update screenshots.
Michael Herzog 3 years ago
parent
commit
25c7f7a1c9

+ 2 - 3
examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js

@@ -3,7 +3,7 @@ import SlotNode from './SlotNode.js';
 import GLSLNodeParser from '../../nodes/parsers/GLSLNodeParser.js';
 import GLSLNodeParser from '../../nodes/parsers/GLSLNodeParser.js';
 import WebGLPhysicalContextNode from './WebGLPhysicalContextNode.js';
 import WebGLPhysicalContextNode from './WebGLPhysicalContextNode.js';
 
 
-import { ShaderChunk /*, LinearEncoding, RGBAFormat, UnsignedByteType, sRGBEncoding */ } from '../../../../../build/three.module.js';
+import { ShaderChunk, LinearEncoding, RGBAFormat, UnsignedByteType, sRGBEncoding } from '../../../../../build/three.module.js';
 
 
 const shaderStages = [ 'vertex', 'fragment' ];
 const shaderStages = [ 'vertex', 'fragment' ];
 
 
@@ -286,7 +286,6 @@ class WebGLNodeBuilder extends NodeBuilder {
 
 
 	getTextureEncodingFromMap( map ) {
 	getTextureEncodingFromMap( map ) {
 
 
-		/*
 		const isWebGL2 = this.renderer.capabilities.isWebGL2;
 		const isWebGL2 = this.renderer.capabilities.isWebGL2;
 
 
 		if ( isWebGL2 && map && map.isTexture && map.format === RGBAFormat && map.type === UnsignedByteType && map.encoding === sRGBEncoding ) {
 		if ( isWebGL2 && map && map.isTexture && map.format === RGBAFormat && map.type === UnsignedByteType && map.encoding === sRGBEncoding ) {
@@ -294,7 +293,7 @@ class WebGLNodeBuilder extends NodeBuilder {
 			return LinearEncoding; // disable inline decode for sRGB textures in WebGL 2
 			return LinearEncoding; // disable inline decode for sRGB textures in WebGL 2
 
 
 		}
 		}
-*/
+
 		return super.getTextureEncodingFromMap( map );
 		return super.getTextureEncodingFromMap( map );
 
 
 	}
 	}

BIN
examples/screenshots/webgl_loader_md2.jpg


+ 3 - 4
src/extras/PMREMGenerator.js

@@ -9,6 +9,7 @@ import {
 	NoBlending,
 	NoBlending,
 	RGBDEncoding,
 	RGBDEncoding,
 	RGBEEncoding,
 	RGBEEncoding,
+	RGBAFormat,
 	RGBEFormat,
 	RGBEFormat,
 	RGBM16Encoding,
 	RGBM16Encoding,
 	RGBM7Encoding,
 	RGBM7Encoding,
@@ -349,7 +350,7 @@ class PMREMGenerator {
 
 
 	_setEncoding( uniform, texture ) {
 	_setEncoding( uniform, texture ) {
 
 
-		/* if ( this._renderer.capabilities.isWebGL2 === true && texture.format === RGBAFormat && texture.type === UnsignedByteType && texture.encoding === sRGBEncoding ) {
+		if ( this._renderer.capabilities.isWebGL2 === true && texture.format === RGBAFormat && texture.type === UnsignedByteType && texture.encoding === sRGBEncoding ) {
 
 
 			uniform.value = ENCODINGS[ LinearEncoding ];
 			uniform.value = ENCODINGS[ LinearEncoding ];
 
 
@@ -357,9 +358,7 @@ class PMREMGenerator {
 
 
 			uniform.value = ENCODINGS[ texture.encoding ];
 			uniform.value = ENCODINGS[ texture.encoding ];
 
 
-		} */
-
-		uniform.value = ENCODINGS[ texture.encoding ];
+		}
 
 
 	}
 	}
 
 

+ 3 - 3
src/renderers/webgl/WebGLPrograms.js

@@ -1,4 +1,4 @@
-import { BackSide, DoubleSide, CubeUVRefractionMapping, CubeUVReflectionMapping, LinearEncoding, ObjectSpaceNormalMap, TangentSpaceNormalMap, NoToneMapping } from '../../constants.js';
+import { BackSide, DoubleSide, CubeUVRefractionMapping, CubeUVReflectionMapping, LinearEncoding, sRGBEncoding, ObjectSpaceNormalMap, TangentSpaceNormalMap, NoToneMapping, RGBAFormat, UnsignedByteType } from '../../constants.js';
 import { WebGLProgram } from './WebGLProgram.js';
 import { WebGLProgram } from './WebGLProgram.js';
 import { ShaderLib } from '../shaders/ShaderLib.js';
 import { ShaderLib } from '../shaders/ShaderLib.js';
 import { UniformsUtils } from '../shaders/UniformsUtils.js';
 import { UniformsUtils } from '../shaders/UniformsUtils.js';
@@ -108,11 +108,11 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
 
 
 		}
 		}
 
 
-		/* if ( isWebGL2 && map && map.isTexture && map.format === RGBAFormat && map.type === UnsignedByteType && map.encoding === sRGBEncoding ) {
+		if ( isWebGL2 && map && map.isTexture && map.format === RGBAFormat && map.type === UnsignedByteType && map.encoding === sRGBEncoding ) {
 
 
 			encoding = LinearEncoding; // disable inline decode for sRGB textures in WebGL 2
 			encoding = LinearEncoding; // disable inline decode for sRGB textures in WebGL 2
 
 
-		} */
+		}
 
 
 		return encoding;
 		return encoding;
 
 

+ 3 - 5
src/renderers/webgl/WebGLTextures.js

@@ -1,4 +1,4 @@
-import { LinearFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, RGBFormat, RGBAFormat, DepthFormat, DepthStencilFormat, UnsignedShortType, UnsignedIntType, UnsignedInt248Type, FloatType, HalfFloatType, MirroredRepeatWrapping, ClampToEdgeWrapping, RepeatWrapping } from '../../constants.js';
+import { LinearFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, RGBFormat, RGBAFormat, DepthFormat, DepthStencilFormat, UnsignedShortType, UnsignedIntType, UnsignedInt248Type, FloatType, HalfFloatType, MirroredRepeatWrapping, ClampToEdgeWrapping, RepeatWrapping, sRGBEncoding } from '../../constants.js';
 import * as MathUtils from '../../math/MathUtils.js';
 import * as MathUtils from '../../math/MathUtils.js';
 import { createElementNS } from '../../utils.js';
 import { createElementNS } from '../../utils.js';
 
 
@@ -130,7 +130,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
 
 
 	}
 	}
 
 
-	function getInternalFormat( internalFormatName, glFormat, glType/*, encoding*/ ) {
+	function getInternalFormat( internalFormatName, glFormat, glType, encoding ) {
 
 
 		if ( isWebGL2 === false ) return glFormat;
 		if ( isWebGL2 === false ) return glFormat;
 
 
@@ -164,9 +164,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
 
 
 			if ( glType === _gl.FLOAT ) internalFormat = _gl.RGBA32F;
 			if ( glType === _gl.FLOAT ) internalFormat = _gl.RGBA32F;
 			if ( glType === _gl.HALF_FLOAT ) internalFormat = _gl.RGBA16F;
 			if ( glType === _gl.HALF_FLOAT ) internalFormat = _gl.RGBA16F;
-			//if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = ( encoding === sRGBEncoding ) ? _gl.SRGB8_ALPHA8 : _gl.RGBA8;
-			if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = _gl.RGBA8;
-
+			if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = ( encoding === sRGBEncoding ) ? _gl.SRGB8_ALPHA8 : _gl.RGBA8;
 
 
 		}
 		}