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: Fix receiveShadow and introduce shadowPositionNode #28146

Merged
merged 5 commits into from
Apr 17, 2024

Conversation

RenaudRohlinger
Copy link
Collaborator

@RenaudRohlinger RenaudRohlinger commented Apr 16, 2024

Description

Currently, setting material.receiveShadow = false does not affect the shadow behavior. This pull request fixes the issue.
This pull request also introduces shadowPositionNode which allows the modification of the comparison point for objects receiving the shadow.

There is a current limitation with light.shadowNode, which globally affects all the meshes receiving a shadow from a light, and material.shadowNode, which modifies the behavior of the mesh that casts a shadow. material.shadowPositionNode modifies the behavior of the mesh that receives the shadow.

This allows the alignment of shadows on custom surfaces modified by nodes or even custom effects on specific surface, for example:

planeMaterial.shadowPositionNode = tslFn( () => {

	const pos = positionWorld.toVar();
	pos.xz.addAssign( mx_fractal_noise_vec3( positionWorld.mul( 2 ) ).saturate().xz );
	return pos;

} )();
image

PS: Since it's more about the pixels rather than the position of the vertices, would something like shadowCompareNode be better? /cc @sunag

This contribution is funded by Utsubo

@RenaudRohlinger RenaudRohlinger requested a review from sunag April 16, 2024 13:35
@sunag
Copy link
Collaborator

sunag commented Apr 16, 2024

Very nice! Do you think about adding the example updated?

@RenaudRohlinger
Copy link
Collaborator Author

Good idea! Done 👍

@RenaudRohlinger RenaudRohlinger added this to the r164 milestone Apr 17, 2024
@sunag sunag merged commit 34cfc4d into mrdoob:dev Apr 17, 2024
11 checks passed
let shadowCoord = uniform( shadow.matrix ).mul( positionWorld.add( normalWorld.mul( normalBias ) ) );
const position = object.material.shadowPositionNode || positionWorld;

let shadowCoord = uniform( shadow.matrix ).mul( position.add( normalWorld.mul( normalBias ) ) );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we create an offset of the normals instead of changing the position? We could use it on other types of surfaces, this seems limiting to me since normalWorld continues with the reference from the previous position.

An update I haven't made yet... I think we should test is that the leftover normals should follow the object's normalMap changes.

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