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: Added .castShadowNode and .receivedShadowNode #29840

Merged
merged 2 commits into from
Nov 8, 2024

Conversation

sunag
Copy link
Collaborator

@sunag sunag commented Nov 8, 2024

Related issue: #29838 (comment)

Description

Renaming .shadowNode to .castShadowNode seems like a better name and more in line with the Three.js API regarding shadow casting.

.receivedShadowNode is the new input, and should use TSL Fn as input, where the manipulation of the received shadow can be performed. Using Fn we can also create the shadows mask manually, so I removed the node shadows to avoid redundancy.

  • Added material.castShadowNode and material.receivedShadowNode
  • Removed shadows

Manual way to add shadows

const totalShadows = float( 1 ).toVar();

ground.material.receivedShadowNode = Fn( ( [ shadow ] ) => {

	totalShadows.mulAssign( shadow );

	//return float( 1 ); // bypass received shadows
	return shadow.mix( color( 0xff0000 ), 1 ); // modify shadow color

} );

// ground.material.outputNode = output.add( totalShadows.oneMinus() ); // shadow mask output

Copy link

github-actions bot commented Nov 8, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 692.22
171.45
692.22
171.45
+0 B
+0 B
WebGPU 825.57
222.93
825.78
222.98
+208 B
+57 B
WebGPU Nodes 824.68
222.72
824.89
222.78
+208 B
+51 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 464.58
112.26
464.58
112.26
+0 B
+0 B
WebGPU 545.69
147.79
545.94
147.85
+250 B
+56 B
WebGPU Nodes 501.57
137.49
501.82
137.55
+250 B
+53 B

@sunag sunag added this to the r171 milestone Nov 8, 2024
@sunag sunag marked this pull request as ready for review November 8, 2024 04:18
@sunag sunag mentioned this pull request Nov 8, 2024
@sunag sunag merged commit 8f55e4b into mrdoob:dev Nov 8, 2024
12 checks passed
@sunag sunag deleted the dev-shadows-2 branch November 8, 2024 14:55
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.

1 participant