Skip to content

Commit 92eec47

Browse files
committed
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`.
1 parent fa56a5c commit 92eec47

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

crates/bevy_pbr/src/render/pbr.wgsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn fragment(in: FragmentInput) -> [[location(0)]] vec4<f32> {
8585
);
8686
pbr_input.V = calculate_view(in.world_position, pbr_input.is_orthographic);
8787

88-
output_color = pbr(pbr_input);
88+
output_color = tone_mapping(pbr(pbr_input));
8989
}
9090

9191
return output_color;

crates/bevy_pbr/src/render/pbr_functions.wgsl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,14 @@ fn pbr(
186186
cluster_index,
187187
);
188188

189+
return output_color;
190+
}
191+
192+
fn tone_mapping(in: vec4<f32>) -> vec4<f32> {
189193
// tone_mapping
190-
output_color = vec4<f32>(reinhard_luminance(output_color.rgb), output_color.a);
194+
return vec4<f32>(reinhard_luminance(in.rgb), in.a);
195+
191196
// Gamma correction.
192197
// Not needed with sRGB buffer
193198
// output_color.rgb = pow(output_color.rgb, vec3(1.0 / 2.2));
194-
195-
return output_color;
196199
}

0 commit comments

Comments
 (0)