Fix post_processing and shader_prepass examples (#7419)

# Objective

- Fix `post_processing` and `shader_prepass` examples as they fail when compiling shaders due to missing shader defs
- Fixes #6799
- Fixes #6996
- Fixes #7375 
- Supercedes #6997
- Supercedes #7380 

## Solution

- The prepass was broken due to a missing `MAX_CASCADES_PER_LIGHT` shader def. Add it.
- The shader used in the `post_processing` example is applied to a 2D mesh, so use the correct mesh2d_view_bindings shader import.
This commit is contained in:
Robert Swain 2023-01-30 22:53:08 +00:00
parent 937fc039b1
commit 8b7ebe1738
2 changed files with 7 additions and 3 deletions

View file

@ -1,4 +1,4 @@
#import bevy_pbr::mesh_view_bindings #import bevy_sprite::mesh2d_view_bindings
#import bevy_pbr::utils #import bevy_pbr::utils
@group(1) @binding(0) @group(1) @binding(0)
@ -22,7 +22,7 @@ fn fragment(
textureSample(texture, our_sampler, uv + vec2<f32>(-offset_strength, 0.0)).g, textureSample(texture, our_sampler, uv + vec2<f32>(-offset_strength, 0.0)).g,
textureSample(texture, our_sampler, uv + vec2<f32>(0.0, offset_strength)).b, textureSample(texture, our_sampler, uv + vec2<f32>(0.0, offset_strength)).b,
1.0 1.0
); );
return output_color; return output_color;
} }

View file

@ -46,7 +46,7 @@ use bevy_utils::{tracing::error, HashMap};
use crate::{ use crate::{
AlphaMode, DrawMesh, Material, MaterialPipeline, MaterialPipelineKey, MeshPipeline, AlphaMode, DrawMesh, Material, MaterialPipeline, MaterialPipelineKey, MeshPipeline,
MeshPipelineKey, MeshUniform, RenderMaterials, SetMaterialBindGroup, SetMeshBindGroup, MeshPipelineKey, MeshUniform, RenderMaterials, SetMaterialBindGroup, SetMeshBindGroup,
MAX_DIRECTIONAL_LIGHTS, MAX_CASCADES_PER_LIGHT, MAX_DIRECTIONAL_LIGHTS,
}; };
use std::{hash::Hash, marker::PhantomData}; use std::{hash::Hash, marker::PhantomData};
@ -211,6 +211,10 @@ where
"MAX_DIRECTIONAL_LIGHTS".to_string(), "MAX_DIRECTIONAL_LIGHTS".to_string(),
MAX_DIRECTIONAL_LIGHTS as i32, MAX_DIRECTIONAL_LIGHTS as i32,
)); ));
shader_defs.push(ShaderDefVal::Int(
"MAX_CASCADES_PER_LIGHT".to_string(),
MAX_CASCADES_PER_LIGHT as i32,
));
if layout.contains(Mesh::ATTRIBUTE_UV_0) { if layout.contains(Mesh::ATTRIBUTE_UV_0) {
shader_defs.push("VERTEX_UVS".into()); shader_defs.push("VERTEX_UVS".into());