From f5803c62cc4a29d90744e9dc7811d086e354c1d8 Mon Sep 17 00:00:00 2001 From: Don McCurdy Date: Sun, 25 Jul 2021 03:44:09 -0700 Subject: [PATCH] MeshStandardMaterial: Remove .vertexTangents property. (#22146) --- .../api/en/materials/MeshStandardMaterial.html | 7 ------- .../api/zh/materials/MeshStandardMaterial.html | 8 -------- editor/js/Sidebar.Material.js | 1 - examples/jsm/loaders/GLTFLoader.js | 18 ++---------------- src/Three.Legacy.js | 15 ++++++++++++++- src/loaders/MaterialLoader.js | 2 -- src/materials/MeshStandardMaterial.js | 4 ---- .../clearcoat_normal_fragment_maps.glsl.js | 6 ++++++ .../ShaderChunk/normal_fragment_maps.glsl.js | 6 ++++++ src/renderers/webgl/WebGLProgram.js | 2 ++ src/renderers/webgl/WebGLPrograms.js | 5 +++-- 11 files changed, 33 insertions(+), 41 deletions(-) diff --git a/docs/api/en/materials/MeshStandardMaterial.html b/docs/api/en/materials/MeshStandardMaterial.html index e38047923063f6..49b726e6b32664 100644 --- a/docs/api/en/materials/MeshStandardMaterial.html +++ b/docs/api/en/materials/MeshStandardMaterial.html @@ -233,13 +233,6 @@

[property:Float roughness]

[property:Texture roughnessMap]

The green channel of this texture is used to alter the roughness of the material.

-

[property:Boolean vertexTangents]

-

- Defines whether precomputed vertex tangents, which must be provided in a vec4 "tangent" attribute, - are used. When disabled, tangents are derived automatically. Using precomputed tangents will give - more accurate normal map details in some cases, such as with mirrored UVs. Default is false. -

-

[property:Boolean wireframe]

Render geometry as wireframe. Default is *false* (i.e. render as flat polygons).

diff --git a/docs/api/zh/materials/MeshStandardMaterial.html b/docs/api/zh/materials/MeshStandardMaterial.html index a22f025b5d4637..369ab545e5f184 100644 --- a/docs/api/zh/materials/MeshStandardMaterial.html +++ b/docs/api/zh/materials/MeshStandardMaterial.html @@ -191,14 +191,6 @@

[property:Float roughness]

[property:Texture roughnessMap]

该纹理的绿色通道用于改变材质的粗糙度。

-

[property:Boolean vertexTangents]

-

- Defines whether precomputed vertex tangents, which must be provided in a vec4 "tangent" attribute, - are used. When disabled, tangents are derived automatically. Using precomputed tangents will give - more accurate normal map details in some cases, such as with mirrored UVs. Default is false. -

- -

[property:Boolean wireframe]

将几何体渲染为线框。默认值为*false*(即渲染为平面多边形)。

diff --git a/editor/js/Sidebar.Material.js b/editor/js/Sidebar.Material.js index e1f98c9c50077f..62050f74f797ed 100644 --- a/editor/js/Sidebar.Material.js +++ b/editor/js/Sidebar.Material.js @@ -1255,7 +1255,6 @@ function SidebarMaterial( editor ) { 'clearcoatRoughness': materialClearcoatRoughnessRow, 'vertexShader': materialProgramRow, 'vertexColors': materialVertexColorsRow, - 'vertexTangents': materialVertexTangentsRow, 'depthPacking': materialDepthPackingRow, 'map': materialMapRow, 'matcap': materialMatcapMapRow, diff --git a/examples/jsm/loaders/GLTFLoader.js b/examples/jsm/loaders/GLTFLoader.js index 543eb2e8f3ff97..f3877d47247b33 100644 --- a/examples/jsm/loaders/GLTFLoader.js +++ b/examples/jsm/loaders/GLTFLoader.js @@ -684,8 +684,7 @@ class GLTFMaterialsClearcoatExtension { const scale = extension.clearcoatNormalTexture.scale; - // https://github.com/mrdoob/three.js/issues/11438#issuecomment-507003995 - materialParams.clearcoatNormalScale = new Vector2( scale, - scale ); + materialParams.clearcoatNormalScale = new Vector2( scale, scale ); } @@ -2892,16 +2891,6 @@ class GLTFParser { if ( useVertexColors ) cachedMaterial.vertexColors = true; if ( useFlatShading ) cachedMaterial.flatShading = true; - if ( useVertexTangents ) { - - cachedMaterial.vertexTangents = true; - - // https://github.com/mrdoob/three.js/issues/11438#issuecomment-507003995 - if ( cachedMaterial.normalScale ) cachedMaterial.normalScale.y *= - 1; - if ( cachedMaterial.clearcoatNormalScale ) cachedMaterial.clearcoatNormalScale.y *= - 1; - - } - this.cache.add( cacheKey, cachedMaterial ); this.associations.set( cachedMaterial, this.associations.get( material ) ); @@ -3040,12 +3029,9 @@ class GLTFParser { pending.push( parser.assignTexture( materialParams, 'normalMap', materialDef.normalTexture ) ); - // https://github.com/mrdoob/three.js/issues/11438#issuecomment-507003995 - materialParams.normalScale = new Vector2( 1, - 1 ); - if ( materialDef.normalTexture.scale !== undefined ) { - materialParams.normalScale.set( materialDef.normalTexture.scale, - materialDef.normalTexture.scale ); + materialParams.normalScale = new Vector2( materialDef.normalTexture.scale, materialDef.normalTexture.scale ); } diff --git a/src/Three.Legacy.js b/src/Three.Legacy.js index 7bae62247d95f7..6b3e67366562c1 100644 --- a/src/Three.Legacy.js +++ b/src/Three.Legacy.js @@ -1295,7 +1295,20 @@ Object.defineProperties( Material.prototype, { this.stencilFuncMask = value; } - } + }, + + vertexTangents: { + get: function () { + + console.warn( 'THREE.' + this.type + ': .vertexTangents has been removed.' ); + + }, + set: function () { + + console.warn( 'THREE.' + this.type + ': .vertexTangents has been removed.' ); + + } + }, } ); diff --git a/src/loaders/MaterialLoader.js b/src/loaders/MaterialLoader.js index 8039d6e349616a..ade7aa883db4ad 100644 --- a/src/loaders/MaterialLoader.js +++ b/src/loaders/MaterialLoader.js @@ -127,8 +127,6 @@ class MaterialLoader extends Loader { if ( json.alphaToCoverage !== undefined ) material.alphaToCoverage = json.alphaToCoverage; if ( json.premultipliedAlpha !== undefined ) material.premultipliedAlpha = json.premultipliedAlpha; - if ( json.vertexTangents !== undefined ) material.vertexTangents = json.vertexTangents; - if ( json.visible !== undefined ) material.visible = json.visible; if ( json.toneMapped !== undefined ) material.toneMapped = json.toneMapped; diff --git a/src/materials/MeshStandardMaterial.js b/src/materials/MeshStandardMaterial.js index a32407438103ec..9ceede43dcb72e 100644 --- a/src/materials/MeshStandardMaterial.js +++ b/src/materials/MeshStandardMaterial.js @@ -106,8 +106,6 @@ class MeshStandardMaterial extends Material { this.flatShading = false; - this.vertexTangents = false; - this.setValues( parameters ); } @@ -163,8 +161,6 @@ class MeshStandardMaterial extends Material { this.flatShading = source.flatShading; - this.vertexTangents = source.vertexTangents; - return this; } diff --git a/src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_maps.glsl.js b/src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_maps.glsl.js index 9a35bdbee1afa9..c422ccafe0d1d1 100644 --- a/src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_maps.glsl.js +++ b/src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_maps.glsl.js @@ -4,6 +4,12 @@ export default /* glsl */` vec3 clearcoatMapN = texture2D( clearcoatNormalMap, vUv ).xyz * 2.0 - 1.0; clearcoatMapN.xy *= clearcoatNormalScale; + #ifdef FLIP_NORMAL_SCALE_Y + + clearcoatMapN.y *= -1.0; + + #endif + #ifdef USE_TANGENT clearcoatNormal = normalize( vTBN * clearcoatMapN ); diff --git a/src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js b/src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js index 86bd8caa6bc923..9e7bd4ef85ce2c 100644 --- a/src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js +++ b/src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js @@ -23,6 +23,12 @@ export default /* glsl */` vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0; mapN.xy *= normalScale; + #ifdef FLIP_NORMAL_SCALE_Y + + mapN.y *= -1.0; + + #endif + #ifdef USE_TANGENT normal = normalize( vTBN * mapN ); diff --git a/src/renderers/webgl/WebGLProgram.js b/src/renderers/webgl/WebGLProgram.js index fd95dae1b70c49..32ca3c5ee47d94 100644 --- a/src/renderers/webgl/WebGLProgram.js +++ b/src/renderers/webgl/WebGLProgram.js @@ -477,6 +477,7 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) { parameters.vertexAlphas ? '#define USE_COLOR_ALPHA' : '', parameters.vertexUvs ? '#define USE_UV' : '', parameters.uvsVertexOnly ? '#define UVS_VERTEX_ONLY' : '', + parameters.flipNormalScaleY ? '#define FLIP_NORMAL_SCALE_Y' : '', parameters.flatShading ? '#define FLAT_SHADED' : '', @@ -620,6 +621,7 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) { parameters.vertexAlphas ? '#define USE_COLOR_ALPHA' : '', parameters.vertexUvs ? '#define USE_UV' : '', parameters.uvsVertexOnly ? '#define UVS_VERTEX_ONLY' : '', + parameters.flipNormalScaleY ? '#define FLIP_NORMAL_SCALE_Y' : '', parameters.gradientMap ? '#define USE_GRADIENTMAP' : '', diff --git a/src/renderers/webgl/WebGLPrograms.js b/src/renderers/webgl/WebGLPrograms.js index b8dfe5aaffad7e..d4342f9b1f37c4 100644 --- a/src/renderers/webgl/WebGLPrograms.js +++ b/src/renderers/webgl/WebGLPrograms.js @@ -38,7 +38,7 @@ function WebGLPrograms( renderer, cubemaps, extensions, capabilities, bindingSta 'map', 'mapEncoding', 'matcap', 'matcapEncoding', 'envMap', 'envMapMode', 'envMapEncoding', 'envMapCubeUV', 'lightMap', 'lightMapEncoding', 'aoMap', 'emissiveMap', 'emissiveMapEncoding', 'bumpMap', 'normalMap', 'objectSpaceNormalMap', 'tangentSpaceNormalMap', 'clearcoatMap', 'clearcoatRoughnessMap', 'clearcoatNormalMap', 'displacementMap', 'specularMap', 'roughnessMap', 'metalnessMap', 'gradientMap', - 'alphaMap', 'combine', 'vertexColors', 'vertexAlphas', 'vertexTangents', 'vertexUvs', 'uvsVertexOnly', 'fog', 'useFog', 'fogExp2', + 'alphaMap', 'combine', 'vertexColors', 'vertexAlphas', 'vertexTangents', 'vertexUvs', 'uvsVertexOnly', 'flipNormalScaleY', 'fog', 'useFog', 'fogExp2', 'flatShading', 'sizeAttenuation', 'logarithmicDepthBuffer', 'skinning', 'maxBones', 'useVertexTexture', 'morphTargets', 'morphNormals', 'premultipliedAlpha', 'numDirLights', 'numPointLights', 'numSpotLights', 'numHemiLights', 'numRectAreaLights', @@ -208,11 +208,12 @@ function WebGLPrograms( renderer, cubemaps, extensions, capabilities, bindingSta combine: material.combine, - vertexTangents: ( material.normalMap && material.vertexTangents ), + vertexTangents: ( material.normalMap && object.geometry && object.geometry.attributes.tangent ), vertexColors: material.vertexColors, vertexAlphas: material.vertexColors === true && object.geometry && object.geometry.attributes.color && object.geometry.attributes.color.itemSize === 4, vertexUvs: !! material.map || !! material.bumpMap || !! material.normalMap || !! material.specularMap || !! material.alphaMap || !! material.emissiveMap || !! material.roughnessMap || !! material.metalnessMap || !! material.clearcoatMap || !! material.clearcoatRoughnessMap || !! material.clearcoatNormalMap || !! material.displacementMap || !! material.transmissionMap || !! material.thicknessMap, uvsVertexOnly: ! ( !! material.map || !! material.bumpMap || !! material.normalMap || !! material.specularMap || !! material.alphaMap || !! material.emissiveMap || !! material.roughnessMap || !! material.metalnessMap || !! material.clearcoatNormalMap || !! material.transmission || !! material.transmissionMap || !! material.thicknessMap ) && !! material.displacementMap, + flipNormalScaleY: ( ( material.normalMap && material.normalMap.flipY === false || material.clearcoatNormalMap && material.clearcoatNormalMap.flipY === false ) && ! ( object.geometry && object.geometry.attributes.tangent ) ), fog: !! fog, useFog: material.fog,