Ver código fonte

ShaderChunks: Ignore alpha in output_fragment when using NoBlending (#22424)

* ShaderChunks: Ignore alpha in output_fragment when transparent = false.

* ShaderChunks: Define OPAQUE instead of TRANSPARENT.

* ShaderChunks: Define OPAQUE when using NoBlending.

* ShaderChunk: Clean up.
Mr.doob 3 anos atrás
pai
commit
2a3d87a74b

+ 2 - 0
examples/jsm/loaders/GLTFLoader.js

@@ -37,6 +37,7 @@ import {
 	NearestFilter,
 	NearestFilter,
 	NearestMipmapLinearFilter,
 	NearestMipmapLinearFilter,
 	NearestMipmapNearestFilter,
 	NearestMipmapNearestFilter,
+	NoBlending,
 	NumberKeyframeTrack,
 	NumberKeyframeTrack,
 	Object3D,
 	Object3D,
 	OrthographicCamera,
 	OrthographicCamera,
@@ -3118,6 +3119,7 @@ class GLTFParser {
 
 
 		} else {
 		} else {
 
 
+			materialParams.blending = NoBlending;
 			materialParams.transparent = false;
 			materialParams.transparent = false;
 
 
 			if ( alphaMode === ALPHA_MODES.MASK ) {
 			if ( alphaMode === ALPHA_MODES.MASK ) {

+ 2 - 0
src/renderers/shaders/ShaderChunk.js

@@ -71,6 +71,7 @@ import normalmap_pars_fragment from './ShaderChunk/normalmap_pars_fragment.glsl.
 import clearcoat_normal_fragment_begin from './ShaderChunk/clearcoat_normal_fragment_begin.glsl.js';
 import clearcoat_normal_fragment_begin from './ShaderChunk/clearcoat_normal_fragment_begin.glsl.js';
 import clearcoat_normal_fragment_maps from './ShaderChunk/clearcoat_normal_fragment_maps.glsl.js';
 import clearcoat_normal_fragment_maps from './ShaderChunk/clearcoat_normal_fragment_maps.glsl.js';
 import clearcoat_pars_fragment from './ShaderChunk/clearcoat_pars_fragment.glsl.js';
 import clearcoat_pars_fragment from './ShaderChunk/clearcoat_pars_fragment.glsl.js';
+import output_fragment from './ShaderChunk/output_fragment.glsl.js';
 import packing from './ShaderChunk/packing.glsl.js';
 import packing from './ShaderChunk/packing.glsl.js';
 import premultiplied_alpha_fragment from './ShaderChunk/premultiplied_alpha_fragment.glsl.js';
 import premultiplied_alpha_fragment from './ShaderChunk/premultiplied_alpha_fragment.glsl.js';
 import project_vertex from './ShaderChunk/project_vertex.glsl.js';
 import project_vertex from './ShaderChunk/project_vertex.glsl.js';
@@ -207,6 +208,7 @@ export const ShaderChunk = {
 	clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
 	clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
 	clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
 	clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
 	clearcoat_pars_fragment: clearcoat_pars_fragment,
 	clearcoat_pars_fragment: clearcoat_pars_fragment,
+	output_fragment: output_fragment,
 	packing: packing,
 	packing: packing,
 	premultiplied_alpha_fragment: premultiplied_alpha_fragment,
 	premultiplied_alpha_fragment: premultiplied_alpha_fragment,
 	project_vertex: project_vertex,
 	project_vertex: project_vertex,

+ 11 - 0
src/renderers/shaders/ShaderChunk/output_fragment.glsl.js

@@ -0,0 +1,11 @@
+export default /* glsl */`
+#ifdef OPAQUE
+
+gl_FragColor = vec4( outgoingLight, 1.0 );
+
+#else
+
+gl_FragColor = vec4( outgoingLight, diffuseColor.a );
+
+#endif
+`;

+ 1 - 2
src/renderers/shaders/ShaderLib/linedashed_frag.glsl.js

@@ -31,8 +31,7 @@ void main() {
 
 
 	outgoingLight = diffuseColor.rgb; // simple shader
 	outgoingLight = diffuseColor.rgb; // simple shader
 
 
-	gl_FragColor = vec4( outgoingLight, diffuseColor.a );
-
+	#include <output_fragment>
 	#include <tonemapping_fragment>
 	#include <tonemapping_fragment>
 	#include <encodings_fragment>
 	#include <encodings_fragment>
 	#include <fog_fragment>
 	#include <fog_fragment>

+ 1 - 2
src/renderers/shaders/ShaderLib/meshbasic_frag.glsl.js

@@ -62,8 +62,7 @@ void main() {
 
 
 	#include <envmap_fragment>
 	#include <envmap_fragment>
 
 
-	gl_FragColor = vec4( outgoingLight, diffuseColor.a );
-
+	#include <output_fragment>
 	#include <tonemapping_fragment>
 	#include <tonemapping_fragment>
 	#include <encodings_fragment>
 	#include <encodings_fragment>
 	#include <fog_fragment>
 	#include <fog_fragment>

+ 1 - 2
src/renderers/shaders/ShaderLib/meshlambert_frag.glsl.js

@@ -88,8 +88,7 @@ void main() {
 
 
 	#include <envmap_fragment>
 	#include <envmap_fragment>
 
 
-	gl_FragColor = vec4( outgoingLight, diffuseColor.a );
-
+	#include <output_fragment>
 	#include <tonemapping_fragment>
 	#include <tonemapping_fragment>
 	#include <encodings_fragment>
 	#include <encodings_fragment>
 	#include <fog_fragment>
 	#include <fog_fragment>

+ 1 - 2
src/renderers/shaders/ShaderLib/meshmatcap_frag.glsl.js

@@ -53,8 +53,7 @@ void main() {
 
 
 	vec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;
 	vec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;
 
 
-	gl_FragColor = vec4( outgoingLight, diffuseColor.a );
-
+	#include <output_fragment>
 	#include <tonemapping_fragment>
 	#include <tonemapping_fragment>
 	#include <encodings_fragment>
 	#include <encodings_fragment>
 	#include <fog_fragment>
 	#include <fog_fragment>

+ 1 - 3
src/renderers/shaders/ShaderLib/meshphong_frag.glsl.js

@@ -64,9 +64,7 @@ void main() {
 	vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;
 	vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;
 
 
 	#include <envmap_fragment>
 	#include <envmap_fragment>
-
-	gl_FragColor = vec4( outgoingLight, diffuseColor.a );
-
+	#include <output_fragment>
 	#include <tonemapping_fragment>
 	#include <tonemapping_fragment>
 	#include <encodings_fragment>
 	#include <encodings_fragment>
 	#include <fog_fragment>
 	#include <fog_fragment>

+ 1 - 2
src/renderers/shaders/ShaderLib/meshphysical_frag.glsl.js

@@ -117,8 +117,7 @@ void main() {
 
 
 	#endif
 	#endif
 
 
-	gl_FragColor = vec4( outgoingLight, diffuseColor.a );
-
+	#include <output_fragment>
 	#include <tonemapping_fragment>
 	#include <tonemapping_fragment>
 	#include <encodings_fragment>
 	#include <encodings_fragment>
 	#include <fog_fragment>
 	#include <fog_fragment>

+ 1 - 2
src/renderers/shaders/ShaderLib/meshtoon_frag.glsl.js

@@ -57,8 +57,7 @@ void main() {
 
 
 	vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;
 	vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;
 
 
-	gl_FragColor = vec4( outgoingLight, diffuseColor.a );
-
+	#include <output_fragment>
 	#include <tonemapping_fragment>
 	#include <tonemapping_fragment>
 	#include <encodings_fragment>
 	#include <encodings_fragment>
 	#include <fog_fragment>
 	#include <fog_fragment>

+ 1 - 2
src/renderers/shaders/ShaderLib/points_frag.glsl.js

@@ -24,8 +24,7 @@ void main() {
 
 
 	outgoingLight = diffuseColor.rgb;
 	outgoingLight = diffuseColor.rgb;
 
 
-	gl_FragColor = vec4( outgoingLight, diffuseColor.a );
-
+	#include <output_fragment>
 	#include <tonemapping_fragment>
 	#include <tonemapping_fragment>
 	#include <encodings_fragment>
 	#include <encodings_fragment>
 	#include <fog_fragment>
 	#include <fog_fragment>

+ 1 - 2
src/renderers/shaders/ShaderLib/sprite_frag.glsl.js

@@ -25,8 +25,7 @@ void main() {
 
 
 	outgoingLight = diffuseColor.rgb;
 	outgoingLight = diffuseColor.rgb;
 
 
-	gl_FragColor = vec4( outgoingLight, diffuseColor.a );
-
+	#include <output_fragment>
 	#include <tonemapping_fragment>
 	#include <tonemapping_fragment>
 	#include <encodings_fragment>
 	#include <encodings_fragment>
 	#include <fog_fragment>
 	#include <fog_fragment>

+ 2 - 1
src/renderers/webgl/WebGLProgram.js

@@ -1,7 +1,7 @@
 import { WebGLUniforms } from './WebGLUniforms.js';
 import { WebGLUniforms } from './WebGLUniforms.js';
 import { WebGLShader } from './WebGLShader.js';
 import { WebGLShader } from './WebGLShader.js';
 import { ShaderChunk } from '../shaders/ShaderChunk.js';
 import { ShaderChunk } from '../shaders/ShaderChunk.js';
-import { NoToneMapping, AddOperation, MixOperation, MultiplyOperation, CubeRefractionMapping, CubeUVRefractionMapping, CubeUVReflectionMapping, CubeReflectionMapping, PCFSoftShadowMap, PCFShadowMap, VSMShadowMap, ACESFilmicToneMapping, CineonToneMapping, CustomToneMapping, ReinhardToneMapping, LinearToneMapping, GammaEncoding, RGBDEncoding, RGBM16Encoding, RGBM7Encoding, RGBEEncoding, sRGBEncoding, LinearEncoding, LogLuvEncoding, GLSL3 } from '../../constants.js';
+import { NoBlending, NoToneMapping, AddOperation, MixOperation, MultiplyOperation, CubeRefractionMapping, CubeUVRefractionMapping, CubeUVReflectionMapping, CubeReflectionMapping, PCFSoftShadowMap, PCFShadowMap, VSMShadowMap, ACESFilmicToneMapping, CineonToneMapping, CustomToneMapping, ReinhardToneMapping, LinearToneMapping, GammaEncoding, RGBDEncoding, RGBM16Encoding, RGBM7Encoding, RGBEEncoding, sRGBEncoding, LinearEncoding, LogLuvEncoding, GLSL3 } from '../../constants.js';
 
 
 let programIdCount = 0;
 let programIdCount = 0;
 
 
@@ -670,6 +670,7 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
 			( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '',
 			( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '',
 
 
 			parameters.dithering ? '#define DITHERING' : '',
 			parameters.dithering ? '#define DITHERING' : '',
+			parameters.blending === NoBlending ? '#define OPAQUE' : '',
 
 
 			ShaderChunk[ 'encodings_pars_fragment' ], // this code is required here because it is used by the various encoding/decoding function defined below
 			ShaderChunk[ 'encodings_pars_fragment' ], // this code is required here because it is used by the various encoding/decoding function defined below
 			parameters.map ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
 			parameters.map ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',

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

@@ -47,7 +47,7 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
 		'numDirLights', 'numPointLights', 'numSpotLights', 'numHemiLights', 'numRectAreaLights',
 		'numDirLights', 'numPointLights', 'numSpotLights', 'numHemiLights', 'numRectAreaLights',
 		'numDirLightShadows', 'numPointLightShadows', 'numSpotLightShadows',
 		'numDirLightShadows', 'numPointLightShadows', 'numSpotLightShadows',
 		'shadowMapEnabled', 'shadowMapType', 'toneMapping', 'physicallyCorrectLights',
 		'shadowMapEnabled', 'shadowMapType', 'toneMapping', 'physicallyCorrectLights',
-		'doubleSided', 'flipSided', 'numClippingPlanes', 'numClipIntersection', 'depthPacking', 'dithering',
+		'doubleSided', 'flipSided', 'numClippingPlanes', 'numClipIntersection', 'depthPacking', 'dithering', 'blending',
 		'sheenTint', 'transmission', 'transmissionMap', 'thicknessMap'
 		'sheenTint', 'transmission', 'transmissionMap', 'thicknessMap'
 	];
 	];
 
 
@@ -208,6 +208,7 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
 			specularIntensityMap: !! material.specularIntensityMap,
 			specularIntensityMap: !! material.specularIntensityMap,
 			specularTintMap: !! material.specularTintMap,
 			specularTintMap: !! material.specularTintMap,
 			specularTintMapEncoding: getTextureEncodingFromMap( material.specularTintMap ),
 			specularTintMapEncoding: getTextureEncodingFromMap( material.specularTintMap ),
+
 			alphaMap: !! material.alphaMap,
 			alphaMap: !! material.alphaMap,
 			alphaTest: useAlphaTest,
 			alphaTest: useAlphaTest,
 
 
@@ -256,6 +257,7 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
 			numClippingPlanes: clipping.numPlanes,
 			numClippingPlanes: clipping.numPlanes,
 			numClipIntersection: clipping.numIntersection,
 			numClipIntersection: clipping.numIntersection,
 
 
+			blending: material.blending,
 			dithering: material.dithering,
 			dithering: material.dithering,
 
 
 			shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
 			shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,