2
0
Эх сурвалжийг харах

WebGLRenderer: Add support for GLTF opaque alpha_mode (#22428)

* WebGLRenderer: Add support for GLTF opaque alpha_mode.

* Replaced material.blending = GLTFOpaqueBlending with material.format = RGBFormat.

* Clean up.
Mr.doob 3 жил өмнө
parent
commit
f0583761c5

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

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

+ 1 - 0
src/loaders/MaterialLoader.js

@@ -93,6 +93,7 @@ class MaterialLoader extends Loader {
 		if ( json.side !== undefined ) material.side = json.side;
 		if ( json.side !== undefined ) material.side = json.side;
 		if ( json.shadowSide !== undefined ) material.shadowSide = json.shadowSide;
 		if ( json.shadowSide !== undefined ) material.shadowSide = json.shadowSide;
 		if ( json.opacity !== undefined ) material.opacity = json.opacity;
 		if ( json.opacity !== undefined ) material.opacity = json.opacity;
+		if ( json.format !== undefined ) material.format = json.format;
 		if ( json.transparent !== undefined ) material.transparent = json.transparent;
 		if ( json.transparent !== undefined ) material.transparent = json.transparent;
 		if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
 		if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
 		if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
 		if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;

+ 4 - 1
src/materials/Material.js

@@ -1,5 +1,5 @@
 import { EventDispatcher } from '../core/EventDispatcher.js';
 import { EventDispatcher } from '../core/EventDispatcher.js';
-import { FrontSide, FlatShading, NormalBlending, LessEqualDepth, AddEquation, OneMinusSrcAlphaFactor, SrcAlphaFactor, AlwaysStencilFunc, KeepStencilOp } from '../constants.js';
+import { FrontSide, FlatShading, NormalBlending, LessEqualDepth, AddEquation, OneMinusSrcAlphaFactor, SrcAlphaFactor, AlwaysStencilFunc, KeepStencilOp, RGBAFormat } from '../constants.js';
 import * as MathUtils from '../math/MathUtils.js';
 import * as MathUtils from '../math/MathUtils.js';
 
 
 let materialId = 0;
 let materialId = 0;
@@ -26,6 +26,7 @@ class Material extends EventDispatcher {
 		this.vertexColors = false;
 		this.vertexColors = false;
 
 
 		this.opacity = 1;
 		this.opacity = 1;
+		this.format = RGBAFormat;
 		this.transparent = false;
 		this.transparent = false;
 
 
 		this.blendSrc = SrcAlphaFactor;
 		this.blendSrc = SrcAlphaFactor;
@@ -301,6 +302,7 @@ class Material extends EventDispatcher {
 		if ( this.vertexColors ) data.vertexColors = true;
 		if ( this.vertexColors ) data.vertexColors = true;
 
 
 		if ( this.opacity < 1 ) data.opacity = this.opacity;
 		if ( this.opacity < 1 ) data.opacity = this.opacity;
+		if ( this.format !== RGBAFormat ) data.format = this.format;
 		if ( this.transparent === true ) data.transparent = this.transparent;
 		if ( this.transparent === true ) data.transparent = this.transparent;
 
 
 		data.depthFunc = this.depthFunc;
 		data.depthFunc = this.depthFunc;
@@ -397,6 +399,7 @@ class Material extends EventDispatcher {
 		this.vertexColors = source.vertexColors;
 		this.vertexColors = source.vertexColors;
 
 
 		this.opacity = source.opacity;
 		this.opacity = source.opacity;
+		this.format = source.format;
 		this.transparent = source.transparent;
 		this.transparent = source.transparent;
 
 
 		this.blendSrc = source.blendSrc;
 		this.blendSrc = source.blendSrc;

+ 2 - 2
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 { 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';
+import { RGBFormat, 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,7 +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' : '',
+			parameters.format === RGBFormat ? '#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 ) : '',

+ 2 - 2
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', 'blending',
+		'doubleSided', 'flipSided', 'numClippingPlanes', 'numClipIntersection', 'depthPacking', 'dithering', 'format',
 		'sheenTint', 'transmission', 'transmissionMap', 'thicknessMap'
 		'sheenTint', 'transmission', 'transmissionMap', 'thicknessMap'
 	];
 	];
 
 
@@ -257,7 +257,7 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
 			numClippingPlanes: clipping.numPlanes,
 			numClippingPlanes: clipping.numPlanes,
 			numClipIntersection: clipping.numIntersection,
 			numClipIntersection: clipping.numIntersection,
 
 
-			blending: material.blending,
+			format: material.format,
 			dithering: material.dithering,
 			dithering: material.dithering,
 
 
 			shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
 			shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,