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

NodeMaterial & WebGPU: Revision of Lighting Model System #25170

Merged
merged 25 commits into from
Dec 23, 2022

Conversation

sunag
Copy link
Collaborator

@sunag sunag commented Dec 22, 2022

Description

We have a much more solid system for creating Lighting Models, WebGPURenderer is completely based on nodes, this means that you can create new materials and new light types, modular and tree-shaking so that we don't have to of hacks ever again :)

MeshStandardNodeMaterial

 class MeshStandardNodeMaterial extends NodeMaterial {

	constructLightingModel( /*builder*/ ) {

		return physicalLightingModel;

	}

	constructVariants( builder, stack ) {

		// METALNESS

		let metalnessNode = this.metalnessNode ? float( this.metalnessNode ) : materialMetalness;

		stack.assign( metalness, metalnessNode );
		stack.assign( diffuseColor, vec4( diffuseColor.rgb.mul( metalnessNode.invert() ), diffuseColor.a ) );

		// ROUGHNESS

		let roughnessNode = this.roughnessNode ? float( this.roughnessNode ) : materialRoughness;
		roughnessNode = getRoughness.call( { roughness: roughnessNode } );

		stack.assign( roughness, roughnessNode );

		// SPECULAR COLOR

		const specularColorNode = mix( vec3( 0.04 ), materialColor.rgb, metalnessNode );

		stack.assign( specularColor, specularColorNode );

	}

}

MeshPhongNodeMaterial

 class MeshPhongNodeMaterial extends NodeMaterial {

	constructLightingModel( /*builder*/ ) {

		return phongLightingModel;

	}

	constructVariants( builder, stack ) {

		// SHININESS

		const shininessNode = float( this.shininessNode || materialShininess ).max( 1e-4 ); // to prevent pow( 0.0, 0.0 )

		stack.assign( shininess, shininessNode );

		// SPECULAR COLOR

		const specularNode = vec3( this.specularNode || materialSpecularColor );

		stack.assign( specularColor, specularNode );

	}

}

image

Highlights

This contribution is funded by Google via Igalia

@sunag sunag marked this pull request as ready for review December 22, 2022 07:11
@sunag sunag added this to the r149 milestone Dec 22, 2022
@sunag
Copy link
Collaborator Author

sunag commented Dec 22, 2022

I updated the description.

@sunag sunag merged commit 0bec83f into mrdoob:dev Dec 23, 2022
@sunag sunag deleted the dev-node-system-revision branch December 23, 2022 17:42
@0b5vr 0b5vr mentioned this pull request Jan 12, 2023
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants