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.
2struct Gradient {
3 sky: vec4<f32>,
4 horizon: vec4<f32>,
5 ground: vec4<f32>,
6}
8fn render_gradient(r: vec3<f32>, g: Gradient) -> vec3<f32> {
9 let r_norm = normalize(r);
10 let y = r_norm.y;
12 let p_sky = max(y, 0f);
13 let p_horizon = 1f-abs(y);
14 let p_ground = max(-y, 0f);
16 let color = (g.sky * p_sky) + (g.horizon * p_horizon) + (g.ground * p_ground);
18 return color.xyz;
21@group(0) @binding(0)
22var<uniform> gradient: Gradient;
24@group(1) @binding(0)
25var image: texture_storage_2d_array<rgba16float, write>;
27@compute @workgroup_size(8, 8, 1)
28fn main(@builtin(global_invocation_id) invocation_id: vec3<u32>, @builtin(num_workgroups) num_workgroups: vec3<u32>) {
29 let size = textureDimensions(image).x;
30 let scale = f32(size)/2f;
32 let dir = vec2<f32>((f32(invocation_id.x)/scale) - 1f, (f32(invocation_id.y)/scale) - 1f);
34 var ray: vec3<f32>;
36 switch invocation_id.z {
37 case 0u {
38 ray = vec3<f32>(1f, -dir.y, -dir.x); // +X
39 }
40 case 1u {
41 ray = vec3<f32>(-1f, -dir.y, dir.x);// -X
42 }
43 case 2u {
44 ray = vec3<f32>(dir.x, 1f, dir.y); // +Y
45 }
46 case 3u {
47 ray = vec3<f32>(dir.x, -1f, -dir.y);// -Y
48 }
49 case 4u {
50 ray = vec3<f32>(dir.x, -dir.y, 1f); // +Z
51 }
52 default: {
53 ray = vec3<f32>(-dir.x, -dir.y, -1f);// -Z
54 }
55 }
57 let render = render_gradient(
58 ray,
59 gradient
60 );
62 textureStore(
63 image,
64 vec2<i32>(invocation_id.xy),
65 i32(invocation_id.z),
66 vec4<f32>(render, 1.0)
67 );
Contents