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

Stencil Mask Example #415

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cmhhelgeson
Copy link
Contributor

@cmhhelgeson cmhhelgeson commented Apr 5, 2024

EDITED 4/3/24

A simple masking example leveraging the stencil buffer. Masks can be positioned with the mouse, resized with the scroll wheel, and inverted.

The example is intended to demonstrate how users can modify existing code with minimal adjustments to create masks with the stencil, render into different scenes, and leverage the capabilities of the render pipeline to directly modify the stencil buffer across one or more passes by disabling the pipeline's color and depth write functionality.
Capture

@cmhhelgeson
Copy link
Contributor Author

Linking to relevant issue #150. Perhaps the reflective floor demo could also be added.

@cmhhelgeson
Copy link
Contributor Author

Hi, I just wanted to check in and see if there was anything more I could do here, of if a different kind of sample would be preferred (reflective floor, orbit around a portal, etc.)

@austinEng austinEng requested a review from greggman May 14, 2024 03:05
@greggman
Copy link
Collaborator

greggman commented May 14, 2024

Sorry, I looked at this a month ago and it seemed not finished so I assumed you were planning to post more? The code references fullscreenQuad.wgsl but no such file exists. It also references positionQuad.vert.wgsl but no such file exists. It also claims to move the mask with the mouse but that doesn't seem to happen.

Personally, I'm not sure it's a good example of what to use a stencil for. Blending between two images is more generally done with alpha channels since you can choose the level of blending per pixel. Rendering to the stencil with an SDF also seems unusual. Of course just seeing a stencil mask work is a probably a good example. I was just thinking it would be nice to see a practical example vs a contrived example. Unfortunately I couldn't think of one.

At the very least, what do you think about making the 2 scenes more varied? As it is, 4x4 grid of blue cubes vs a 4x4 rainbow cubes makes it seems like the effect is changing the cubes vs masking one rendering vs another. In other words, maybe one scene is 4x4 cubes and the other scene is a rotating spiral of spheres. (or something?) just throwing out ideas. for example

Another idea would be to look at some common uses for the canvas 2d mask

@cmhhelgeson
Copy link
Contributor Author

Sorry, I looked at this a month ago and it seemed not finished so I assumed you were planning to post more? The code references fullscreenQuad.wgsl but no such file exists. It also references positionQuad.vert.wgsl but no such file exists. It also claims to move the mask with the mouse but that doesn't seem to happen.

Personally, I'm not sure it's a good example of what to use a stencil for. Blending between two images is more generally done with alpha channels since you can choose the level of blending per pixel. Rendering to the stencil with an SDF also seems unusual. Of course just seeing a stencil mask work is a probably a good example. I was just thinking it would be nice to see a practical example vs a contrived example. Unfortunately I couldn't think of one.

At the very least, what do you think about making the 2 scenes more varied? As it is, 4x4 grid of blue cubes vs a 4x4 rainbow cubes makes it seems like the effect is changing the cubes vs masking one rendering vs another. In other words, maybe one scene is 4x4 cubes and the other scene is a rotating spiral of spheres. (or something?) just throwing out ideas. for example

Another idea would be to look at some common uses for the canvas 2d mask

Wouldn't it just make more sense to port that existing sample over to webgpu-samples?

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.

None yet

2 participants