Skip to content
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: 5 additions & 5 deletions src/nodes/accessors/Bitangent.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import { directionToFaceDirection } from '../display/FrontFacingNode.js';
* @param {string} varyingName - The name of the varying to assign the bitangent to.
* @returns {Node<vec3>} The bitangent node.
*/
const getBitangent = /*@__PURE__*/ Fn( ( [ crossNormalTangent, varyingName ], { subBuildFn, material } ) => {
const getBitangent = /*@__PURE__*/ Fn( ( [ crossNormalTangent, varyingName ], builder ) => {

let bitangent = crossNormalTangent.mul( tangentGeometry.w ).xyz;

if ( subBuildFn === 'NORMAL' && material.flatShading !== true ) {
if ( builder.subBuildFn === 'NORMAL' && builder.isFlatShading() !== true ) {

bitangent = bitangent.toVarying( varyingName );

Expand Down Expand Up @@ -49,11 +49,11 @@ export const bitangentLocal = /*@__PURE__*/ getBitangent( normalLocal.cross( tan
* @tsl
* @type {Node<vec3>}
*/
export const bitangentView = /*@__PURE__*/ ( Fn( ( { subBuildFn, geometry, material } ) => {
export const bitangentView = /*@__PURE__*/ ( Fn( ( builder ) => {

let node;

if ( subBuildFn === 'VERTEX' || geometry.hasAttribute( 'tangent' ) ) {
if ( builder.subBuildFn === 'VERTEX' || builder.geometry.hasAttribute( 'tangent' ) ) {

node = getBitangent( normalView.cross( tangentView ), 'v_bitangentView' ).normalize();

Expand All @@ -63,7 +63,7 @@ export const bitangentView = /*@__PURE__*/ ( Fn( ( { subBuildFn, geometry, mater

}

if ( material.flatShading !== true ) {
if ( builder.isFlatShading() !== true ) {

node = directionToFaceDirection( node );

Expand Down
12 changes: 6 additions & 6 deletions src/nodes/accessors/Normal.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const normalViewGeometry = /*@__PURE__*/ ( Fn( ( builder ) => {

let node;

if ( builder.material.flatShading === true ) {
if ( builder.isFlatShading() ) {

node = normalFlat;

Expand All @@ -76,7 +76,7 @@ export const normalWorldGeometry = /*@__PURE__*/ ( Fn( ( builder ) => {

let normal = normalViewGeometry.transformDirection( cameraViewMatrix );

if ( builder.material.flatShading !== true ) {
if ( builder.isFlatShading() !== true ) {

normal = normal.toVarying( 'v_normalWorldGeometry' );

Expand All @@ -92,15 +92,15 @@ export const normalWorldGeometry = /*@__PURE__*/ ( Fn( ( builder ) => {
* @tsl
* @type {Node<vec3>}
*/
export const normalView = /*@__PURE__*/ ( Fn( ( { subBuildFn, material, context } ) => {
export const normalView = /*@__PURE__*/ ( Fn( ( builder ) => {

let node;

if ( subBuildFn === 'NORMAL' || subBuildFn === 'VERTEX' ) {
if ( builder.subBuildFn === 'NORMAL' || builder.subBuildFn === 'VERTEX' ) {

node = normalViewGeometry;

if ( material.flatShading !== true ) {
if ( builder.isFlatShading() !== true ) {

node = directionToFaceDirection( node );

Expand All @@ -110,7 +110,7 @@ export const normalView = /*@__PURE__*/ ( Fn( ( { subBuildFn, material, context

// Use getUV context to avoid side effects from nodes overwriting getUV in the context (e.g. EnvironmentNode)

node = context.setupNormal().context( { getUV: null } );
node = builder.context.setupNormal().context( { getUV: null } );

}

Expand Down
6 changes: 3 additions & 3 deletions src/nodes/accessors/Tangent.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ export const tangentLocal = /*@__PURE__*/ tangentGeometry.xyz.toVar( 'tangentLoc
* @tsl
* @type {Node<vec3>}
*/
export const tangentView = /*@__PURE__*/ ( Fn( ( { subBuildFn, geometry, material } ) => {
export const tangentView = /*@__PURE__*/ ( Fn( ( builder ) => {

let node;

if ( subBuildFn === 'VERTEX' || geometry.hasAttribute( 'tangent' ) ) {
if ( builder.subBuildFn === 'VERTEX' || builder.geometry.hasAttribute( 'tangent' ) ) {

node = modelViewMatrix.mul( vec4( tangentLocal, 0 ) ).xyz.toVarying( 'v_tangentView' ).normalize();

Expand All @@ -41,7 +41,7 @@ export const tangentView = /*@__PURE__*/ ( Fn( ( { subBuildFn, geometry, materia

}

if ( material.flatShading !== true ) {
if ( builder.isFlatShading() !== true ) {

node = directionToFaceDirection( node );

Expand Down
11 changes: 11 additions & 0 deletions src/nodes/core/NodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,17 @@ class NodeBuilder {

}

/**
* Whether the material is using flat shading or not.
*
* @returns {boolean} Whether the material is using flat shading or not.
*/
isFlatShading() {

return this.material.flatShading === true || this.geometry.hasAttribute( 'normal' ) === false;

}

/**
* Whether the material is opaque or not.
*
Expand Down
4 changes: 2 additions & 2 deletions src/nodes/display/NormalMapNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class NormalMapNode extends TempNode {

}

setup( { material } ) {
setup( builder ) {

const { normalMapType, scaleNode, unpackNormalMode } = this;

Expand Down Expand Up @@ -105,7 +105,7 @@ class NormalMapNode extends TempNode {

let scale = scaleNode;

if ( material.flatShading === true ) {
if ( builder.isFlatShading() === true ) {

scale = directionToFaceDirection( scale );

Expand Down