Skip to content

Commit

Permalink
GLTFLoader: Corrections to normalscale.
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy committed May 27, 2018
1 parent af020fd commit 014653f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
14 changes: 4 additions & 10 deletions examples/js/loaders/GLTFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2204,11 +2204,13 @@ THREE.GLTFLoader = ( function () {

pending.push( parser.assignTexture( material, 'normal', materialDef.normalTexture.index ) );

material.normalScale = new THREE.FloatNode( 1.0 );
// Normal map textures use OpenGL conventions:
// https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#materialnormaltexture
material.normalScale = new THREE.Vector2Node( 1.0, -1.0 );

if ( materialDef.normalTexture.scale !== undefined ) {

material.normalScale.value = materialDef.normalTexture.scale;
material.normalScale.value.multiplyScalar( materialDef.normalTexture.scale );

}

Expand Down Expand Up @@ -2246,14 +2248,6 @@ THREE.GLTFLoader = ( function () {

if ( materialDef.name !== undefined ) material.name = materialDef.name;

// Normal map textures use OpenGL conventions:
// https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#materialnormaltexture
// if ( material.normalScale ) {

// material.normalScale.y = - material.normalScale.y;

// }

if ( materialDef.extras ) material.userData = materialDef.extras;

if ( materialDef.extensions ) addUnknownExtensionsToUserData( extensions, material, materialDef );
Expand Down
6 changes: 4 additions & 2 deletions examples/js/nodes/NodeLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,10 @@ THREE.NodeLib.add( new THREE.FunctionNode( [
" vec3 q1 = dFdy( eye_pos );",
" vec2 st0 = dFdx( mUv.st );",
" vec2 st1 = dFdy( mUv.st );",
" vec3 S = normalize( q0 * st1.t - q1 * st0.t );",
" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );",
" float factor = sign( st1.t * st0.s - st0.t * st1.s );",
" factor *= float( gl_FrontFacing ) * 2.0 - 1.0;",
" vec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * factor );",
" vec3 T = normalize( ( -q0 * st1.s + q1 * st0.s ) * factor );",
" vec3 N = normalize( surf_norm );",
" vec3 mapN = map * 2.0 - 1.0;",
" mapN.xy = scale * mapN.xy;",
Expand Down

0 comments on commit 014653f

Please sign in to comment.