Skip to content

Commit

Permalink
MeshStandardMaterial: Remove .vertexTangents property. (#22146)
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy authored Jul 25, 2021
1 parent 3a9152a commit f5803c6
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 41 deletions.
7 changes: 0 additions & 7 deletions docs/api/en/materials/MeshStandardMaterial.html
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,6 @@ <h3>[property:Float roughness]</h3>
<h3>[property:Texture roughnessMap]</h3>
<p>The green channel of this texture is used to alter the roughness of the material.</p>

<h3>[property:Boolean vertexTangents]</h3>
<p>
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.
</p>

<h3>[property:Boolean wireframe]</h3>
<p>Render geometry as wireframe. Default is *false* (i.e. render as flat polygons).</p>

Expand Down
8 changes: 0 additions & 8 deletions docs/api/zh/materials/MeshStandardMaterial.html
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,6 @@ <h3>[property:Float roughness]</h3>
<h3>[property:Texture roughnessMap]</h3>
<p>该纹理的绿色通道用于改变材质的粗糙度。</p>

<h3>[property:Boolean vertexTangents]</h3>
<p>
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.
</p>


<h3>[property:Boolean wireframe]</h3>
<p>将几何体渲染为线框。默认值为*false*(即渲染为平面多边形)。</p>

Expand Down
1 change: 0 additions & 1 deletion editor/js/Sidebar.Material.js
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,6 @@ function SidebarMaterial( editor ) {
'clearcoatRoughness': materialClearcoatRoughnessRow,
'vertexShader': materialProgramRow,
'vertexColors': materialVertexColorsRow,
'vertexTangents': materialVertexTangentsRow,
'depthPacking': materialDepthPackingRow,
'map': materialMapRow,
'matcap': materialMatcapMapRow,
Expand Down
18 changes: 2 additions & 16 deletions examples/jsm/loaders/GLTFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

}

Expand Down Expand Up @@ -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 ) );
Expand Down Expand Up @@ -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 );

}

Expand Down
15 changes: 14 additions & 1 deletion src/Three.Legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.' );

}
},

} );

Expand Down
2 changes: 0 additions & 2 deletions src/loaders/MaterialLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions src/materials/MeshStandardMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ class MeshStandardMaterial extends Material {

this.flatShading = false;

this.vertexTangents = false;

this.setValues( parameters );

}
Expand Down Expand Up @@ -163,8 +161,6 @@ class MeshStandardMaterial extends Material {

this.flatShading = source.flatShading;

this.vertexTangents = source.vertexTangents;

return this;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
2 changes: 2 additions & 0 deletions src/renderers/webgl/WebGLProgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' : '',

Expand Down Expand Up @@ -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' : '',

Expand Down
5 changes: 3 additions & 2 deletions src/renderers/webgl/WebGLPrograms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f5803c6

Please sign in to comment.