From ddd4b4daf8bb3df1dac0fd5f453269ff4bd4f99a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20S=C3=B8holm?= Date: Sat, 5 Oct 2024 00:51:23 +0200 Subject: [PATCH] Fix deferred rendering (#15656) # Objective Fixes #15525 The deferred and mesh pipelines tonemapping LUT bindings were accidentally out of sync, breaking deferred rendering. As noted in the issue it's still broken on wasm due to hitting a texture limit. ## Solution Add constants for these instead of hardcoding them. ## Testing Test with `cargo run --example deferred_rendering` and see it works, run the same on main and see it crash. --- crates/bevy_pbr/src/deferred/mod.rs | 7 ++++--- crates/bevy_pbr/src/lib.rs | 3 +++ crates/bevy_pbr/src/render/mesh.rs | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/crates/bevy_pbr/src/deferred/mod.rs b/crates/bevy_pbr/src/deferred/mod.rs index fe1a652d2404b..bcb23a7048bfd 100644 --- a/crates/bevy_pbr/src/deferred/mod.rs +++ b/crates/bevy_pbr/src/deferred/mod.rs @@ -2,7 +2,8 @@ use crate::{ graph::NodePbr, irradiance_volume::IrradianceVolume, prelude::EnvironmentMapLight, MeshPipeline, MeshViewBindGroup, RenderViewLightProbes, ScreenSpaceAmbientOcclusion, ScreenSpaceReflectionsUniform, ViewEnvironmentMapUniformOffset, ViewLightProbesUniformOffset, - ViewScreenSpaceReflectionsUniformOffset, + ViewScreenSpaceReflectionsUniformOffset, TONEMAPPING_LUT_SAMPLER_BINDING_INDEX, + TONEMAPPING_LUT_TEXTURE_BINDING_INDEX, }; use bevy_app::prelude::*; use bevy_asset::{load_internal_asset, Handle}; @@ -259,11 +260,11 @@ impl SpecializedRenderPipeline for DeferredLightingLayout { shader_defs.push("TONEMAP_IN_SHADER".into()); shader_defs.push(ShaderDefVal::UInt( "TONEMAPPING_LUT_TEXTURE_BINDING_INDEX".into(), - 22, + TONEMAPPING_LUT_TEXTURE_BINDING_INDEX, )); shader_defs.push(ShaderDefVal::UInt( "TONEMAPPING_LUT_SAMPLER_BINDING_INDEX".into(), - 23, + TONEMAPPING_LUT_SAMPLER_BINDING_INDEX, )); let method = key.intersection(MeshPipelineKey::TONEMAP_METHOD_RESERVED_BITS); diff --git a/crates/bevy_pbr/src/lib.rs b/crates/bevy_pbr/src/lib.rs index 68f75af7bef86..369efdcb59c0b 100644 --- a/crates/bevy_pbr/src/lib.rs +++ b/crates/bevy_pbr/src/lib.rs @@ -158,6 +158,9 @@ pub const RGB9E5_FUNCTIONS_HANDLE: Handle = Handle::weak_from_u128(26590 const MESHLET_VISIBILITY_BUFFER_RESOLVE_SHADER_HANDLE: Handle = Handle::weak_from_u128(2325134235233421); +const TONEMAPPING_LUT_TEXTURE_BINDING_INDEX: u32 = 23; +const TONEMAPPING_LUT_SAMPLER_BINDING_INDEX: u32 = 24; + /// Sets up the entire PBR infrastructure of bevy. pub struct PbrPlugin { /// Controls if the prepass is enabled for the [`StandardMaterial`]. diff --git a/crates/bevy_pbr/src/render/mesh.rs b/crates/bevy_pbr/src/render/mesh.rs index 91f93c61b2560..0b4a3e3bda499 100644 --- a/crates/bevy_pbr/src/render/mesh.rs +++ b/crates/bevy_pbr/src/render/mesh.rs @@ -1842,11 +1842,11 @@ impl SpecializedMeshPipeline for MeshPipeline { shader_defs.push("TONEMAP_IN_SHADER".into()); shader_defs.push(ShaderDefVal::UInt( "TONEMAPPING_LUT_TEXTURE_BINDING_INDEX".into(), - 23, + TONEMAPPING_LUT_TEXTURE_BINDING_INDEX, )); shader_defs.push(ShaderDefVal::UInt( "TONEMAPPING_LUT_SAMPLER_BINDING_INDEX".into(), - 24, + TONEMAPPING_LUT_SAMPLER_BINDING_INDEX, )); let method = key.intersection(MeshPipelineKey::TONEMAP_METHOD_RESERVED_BITS);