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.
1enable wgpu_ray_query;
3struct Uniforms {
4 view_inv: mat4x4<f32>,
5 proj_inv: mat4x4<f32>,
6};
7@group(0) @binding(0)
8var<uniform> uniforms: Uniforms;
10@group(0) @binding(1)
11var output: texture_storage_2d<rgba8unorm, write>;
13@group(0) @binding(2)
14var acc_struct: acceleration_structure;
16@compute @workgroup_size(8, 8)
17fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
18 let target_size = textureDimensions(output);
20 let pixel_center = vec2<f32>(global_id.xy) + vec2<f32>(0.5);
21 let in_uv = pixel_center / vec2<f32>(target_size.xy);
22 let d = in_uv * 2.0 - 1.0;
24 let origin = (uniforms.view_inv * vec4<f32>(0.0, 0.0, 0.0, 1.0)).xyz;
25 let temp = uniforms.proj_inv * vec4<f32>(d.x, d.y, 1.0, 1.0);
26 let direction = (uniforms.view_inv * vec4<f32>(normalize(temp.xyz), 0.0)).xyz;
28 var rq: ray_query;
29 rayQueryInitialize(&rq, acc_struct, RayDesc(0u, 0xFFu, 0.1, 200.0, origin, direction));
30 rayQueryProceed(&rq);
32 var color = vec4<f32>(0.0, 0.0, 0.0, 1.0);
33 let intersection = rayQueryGetCommittedIntersection(&rq);
34 if intersection.kind != RAY_QUERY_INTERSECTION_NONE {
35 color = vec4<f32>(intersection.barycentrics, 1.0 - intersection.barycentrics.x - intersection.barycentrics.y, 1.0);
36 }
38 textureStore(output, global_id.xy, color);
Contents