Skip to content

How to use custom masks in MaterialExtension #20022

Answered by snappa-app
snappa-app asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks @JMS55 - that's super helpful. What I ended up doing to get it working was to copy the pbr_prepass.wgsl material, and then applying modifications to it.

This now allows me to mask out using AlphaMode::Mask(_). Right now when pixels are masked out, their shadows are removed. Eventually I'd like to have their shadows continue appearing, but this is suitable for now.

Now masked_prepass.wgsl looks like

//
// Begin
//

#import bevy_pbr::mesh_functions
#import "shaders/library/masking.wgsl"::{hide_when_masked}

struct MaskedMaterialExtension {
  occluder_data: array<vec4<f32>, 16384>,
}

@group(2) @binding(100)
var<uniform> masked_material: MaskedMaterialExtension;

//
// End
//


...
..…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by snappa-app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants