Skip to content

Commit

Permalink
NodeMaterial: Added flatShading
Browse files Browse the repository at this point in the history
  • Loading branch information
sunag committed Jun 24, 2023
1 parent d648c86 commit 8399b5e
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions examples/jsm/nodes/materials/NodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import { materialAlphaTest, materialColor, materialOpacity, materialEmissive } f
import { modelViewProjection } from '../accessors/ModelViewProjectionNode.js';
import { transformedNormalView } from '../accessors/NormalNode.js';
import { instance } from '../accessors/InstanceNode.js';
import { positionLocal } from '../accessors/PositionNode.js';
import { positionLocal, positionView } from '../accessors/PositionNode.js';
import { skinning } from '../accessors/SkinningNode.js';
import { morph } from '../accessors/MorphNode.js';
import { texture } from '../accessors/TextureNode.js';
import { cubeTexture } from '../accessors/CubeTextureNode.js';
import { lightsWithoutWrap } from '../lighting/LightsNode.js';
import { mix } from '../math/MathNode.js';
import { mix, dFdx, dFdy } from '../math/MathNode.js';
import { float, vec3, vec4 } from '../shadernode/ShaderNode.js';
import AONode from '../lighting/AONode.js';
import EnvironmentNode from '../lighting/EnvironmentNode.js';
Expand Down Expand Up @@ -169,11 +170,21 @@ class NodeMaterial extends ShaderMaterial {

// NORMAL VIEW

const normalNode = this.normalNode ? vec3( this.normalNode ) : materialNormal;
if ( this.flatShading === true ) {

stack.assign( transformedNormalView, normalNode );
const fdx = dFdx( positionView );
const fdy = dFdy( positionView.negate() ); // use -positionView ?
const normalNode = fdx.cross( fdy ).normalize();

return normalNode;
stack.assign( transformedNormalView, normalNode );

} else {

const normalNode = this.normalNode ? vec3( this.normalNode ) : materialNormal;

stack.assign( transformedNormalView, normalNode );

}

}

Expand Down

0 comments on commit 8399b5e

Please sign in to comment.