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: BSDFs, SkinningNode updated to ShaderNode and ArrayElement support #22662

Merged
merged 21 commits into from
Oct 10, 2021

Conversation

sunag
Copy link
Collaborator

@sunag sunag commented Oct 8, 2021

Description

I rewrite the current PBR of WebGPU in GLSL to ShaderNode and I did some updates in NodeMaterial.

ShaderNode

const Skinning = new ShaderNode( ( inputs, builder ) => {

	const { position, normal, index, weight, bindMatrix, bindMatrixInverse, boneMatrices } = inputs;

	const boneMatX = element( boneMatrices, index.x );
	const boneMatY = element( boneMatrices, index.y );
	const boneMatZ = element( boneMatrices, index.z );
	const boneMatW = element( boneMatrices, index.w );

	// POSITION

	const skinVertex = mul( bindMatrix, position );

	const skinned = add(
		mul( mul( boneMatX, skinVertex ), weight.x ),
		mul( mul( boneMatY, skinVertex ), weight.y ),
		mul( mul( boneMatZ, skinVertex ), weight.z ),
		mul( mul( boneMatW, skinVertex ), weight.w )
	);

	const skinPosition = mul( bindMatrixInverse, skinned ).xyz;

	// NORMAL

	let skinMatrix = add(
		mul( weight.x, boneMatX ),
		mul( weight.y, boneMatY ),
		mul( weight.z, boneMatZ ),
		mul( weight.w, boneMatW )
	);

	skinMatrix = mul( mul( bindMatrixInverse, skinMatrix ), bindMatrix );

	const skinNormal = transformDirection( skinMatrix, normal ).xyz;

	// ASSIGNS

	assign( position, skinPosition ).build( builder );
	assign( normal, skinNormal ).build( builder );

} );

This contribution is funded by Google via Igalia.

@sunag sunag changed the title NodeMaterial: BSDFs updated to ShaderNode NodeMaterial: BSDFs, SkinningNode updated to ShaderNode and ArrayElement support Oct 9, 2021
@mrdoob
Copy link
Owner

mrdoob commented Oct 10, 2021

Looking good!

@mrdoob mrdoob added this to the r134 milestone Oct 10, 2021
@mrdoob mrdoob merged commit 96afd8d into mrdoob:dev Oct 10, 2021
@mrdoob
Copy link
Owner

mrdoob commented Oct 10, 2021

Thanks!

@sunag sunag deleted the dev-shadernodes branch October 10, 2021 11:52
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.

2 participants