diff --git a/examples/jsm/nodes/functions/LambertLightingModel.js b/examples/jsm/nodes/functions/LambertLightingModel.js new file mode 100644 index 00000000000000..04437bc16e72c0 --- /dev/null +++ b/examples/jsm/nodes/functions/LambertLightingModel.js @@ -0,0 +1,24 @@ +import BRDF_Lambert from './BSDF/BRDF_Lambert.js'; +import { lightingModel } from '../core/LightingModel.js'; +import { diffuseColor } from '../core/PropertyNode.js'; +import { transformedNormalView } from '../accessors/NormalNode.js'; +import { tslFn } from '../shadernode/ShaderNode.js'; + +const RE_Direct_Lambert = tslFn( ( { lightDirection, lightColor, reflectedLight } ) => { + + const dotNL = transformedNormalView.dot( lightDirection ).clamp(); + const irradiance = dotNL.mul( lightColor ); + + reflectedLight.directDiffuse.addAssign( irradiance.mul( BRDF_Lambert( { diffuseColor: diffuseColor.rgb } ) ) ); + +} ); + +const RE_IndirectDiffuse_Lambert = tslFn( ( { irradiance, reflectedLight } ) => { + + reflectedLight.indirectDiffuse.addAssign( irradiance.mul( BRDF_Lambert( { diffuseColor } ) ) ); + +} ); + +const lambertLightingModel = lightingModel( null, RE_Direct_Lambert, RE_IndirectDiffuse_Lambert ); + +export default lambertLightingModel; diff --git a/examples/jsm/nodes/materials/Materials.js b/examples/jsm/nodes/materials/Materials.js index 8453c84c182ad3..4949da8305058e 100644 --- a/examples/jsm/nodes/materials/Materials.js +++ b/examples/jsm/nodes/materials/Materials.js @@ -4,6 +4,7 @@ export { default as NodeMaterial, addNodeMaterial, createNodeMaterialFromType } export { default as LineBasicNodeMaterial } from './LineBasicNodeMaterial.js'; export { default as MeshNormalNodeMaterial } from './MeshNormalNodeMaterial.js'; export { default as MeshBasicNodeMaterial } from './MeshBasicNodeMaterial.js'; +export { default as MeshLambertNodeMaterial } from './MeshLambertNodeMaterial.js'; export { default as MeshPhongNodeMaterial } from './MeshPhongNodeMaterial.js'; export { default as MeshStandardNodeMaterial } from './MeshStandardNodeMaterial.js'; export { default as MeshPhysicalNodeMaterial } from './MeshPhysicalNodeMaterial.js'; diff --git a/examples/jsm/nodes/materials/MeshLambertNodeMaterial.js b/examples/jsm/nodes/materials/MeshLambertNodeMaterial.js new file mode 100644 index 00000000000000..fc3b2a84e43df2 --- /dev/null +++ b/examples/jsm/nodes/materials/MeshLambertNodeMaterial.js @@ -0,0 +1,34 @@ +import NodeMaterial, { addNodeMaterial } from './NodeMaterial.js'; +import lambertLightingModel from '../functions/LambertLightingModel.js'; + +import { MeshLambertMaterial } from 'three'; + +const defaultValues = new MeshLambertMaterial(); + +class MeshLambertNodeMaterial extends NodeMaterial { + + constructor( parameters ) { + + super(); + + this.isMeshLambertNodeMaterial = true; + + this.lights = true; + + this.setDefaultValues( defaultValues ); + + this.setValues( parameters ); + + } + + constructLightingModel( /*builder*/ ) { + + return lambertLightingModel; + + } + +} + +export default MeshLambertNodeMaterial; + +addNodeMaterial( MeshLambertNodeMaterial );