Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGLRenderer, GLTFLoader: Clean up .vertexTangents removal. #22182

Merged
merged 1 commit into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions examples/jsm/exporters/GLTFExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1219,14 +1219,10 @@ class GLTFWriter {

const normalMapDef = { index: this.processTexture( material.normalMap ) };

if ( material.normalScale && material.normalScale.x !== - 1 ) {

if ( material.normalScale.x !== material.normalScale.y ) {

console.warn( 'THREE.GLTFExporter: Normal scale components are different, ignoring Y and exporting X.' );

}
if ( material.normalScale && material.normalScale.x !== 1 ) {

// glTF normal scale is univariate. Ignore `y`, which may be flipped.
// Context: https://github.com/mrdoob/three.js/issues/11438#issuecomment-507003995
normalMapDef.scale = material.normalScale.x;

}
Expand Down
16 changes: 14 additions & 2 deletions examples/jsm/loaders/GLTFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,8 @@ class GLTFMaterialsClearcoatExtension {

const scale = extension.clearcoatNormalTexture.scale;

materialParams.clearcoatNormalScale = new Vector2( scale, scale );
// https://github.com/mrdoob/three.js/issues/11438#issuecomment-507003995
materialParams.clearcoatNormalScale = new Vector2( scale, - scale );

}

Expand Down Expand Up @@ -2891,6 +2892,14 @@ class GLTFParser {
if ( useVertexColors ) cachedMaterial.vertexColors = true;
if ( useFlatShading ) cachedMaterial.flatShading = true;

if ( useVertexTangents ) {

// 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 @@ -3029,9 +3038,12 @@ 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 = new Vector2( materialDef.normalTexture.scale, materialDef.normalTexture.scale );
materialParams.normalScale.set( materialDef.normalTexture.scale, - materialDef.normalTexture.scale );

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ 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,12 +23,6 @@ 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: 0 additions & 2 deletions src/renderers/webgl/WebGLProgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,6 @@ 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 @@ -621,7 +620,6 @@ 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
3 changes: 1 addition & 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', 'flipNormalScaleY', 'fog', 'useFog', 'fogExp2',
'alphaMap', 'combine', 'vertexColors', 'vertexAlphas', 'vertexTangents', 'vertexUvs', 'uvsVertexOnly', 'fog', 'useFog', 'fogExp2',
'flatShading', 'sizeAttenuation', 'logarithmicDepthBuffer', 'skinning',
'maxBones', 'useVertexTexture', 'morphTargets', 'morphNormals', 'premultipliedAlpha',
'numDirLights', 'numPointLights', 'numSpotLights', 'numHemiLights', 'numRectAreaLights',
Expand Down Expand Up @@ -213,7 +213,6 @@ function WebGLPrograms( renderer, cubemaps, extensions, capabilities, bindingSta
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