Skip to content

Commit

Permalink
Handle vertex_uvs if they are present in default prepass fragment sha…
Browse files Browse the repository at this point in the history
…der (#8330)

# Objective

- Enabling AlphaMode::Opaque in the shader_prepass example crashes. The
issue seems to be that enabling opaque also generates vertex_uvs

Fixes #8273

## Solution

- Use the vertex_uvs in the shader if they are present
  • Loading branch information
IceSentry authored Apr 23, 2023
1 parent 4580a91 commit 3f6367d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions crates/bevy_pbr/src/prepass/prepass.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ fn vertex(vertex: Vertex) -> VertexOutput {

#ifdef PREPASS_FRAGMENT
struct FragmentInput {
#ifdef VERTEX_UVS
@location(0) uv: vec2<f32>,
#endif // VERTEX_UVS

#ifdef NORMAL_PREPASS
@location(1) world_normal: vec3<f32>,
#endif // NORMAL_PREPASS
Expand Down
14 changes: 9 additions & 5 deletions examples/shader/shader_prepass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ fn setup(
});

// A quad that shows the outputs of the prepass
// To make it easy, we just draw a big quad right in front of the camera. For a real application, this isn't ideal.
// To make it easy, we just draw a big quad right in front of the camera.
// For a real application, this isn't ideal.
commands.spawn((
MaterialMeshBundle {
mesh: meshes.add(shape::Quad::new(Vec2::new(20.0, 20.0)).into()),
Expand All @@ -77,11 +78,15 @@ fn setup(
NotShadowCaster,
));

// Opaque cube using the StandardMaterial
// Opaque cube
commands.spawn((
PbrBundle {
MaterialMeshBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
material: std_materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
material: materials.add(CustomMaterial {
color: Color::WHITE,
color_texture: Some(asset_server.load("branding/icon.png")),
alpha_mode: AlphaMode::Opaque,
}),
transform: Transform::from_xyz(-1.0, 0.5, 0.0),
..default()
},
Expand All @@ -96,7 +101,6 @@ fn setup(
base_color_texture: Some(asset_server.load("branding/icon.png")),
..default()
}),

transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
});
Expand Down

0 comments on commit 3f6367d

Please sign in to comment.