# Objective `bevy_pbr/utils.wgsl` shader file contains mathematical constants and color conversion functions. Both of those should be accessible without enabling `bevy_pbr` feature. For example, tonemapping can be done in non pbr scenario, and it uses color conversion functions. Fixes #13207 ## Solution * Move mathematical constants (such as PI, E) from `bevy_pbr/src/render/utils.wgsl` into `bevy_render/src/maths.wgsl` * Move color conversion functions from `bevy_pbr/src/render/utils.wgsl` into new file `bevy_render/src/color_operations.wgsl` ## Testing Ran multiple examples, checked they are working: * tonemapping * color_grading * 3d_scene * animated_material * deferred_rendering * 3d_shapes * fog * irradiance_volumes * meshlet * parallax_mapping * pbr * reflection_probes * shadow_biases * 2d_gizmos * light_gizmos --- ## Changelog * Moved mathematical constants (such as PI, E) from `bevy_pbr/src/render/utils.wgsl` into `bevy_render/src/maths.wgsl` * Moved color conversion functions from `bevy_pbr/src/render/utils.wgsl` into new file `bevy_render/src/color_operations.wgsl` ## Migration Guide In user's shader code replace usage of mathematical constants from `bevy_pbr::utils` to the usage of the same constants from `bevy_render::maths`.
25 lines
843 B
WebGPU Shading Language
25 lines
843 B
WebGPU Shading Language
#define_import_path bevy_pbr::gtao_utils
|
|
|
|
#import bevy_render::maths::{PI, HALF_PI}
|
|
|
|
// Approximates single-bounce ambient occlusion to multi-bounce ambient occlusion
|
|
// https://blog.selfshadow.com/publications/s2016-shading-course/activision/s2016_pbs_activision_occlusion.pdf#page=78
|
|
fn gtao_multibounce(visibility: f32, base_color: vec3<f32>) -> vec3<f32> {
|
|
let a = 2.0404 * base_color - 0.3324;
|
|
let b = -4.7951 * base_color + 0.6417;
|
|
let c = 2.7552 * base_color + 0.6903;
|
|
let x = vec3<f32>(visibility);
|
|
return max(x, ((x * a + b) * x + c) * x);
|
|
}
|
|
|
|
fn fast_sqrt(x: f32) -> f32 {
|
|
return bitcast<f32>(0x1fbd1df5 + (bitcast<i32>(x) >> 1u));
|
|
}
|
|
|
|
fn fast_acos(in_x: f32) -> f32 {
|
|
let x = abs(in_x);
|
|
var res = -0.156583 * x + HALF_PI;
|
|
res *= fast_sqrt(1.0 - x);
|
|
return select(PI - res, res, in_x >= 0.0);
|
|
}
|