From 8b7ebe1738515bd46dcfb19d225c5aa91d364aa0 Mon Sep 17 00:00:00 2001 From: Robert Swain Date: Mon, 30 Jan 2023 22:53:08 +0000 Subject: [PATCH] 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. --- assets/shaders/custom_material_chromatic_aberration.wgsl | 4 ++-- crates/bevy_pbr/src/prepass/mod.rs | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/assets/shaders/custom_material_chromatic_aberration.wgsl b/assets/shaders/custom_material_chromatic_aberration.wgsl index e09580848f..787947ce10 100644 --- a/assets/shaders/custom_material_chromatic_aberration.wgsl +++ b/assets/shaders/custom_material_chromatic_aberration.wgsl @@ -1,4 +1,4 @@ -#import bevy_pbr::mesh_view_bindings +#import bevy_sprite::mesh2d_view_bindings #import bevy_pbr::utils @group(1) @binding(0) @@ -22,7 +22,7 @@ fn fragment( textureSample(texture, our_sampler, uv + vec2(-offset_strength, 0.0)).g, textureSample(texture, our_sampler, uv + vec2(0.0, offset_strength)).b, 1.0 - ); + ); return output_color; } diff --git a/crates/bevy_pbr/src/prepass/mod.rs b/crates/bevy_pbr/src/prepass/mod.rs index 3d31258a42..cea5c77abd 100644 --- a/crates/bevy_pbr/src/prepass/mod.rs +++ b/crates/bevy_pbr/src/prepass/mod.rs @@ -46,7 +46,7 @@ use bevy_utils::{tracing::error, HashMap}; use crate::{ AlphaMode, DrawMesh, Material, MaterialPipeline, MaterialPipelineKey, MeshPipeline, MeshPipelineKey, MeshUniform, RenderMaterials, SetMaterialBindGroup, SetMeshBindGroup, - MAX_DIRECTIONAL_LIGHTS, + MAX_CASCADES_PER_LIGHT, MAX_DIRECTIONAL_LIGHTS, }; use std::{hash::Hash, marker::PhantomData}; @@ -211,6 +211,10 @@ where "MAX_DIRECTIONAL_LIGHTS".to_string(), 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) { shader_defs.push("VERTEX_UVS".into());