From ab579c89c09edff0baab57d1392b66e12a7f1138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A0=94=E7=A9=B6=E7=A4=BE=E4=BA=A4?= Date: Sun, 26 Jun 2022 00:00:23 +0000 Subject: [PATCH] Separate PBR and tone mapping into 2 functions (#5078) # Objective - Allow custom shaders to reuse the HDR results of PBR. ## Solution - Separate `pbr()` and `tone_mapping()` into 2 functions in `pbr_functions.wgsl`. --- crates/bevy_pbr/src/render/pbr.wgsl | 2 +- crates/bevy_pbr/src/render/pbr_functions.wgsl | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/bevy_pbr/src/render/pbr.wgsl b/crates/bevy_pbr/src/render/pbr.wgsl index 3f169d5104f665..f4ba112e6e5553 100644 --- a/crates/bevy_pbr/src/render/pbr.wgsl +++ b/crates/bevy_pbr/src/render/pbr.wgsl @@ -85,7 +85,7 @@ fn fragment(in: FragmentInput) -> [[location(0)]] vec4 { ); pbr_input.V = calculate_view(in.world_position, pbr_input.is_orthographic); - output_color = pbr(pbr_input); + output_color = tone_mapping(pbr(pbr_input)); } return output_color; diff --git a/crates/bevy_pbr/src/render/pbr_functions.wgsl b/crates/bevy_pbr/src/render/pbr_functions.wgsl index a2349fcbdeee38..04986fad1586eb 100644 --- a/crates/bevy_pbr/src/render/pbr_functions.wgsl +++ b/crates/bevy_pbr/src/render/pbr_functions.wgsl @@ -186,11 +186,14 @@ fn pbr( cluster_index, ); + return output_color; +} + +fn tone_mapping(in: vec4) -> vec4 { // tone_mapping - output_color = vec4(reinhard_luminance(output_color.rgb), output_color.a); + return vec4(reinhard_luminance(in.rgb), in.a); + // Gamma correction. // Not needed with sRGB buffer // output_color.rgb = pow(output_color.rgb, vec3(1.0 / 2.2)); - - return output_color; }