Search across packages, versions, files, declarations, and comments. Use multiple terms to narrow results (AND), and add @vertex, @fragment, or @compute to filter by shader stage.
1import bevy_pbr::deferred::types::unpack_24bit_normal;
2import bevy_pbr::render::rgb9e5::rgb9e5_to_vec3_;
3import bevy_render::utils::octahedral_decode;
4import bevy_render::view::{View, depth_ndc_to_view_z};
5import package::scene::bindings::ResolvedMaterial;
7struct ResolvedGPixel {
8 world_position: vec3<f32>,
9 world_normal: vec3<f32>,
10 material: ResolvedMaterial,
13fn gpixel_resolve(gpixel: vec4<u32>, depth: f32, pixel_id: vec2<u32>, view_size: vec2<f32>, world_from_clip: mat4x4<f32>) -> ResolvedGPixel {
14 let world_position = reconstruct_world_position(pixel_id, depth, view_size, world_from_clip);
15 let world_normal = octahedral_decode(unpack_24bit_normal(gpixel.a));
17 let base_rough = unpack4x8unorm(gpixel.r);
18 let base_color = pow(base_rough.rgb, vec3(2.2));
19 let perceptual_roughness = base_rough.a;
20 let roughness = perceptual_roughness * perceptual_roughness;
21 let props = unpack4x8unorm(gpixel.b);
22 let reflectance = props.r;
23 let metallic = props.g;
24 let emissive = rgb9e5_to_vec3_(gpixel.g);
25 let material = ResolvedMaterial(base_color, emissive, reflectance, perceptual_roughness, roughness, metallic);
27 return ResolvedGPixel(world_position, world_normal, material);
30fn reconstruct_world_position(pixel_id: vec2<u32>, depth: f32, view_size: vec2<f32>, world_from_clip: mat4x4<f32>) -> vec3<f32> {
31 let uv = (vec2<f32>(pixel_id) + 0.5) / view_size;
32 let xy_ndc = (uv - vec2(0.5)) * vec2(2.0, -2.0);
33 let world_pos = world_from_clip * vec4(xy_ndc, depth, 1.0);
34 return world_pos.xyz / world_pos.w;
37/// Reject if tangent plane differs more than 0.3% or angle between normals more than 90 degrees
38fn pixel_dissimilar(depth: f32, world_position: vec3<f32>, other_world_position: vec3<f32>, normal: vec3<f32>, other_normal: vec3<f32>, view: View) -> bool {
39 // https://developer.download.nvidia.com/video/gputechconf/gtc/2020/presentations/s22699-fast-denoising-with-self-stabilizing-recurrent-blurs.pdf#page=45
40 let tangent_plane_distance = abs(dot(normal, other_world_position - world_position));
41 let view_z = -depth_ndc_to_view_z(depth, view.clip_from_view, view.view_from_clip);
43 return tangent_plane_distance / view_z > 0.003 || dot(normal, other_normal) < 0.0;
46fn permute_pixel(pixel_id: vec2<u32>, frame_index: u32, view_size: vec2<f32>) -> vec2<u32> {
47 let r = frame_index;
48 let offset = vec2<i32>(i32(r & 3u), i32((r >> 2u) & 3u));
49 var shifted_pixel_id = vec2<i32>(pixel_id) + offset;
50 shifted_pixel_id ^= vec2<i32>(3);
51 shifted_pixel_id -= offset;
52 if any(shifted_pixel_id < vec2<i32>(0)) || any(shifted_pixel_id >= vec2<i32>(view_size)) {
53 return pixel_id;
54 }
55 return vec2<u32>(shifted_pixel_id);
Contents