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.
1// module `package::gfx`: declares the pipeline-relevant items (entry points,
2// resource variable, overrides) that the root module re-exports with
3// `public import`.
5// module import: `util` is used both as a module (`util::dot2`, the file
6// util.wesl) and as a declaration (`util()`, the function declared in the
7// root module package.wesl). See Imports.md "Import bindings".
8import package::util;
10// super import from a top-level module: `super` = `package` (the root module
11// is `package.wesl`, so this is also a circular import: root imports gfx too).
12import super::util::{cross2, EPSILON};
14import constants::PI;
16// a resource variable must be `public` to be re-exportable; the
17// @group/@binding annotations carry through the re-export unchanged.
18@group(0) @binding(0) public var<storage, read_write> scene_data: array<vec4f>;
20// host-settable pipeline-overridable constant (re-exported by the root).
21public override exposure: f32 = 1.0;
23// a private override is not host-settable but may derive from another override.
24private override gain: f32 = exposure * 2.0;
26public fn tonemap(c: vec2f) -> f32 {
27 return cross2(c, vec2f(EPSILON)) * gain;
30// entry points must be `public` so the root module can re-export them.
31@vertex
32public fn vert_main(@builtin(vertex_index) vi: u32) -> @builtin(position) vec4f {
33 // `util` used as a declaration: `fn util` from the root module.
34 return vec4f(f32(vi) * util(), 0.0, 0.0, 1.0);
37@fragment
38public fn frag_main(@builtin(position) pos: vec4f) -> @location(0) vec4f {
39 // conditional discard statement.
40 @if(feat1)
41 discard;
42 // `util` used as a module: reaches into util.wesl.
43 let m = util::dot2(pos.xy, pos.xy);
44 return vec4f(m * PI + tonemap(pos.xy));
Contents