Three.js: Normal issue with Bump Maps in StandardNodeMaterial

Created on 17 Jul 2019  路  7Comments  路  Source: mrdoob/three.js

Description of the problem

Normals generated by BumpMapNode (and NormalMapNode) in StandardNodeMaterial seem to be incorrect.

I made 2 simple examples using only a HDR environment map to light the scene - One with StandardNodeMaterial and a second one with MeshStandardMaterial to show the difference. I also added a screenshot from Blender Eevee with the exact same set up which tends to prove that the result generated by MeshStandardMaterial is correct.

The scale factor also seem to be behaving differently.

test

Three.js version
  • [x] Dev
  • [x] r106
Browser
  • [x] All of them
OS
  • [x] All of them
Hardware Requirements (graphics card, VR Device, ...)

Most helpful comment

I am try revise the BumpMapNode in jsfiddle still without success .
I am need to recreate the example locally and continue the tests...

All 7 comments

I keep experimenting with the node materials and I may have a suggestion regarding NormalMapNode.

If the geometry includes multiple uv sets, I would have thought that NormalMapNode would use the same set as the one specified in TextureNode, or at least that it would have been an argument of the constructor.

Currently, this is not very obvious that the uv property has to be set manually after or it will be defaulted to uv set index 0:

let normalTex = new THREE.TextureLoader().load('normal.png');
let normalNodeText = new Nodes.TextureNode(bevelTex, new Nodes.UVNode(1));
let normalMap = new Nodes.NormalMapNode(normalNodeText);
normalMap.uv = new Nodes.UVNode(1);

/ping @sunag :-)

I am try revise the BumpMapNode in jsfiddle still without success .
I am need to recreate the example locally and continue the tests...

@njarraud try replaces the function generate of NormalNode for this:
It will fix NormalNode.WORLD problem.
Exist other bugs to fix I will launch a PR with theses fixes soon.

NormalNode.prototype.generate = function ( builder, output ) {

    var result;

    switch ( this.scope ) {

        case NormalNode.LOCAL:

            // to use vObjectNormal as vertex normal
            //builder.requires.normal = true;

            result = 'normal';

            break;

        case NormalNode.WORLD:

            if ( builder.isShader( 'vertex' ) ) {

                return '( modelMatrix * vec4( objectNormal, 0.0 ) ).xyz';

            } else {

                //builder.requires.worldNormal = true;

                //result = 'vWNormal';

                builder.addNodeCode( 'vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );' );

                result = 'worldNormal';

            }

            break;

        case NormalNode.VIEW:

            result = 'vNormal';

            break;

    }

    return builder.format( result, this.getType( builder ), output );

};

/ping @fi4sk0

NormalNode.VIEW need fix.

@sunag I tried your code. It seems to fix BumpMapNode.

Was this page helpful?
0 / 5 - 0 ratings