mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 20:53:53 +00:00
Extract interleaved_gradient_noise()
to utils.wgsl
This commit is contained in:
parent
dff2f3f4c4
commit
2e226bf7e8
3 changed files with 14 additions and 23 deletions
|
@ -1,7 +1,7 @@
|
|||
#define_import_path bevy_pbr::transmission
|
||||
|
||||
#import bevy_pbr::prepass_utils as prepass_utils
|
||||
#import bevy_pbr::utils PI
|
||||
#import bevy_pbr::utils PI, interleaved_gradient_noise
|
||||
#import bevy_pbr::mesh_view_bindings as view_bindings
|
||||
|
||||
fn specular_transmissive_light(world_position: vec4<f32>, frag_coord: vec3<f32>, view_z: f32, N: vec3<f32>, V: vec3<f32>, ior: f32, thickness: f32, perceptual_roughness: f32, specular_transmissive_color: vec3<f32>, transmitted_environment_light_specular: vec3<f32>) -> vec3<f32> {
|
||||
|
@ -38,18 +38,6 @@ fn specular_transmissive_light(world_position: vec4<f32>, frag_coord: vec3<f32>,
|
|||
return specular_transmissive_color * mix(transmitted_environment_light_specular, background_color.rgb, background_color.a);
|
||||
}
|
||||
|
||||
// https://blog.demofox.org/2022/01/01/interleaved-gradient-noise-a-different-kind-of-low-discrepancy-sequence
|
||||
fn interleaved_gradient_noise(pixel_coordinates: vec2<f32>) -> f32 {
|
||||
#ifdef TEMPORAL_JITTER
|
||||
let frame = f32(view_bindings::globals.frame_count % 64u);
|
||||
let xy = pixel_coordinates + 5.588238 * frame;
|
||||
#else
|
||||
// Don't vary noise per frame if TAA is not enabled
|
||||
let xy = pixel_coordinates;
|
||||
#endif
|
||||
return fract(52.9829189 * fract(0.06711056 * xy.x + 0.00583715 * xy.y));
|
||||
}
|
||||
|
||||
fn fetch_transmissive_background_non_rough(offset_position: vec2<f32>) -> vec4<f32> {
|
||||
return textureSample(
|
||||
view_bindings::view_transmission_texture,
|
||||
|
@ -80,7 +68,11 @@ fn fetch_transmissive_background(offset_position: vec2<f32>, frag_coord: vec3<f3
|
|||
let num_taps = 8; // Fallback to 8 taps, if not specified
|
||||
#endif
|
||||
let num_spirals = i32(ceil(f32(num_taps) / 8.0));
|
||||
let random_angle = interleaved_gradient_noise(frag_coord.xy);
|
||||
#ifdef TEMPORAL_JITTER
|
||||
let random_angle = interleaved_gradient_noise(frag_coord.xy, view_bindings::globals.frame_count);
|
||||
#else
|
||||
let random_angle = interleaved_gradient_noise(frag_coord.xy, 0u);
|
||||
#endif
|
||||
|
||||
// Pixel checkerboard pattern (helps make the interleaved gradient noise pattern less visible)
|
||||
let pixel_checkboard = (
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#define_import_path bevy_pbr::shadow_sampling
|
||||
|
||||
#import bevy_pbr::mesh_view_bindings as view_bindings
|
||||
#import bevy_pbr::utils PI
|
||||
#import bevy_pbr::utils PI, interleaved_gradient_noise
|
||||
|
||||
// Do the lookup, using HW 2x2 PCF and comparison
|
||||
fn sample_shadow_map_hardware(light_local: vec2<f32>, depth: f32, array_index: i32) -> f32 {
|
||||
|
@ -68,13 +68,6 @@ fn sample_shadow_map_castano_thirteen(light_local: vec2<f32>, depth: f32, array_
|
|||
return sum * (1.0 / 144.0);
|
||||
}
|
||||
|
||||
// https://blog.demofox.org/2022/01/01/interleaved-gradient-noise-a-different-kind-of-low-discrepancy-sequence
|
||||
fn interleaved_gradient_noise(pixel_coordinates: vec2<f32>) -> f32 {
|
||||
let frame = f32(view_bindings::globals.frame_count % 64u);
|
||||
let xy = pixel_coordinates + 5.588238 * frame;
|
||||
return fract(52.9829189 * fract(0.06711056 * xy.x + 0.00583715 * xy.y));
|
||||
}
|
||||
|
||||
fn map(min1: f32, max1: f32, min2: f32, max2: f32, value: f32) -> f32 {
|
||||
return min2 + (value - min1) * (max2 - min2) / (max1 - min1);
|
||||
}
|
||||
|
@ -82,7 +75,7 @@ fn map(min1: f32, max1: f32, min2: f32, max2: f32, value: f32) -> f32 {
|
|||
fn sample_shadow_map_jimenez_fourteen(light_local: vec2<f32>, depth: f32, array_index: i32, texel_size: f32) -> f32 {
|
||||
let shadow_map_size = vec2<f32>(textureDimensions(view_bindings::directional_shadow_textures));
|
||||
|
||||
let random_angle = 2.0 * PI * interleaved_gradient_noise(light_local * shadow_map_size);
|
||||
let random_angle = 2.0 * PI * interleaved_gradient_noise(light_local * shadow_map_size, view_bindings::globals.frame_count);
|
||||
let m = vec2(sin(random_angle), cos(random_angle));
|
||||
let rotation_matrix = mat2x2(
|
||||
m.y, -m.x,
|
||||
|
|
|
@ -48,3 +48,9 @@ fn octahedral_decode(v: vec2<f32>) -> vec3<f32> {
|
|||
n = vec3(n.xy + w, n.z);
|
||||
return normalize(n);
|
||||
}
|
||||
|
||||
// https://blog.demofox.org/2022/01/01/interleaved-gradient-noise-a-different-kind-of-low-discrepancy-sequence
|
||||
fn interleaved_gradient_noise(pixel_coordinates: vec2<f32>, frame: u32) -> f32 {
|
||||
let xy = pixel_coordinates + 5.588238 * f32(frame % 64u);
|
||||
return fract(52.9829189 * fract(0.06711056 * xy.x + 0.00583715 * xy.y));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue