Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGPURenderer: Add MeshLambertNodeMaterial #26448

Merged
merged 1 commit into from
Jul 17, 2023
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
24 changes: 24 additions & 0 deletions examples/jsm/nodes/functions/LambertLightingModel.js
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions examples/jsm/nodes/materials/Materials.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
34 changes: 34 additions & 0 deletions examples/jsm/nodes/materials/MeshLambertNodeMaterial.js
Original file line number Diff line number Diff line change
@@ -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 );