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

WebGPU support for rendering to shadow map for Directional lights #4924

Merged
merged 2 commits into from
Dec 15, 2022

Conversation

mvaligursky
Copy link
Contributor

@mvaligursky mvaligursky commented Dec 14, 2022

WebGPU platform can render to a shadow map for directional light. The shadow map cannot be still used to sample from, that would be done in a follow up PR.

Part of the changes is refactoring of ShadowRendererLocal and ShadowRendererDirectional - those no longer extend the ShadowRenderer, but share a single instance of it, to limit some resource duplication.

Screenshot 2022-12-14 at 11 32 20

@mvaligursky mvaligursky changed the title WebGPU support for rendering to shadow map WebGPU support for rendering to shadow map for Directional lights Dec 14, 2022
@mvaligursky mvaligursky self-assigned this Dec 14, 2022
Comment on lines +85 to +90
destroy() {
this.viewBindGroups.forEach((bg) => {
bg.defaultUniformBuffer.destroy();
bg.destroy();
});
this.viewBindGroups.length = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't it make sense to delete bg.defaultUniformBuffer in BindGroup#destroy instead? It feels like BindGroup#destroy isn't doing a full job when you still need to delete internal properties yourself first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a property value I assign to it, but it does not own it, as multiple bindGroups can use the same uniform buffer. If JS had some easier way to do ref counting, this would be ref counted perhaps.
It's similar to how when you create a render target, you give it color buffer, but you need to destroy it even when RT itself is destroyed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually, a material -> texture is even more similar to this. Texture, as well as Uniform Buffer is a buffer GPU resource. Material does not own it, it does not destroy it, only uses it. Same here. In this specific instance, there is only one user of this uniform buffer, so I destroy it, but that's not a case in general.

@mvaligursky mvaligursky merged commit 9e42653 into main Dec 15, 2022
@mvaligursky mvaligursky deleted the mv-webgpu-shadow-map branch December 15, 2022 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: graphics Graphics related issue feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants