Browse Source

WebGLNodeBuilder: Fix sRGBEncoding map using WebGL2 (#22585)

* WebGLNodeBuilder: fix sRGBEncoding map using WebGL2

* WebGLNodeBuilder: fix sRGBEncoding map using WebGL2 (style 2)
sunag 3 years ago
parent
commit
c69a6672c1
1 changed files with 15 additions and 1 deletions
  1. 15 1
      examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js

+ 15 - 1
examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js

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