diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-21 10:24:24 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-21 10:24:24 +0100 |
| commit | 7d6c9bc2f10a479d9e054af56a75e535d1015b79 (patch) | |
| tree | a364cc4d16052162c48e15e9e05e491e9ba1e758 /workspaces/main/shaders/masked_cube.wgsl | |
| parent | 53187e2d930cf982a0bc7f99262586c6a8a0640a (diff) | |
docs: Update WGSL files to use shorter vector and matrix type aliases
Replaced `vec2<f32>`, `vec3<f32>`, `vec4<f32>`, `mat4x4<f32>`, and `mat3x3<f32>` with their shorter aliases `vec2f`, `vec3f`, `vec4f`, `mat4x4f`, and `mat3x3f` across all WGSL shader files in `workspaces/main/shaders/`. This improves readability and aligns with modern WGSL conventions.
Diffstat (limited to 'workspaces/main/shaders/masked_cube.wgsl')
| -rw-r--r-- | workspaces/main/shaders/masked_cube.wgsl | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/workspaces/main/shaders/masked_cube.wgsl b/workspaces/main/shaders/masked_cube.wgsl index 5e673a3..8e3fa26 100644 --- a/workspaces/main/shaders/masked_cube.wgsl +++ b/workspaces/main/shaders/masked_cube.wgsl @@ -12,35 +12,35 @@ @group(1) @binding(1) var mask_sampler: sampler; struct VertexOutput { - @builtin(position) position: vec4<f32>, - @location(0) local_pos: vec3<f32>, - @location(1) color: vec4<f32>, + @builtin(position) position: vec4f, + @location(0) local_pos: vec3f, + @location(1) color: vec4f, @location(2) @interpolate(flat) instance_index: u32, - @location(3) world_pos: vec3<f32>, - @location(4) transformed_normal: vec3<f32>, + @location(3) world_pos: vec3f, + @location(4) transformed_normal: vec3f, }; @vertex fn vs_main(@builtin(vertex_index) vertex_index: u32, @builtin(instance_index) instance_index: u32) -> VertexOutput { - var pos = array<vec3<f32>, 36>( - vec3(-1.0, -1.0, 1.0), vec3( 1.0, -1.0, 1.0), vec3( 1.0, 1.0, 1.0), - vec3(-1.0, -1.0, 1.0), vec3( 1.0, 1.0, 1.0), vec3(-1.0, 1.0, 1.0), - vec3(-1.0, -1.0, -1.0), vec3(-1.0, 1.0, -1.0), vec3( 1.0, 1.0, -1.0), - vec3(-1.0, -1.0, -1.0), vec3( 1.0, 1.0, -1.0), vec3( 1.0, -1.0, -1.0), - vec3(-1.0, 1.0, -1.0), vec3(-1.0, 1.0, 1.0), vec3( 1.0, 1.0, 1.0), - vec3(-1.0, 1.0, -1.0), vec3( 1.0, 1.0, 1.0), vec3( 1.0, 1.0, -1.0), - vec3(-1.0, -1.0, -1.0), vec3( 1.0, -1.0, -1.0), vec3( 1.0, -1.0, 1.0), - vec3(-1.0, -1.0, -1.0), vec3( 1.0, -1.0, 1.0), vec3(-1.0, -1.0, 1.0), - vec3( 1.0, -1.0, -1.0), vec3( 1.0, 1.0, -1.0), vec3( 1.0, 1.0, 1.0), - vec3( 1.0, -1.0, -1.0), vec3( 1.0, 1.0, 1.0), vec3( 1.0, -1.0, 1.0), - vec3(-1.0, -1.0, -1.0), vec3(-1.0, -1.0, 1.0), vec3(-1.0, 1.0, 1.0), - vec3(-1.0, -1.0, -1.0), vec3(-1.0, 1.0, 1.0), vec3(-1.0, 1.0, -1.0) + var pos = array<vec3f, 36>( + vec3f(-1.0, -1.0, 1.0), vec3f( 1.0, -1.0, 1.0), vec3f( 1.0, 1.0, 1.0), + vec3f(-1.0, -1.0, 1.0), vec3f( 1.0, 1.0, 1.0), vec3f(-1.0, 1.0, 1.0), + vec3f(-1.0, -1.0, -1.0), vec3f(-1.0, 1.0, -1.0), vec3f( 1.0, 1.0, -1.0), + vec3f(-1.0, -1.0, -1.0), vec3f( 1.0, 1.0, -1.0), vec3f( 1.0, -1.0, -1.0), + vec3f(-1.0, 1.0, -1.0), vec3f(-1.0, 1.0, 1.0), vec3f( 1.0, 1.0, 1.0), + vec3f(-1.0, 1.0, -1.0), vec3f( 1.0, 1.0, 1.0), vec3f( 1.0, 1.0, -1.0), + vec3f(-1.0, -1.0, -1.0), vec3f( 1.0, -1.0, -1.0), vec3f( 1.0, -1.0, 1.0), + vec3f(-1.0, -1.0, -1.0), vec3f( 1.0, -1.0, 1.0), vec3f(-1.0, -1.0, 1.0), + vec3f( 1.0, -1.0, -1.0), vec3f( 1.0, 1.0, -1.0), vec3f( 1.0, 1.0, 1.0), + vec3f( 1.0, -1.0, -1.0), vec3f( 1.0, 1.0, 1.0), vec3f( 1.0, -1.0, 1.0), + vec3f(-1.0, -1.0, -1.0), vec3f(-1.0, -1.0, 1.0), vec3f(-1.0, 1.0, 1.0), + vec3f(-1.0, -1.0, -1.0), vec3f(-1.0, 1.0, 1.0), vec3f(-1.0, 1.0, -1.0) ); var p = pos[vertex_index]; let obj = object_data.objects[instance_index]; - let world_pos = obj.model * vec4<f32>(p, 1.0); + let world_pos = obj.model * vec4f(p, 1.0); let clip_pos = globals.view_proj * world_pos; var out: VertexOutput; @@ -49,7 +49,7 @@ fn vs_main(@builtin(vertex_index) vertex_index: u32, out.color = obj.color; out.instance_index = instance_index; out.world_pos = world_pos.xyz; - out.transformed_normal = normalize(vec3<f32>(0.0, 1.0, 0.0)); + out.transformed_normal = normalize(vec3f(0.0, 1.0, 0.0)); return out; } @@ -60,7 +60,7 @@ fn vs_main(@builtin(vertex_index) vertex_index: u32, #include "ray_box" struct FragmentOutput { - @location(0) color: vec4<f32>, + @location(0) color: vec4f, @builtin(frag_depth) depth: f32, }; @@ -76,19 +76,19 @@ fn fs_main(in: VertexOutput) -> FragmentOutput { let obj = object_data.objects[in.instance_index]; let obj_type = obj.params.x; - var p: vec3<f32>; - var normal: vec3<f32>; + var p: vec3f; + var normal: vec3f; var base_color = in.color.rgb; - let light_dir = normalize(vec3<f32>(1.0, 1.0, 1.0)); + let light_dir = normalize(vec3f(1.0, 1.0, 1.0)); let ray_origin = globals.camera_pos_time.xyz; let ray_dir = normalize(in.world_pos - ray_origin); let inv_model = obj.inv_model; - let local_origin = (inv_model * vec4<f32>(ray_origin, 1.0)).xyz; - let local_dir = normalize((inv_model * vec4<f32>(ray_dir, 0.0)).xyz); + let local_origin = (inv_model * vec4f(ray_origin, 1.0)).xyz; + let local_dir = normalize((inv_model * vec4f(ray_dir, 0.0)).xyz); - let bounds = ray_box_intersection(local_origin, local_dir, vec3<f32>(1.0)); + let bounds = ray_box_intersection(local_origin, local_dir, vec3f(1.0)); if (!bounds.hit) { discard; } @@ -99,11 +99,11 @@ fn fs_main(in: VertexOutput) -> FragmentOutput { var t_march = t_start; let max_steps = 128; var hit = false; - var local_p = vec3<f32>(0.0); + var local_p = vec3f(0.0); for (var step = 0; step < max_steps; step++) { local_p = local_origin + t_march * local_dir; - let d = sdBox(local_p, vec3<f32>(1.0)); + let d = sdBox(local_p, vec3f(1.0)); if (d < 0.001) { hit = true; @@ -122,17 +122,17 @@ fn fs_main(in: VertexOutput) -> FragmentOutput { p = local_p; let eps = 0.001; - normal = normalize(vec3<f32>( - sdBox(p + vec3<f32>(eps, 0.0, 0.0), vec3<f32>(1.0)) - - sdBox(p - vec3<f32>(eps, 0.0, 0.0), vec3<f32>(1.0)), - sdBox(p + vec3<f32>(0.0, eps, 0.0), vec3<f32>(1.0)) - - sdBox(p - vec3<f32>(0.0, eps, 0.0), vec3<f32>(1.0)), - sdBox(p + vec3<f32>(0.0, 0.0, eps), vec3<f32>(1.0)) - - sdBox(p - vec3<f32>(0.0, 0.0, eps), vec3<f32>(1.0)) + normal = normalize(vec3f( + sdBox(p + vec3f(eps, 0.0, 0.0), vec3f(1.0)) - + sdBox(p - vec3f(eps, 0.0, 0.0), vec3f(1.0)), + sdBox(p + vec3f(0.0, eps, 0.0), vec3f(1.0)) - + sdBox(p - vec3f(0.0, eps, 0.0), vec3f(1.0)), + sdBox(p + vec3f(0.0, 0.0, eps), vec3f(1.0)) - + sdBox(p - vec3f(0.0, 0.0, eps), vec3f(1.0)) )); - let world_p = (obj.model * vec4<f32>(p, 1.0)).xyz; - let world_normal = normalize((obj.model * vec4<f32>(normal, 0.0)).xyz); + let world_p = (obj.model * vec4f(p, 1.0)).xyz; + let world_normal = normalize((obj.model * vec4f(normal, 0.0)).xyz); let bump_strength = 0.3; let bump_scale = 4.0; @@ -140,7 +140,7 @@ fn fs_main(in: VertexOutput) -> FragmentOutput { let noise_val = textureSample(noise_tex, noise_sampler, noise_uv).r; let bump_offset = (noise_val - 0.5) * bump_strength; - let bumped_normal = normalize(world_normal + vec3<f32>(bump_offset)); + let bumped_normal = normalize(world_normal + vec3f(bump_offset)); let diffuse = max(dot(bumped_normal, light_dir), 0.0); let ambient = 0.3; @@ -148,11 +148,11 @@ fn fs_main(in: VertexOutput) -> FragmentOutput { let final_color = base_color * lighting; - let clip_p = globals.view_proj * vec4<f32>(world_p, 1.0); + let clip_p = globals.view_proj * vec4f(world_p, 1.0); let depth = clip_p.z / clip_p.w; var out: FragmentOutput; - out.color = vec4<f32>(final_color, 1.0); + out.color = vec4f(final_color, 1.0); out.depth = depth; return out; |
