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

TSL: shadows #29838

Merged
merged 1 commit into from
Nov 8, 2024
Merged

TSL: shadows #29838

merged 1 commit into from
Nov 8, 2024

Conversation

sunag
Copy link
Collaborator

@sunag sunag commented Nov 7, 2024

Description

The shadows node allows shadows to be used as masks for effects.

import { output, shadows } from 'three/tsl';

material.outputNode = output.add( shadows );

image

@sunag sunag added this to the r171 milestone Nov 7, 2024
@sunag sunag marked this pull request as ready for review November 7, 2024 23:41
@sunag sunag changed the title TSL: Added shadows TSL: shadows Nov 7, 2024
Copy link

github-actions bot commented Nov 7, 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.46
222.91
825.57
222.93
+104 B
+20 B
WebGPU Nodes 824.58
222.7
824.68
222.72
+104 B
+27 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.63
147.78
545.69
147.79
+62 B
+11 B
WebGPU Nodes 501.51
137.48
501.57
137.49
+62 B
+15 B

@sunag sunag merged commit 736201e into mrdoob:dev Nov 8, 2024
12 checks passed
@sunag sunag deleted the dev-shadows branch November 8, 2024 02:07
@Makio64
Copy link
Contributor

Makio64 commented Nov 8, 2024

@sunag Asking for my personal understanding :
1 : this allow us to get the shadow casted on the mesh and use it in the material for example for adding a dithering or modifying the color of the shadow on the material ( in the fragment shader level ) ?
2 : this allow us to modifying the shadow texture before its send to the material ( for example to add blur on it )

@sunag
Copy link
Collaborator Author

sunag commented Nov 8, 2024

We have some API features aimed at different purposes.

  • material.shadowNode -> Allows you to change the opacity and color of the shadow, or procedural effect in TSL.
    https://threejs.org/examples/?q=shadow%20opacity#webgpu_shadowmap_opacity

  • material.outputNode = output.add( shadows ) -> Allows you to obtain the shadow at the output level, useful for creating special effects based on the shadow, such as using the shadow as a mask to project another node in the shadow area in the target material. Note that add() can be replaced by another mathematical operation here.

  • light.shadow.filterNode -> Here customizing the shadow filter, such as using PCFSoftShadowMap or creating your own, is the appropriate place to soften the shadow.

@Makio64
Copy link
Contributor

Makio64 commented Nov 8, 2024

Thanks for clarifying! Just to be sure :

Shadows render pass :
material.shadowNode : how the material project his shadow into the shadowmap during the rendering of lights
light.shadow.filterNode : filter apply during the rendering of the lights ( blur etc.. )

Scene render pass :
shadows : the value of the compile shadows at the pixel level ( in the fragment shaders ).

So when you do :
material.outputNode = output.add( shadows ) it add the shadow value over the output which already have shadows ?
If I want to rewrite how the shadow is rendered on my mesh for example with a very low opacity for a 'GhostMaterial' how to do so ( I originaly thought it was the purpose of the shadowNode. ) ?

Maybe shadowNode is little bit confusing and a castShadowNode and a receivedShadowNodewould be easier or maybe its just me ?

@sunag
Copy link
Collaborator Author

sunag commented Nov 8, 2024

Maybe shadowNode is little bit confusing and a castShadowNode and a receivedShadowNodewould be easier or maybe its just me ?

castShadowNode seems like a good name 👍

@sunag
Copy link
Collaborator Author

sunag commented Nov 8, 2024

@Makio64 I think this will be possible now, the suggestion was great and I updated the API.
#29840

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