Skip to content

Commit

Permalink
Separate PBR and tone mapping into 2 functions (bevyengine#5078)
Browse files Browse the repository at this point in the history
# Objective

- Allow custom shaders to reuse the HDR results of PBR.

## Solution

- Separate `pbr()` and `tone_mapping()` into 2 functions in `pbr_functions.wgsl`.
  • Loading branch information
cryscan authored and james7132 committed Oct 28, 2022
1 parent 1c3af19 commit 2e0ec34
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/render/pbr.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn fragment(in: FragmentInput) -> [[location(0)]] vec4<f32> {
);
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;
Expand Down
9 changes: 6 additions & 3 deletions crates/bevy_pbr/src/render/pbr_functions.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,14 @@ fn pbr(
cluster_index,
);

return output_color;
}

fn tone_mapping(in: vec4<f32>) -> vec4<f32> {
// tone_mapping
output_color = vec4<f32>(reinhard_luminance(output_color.rgb), output_color.a);
return vec4<f32>(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;
}

0 comments on commit 2e0ec34

Please sign in to comment.