From 7d6c9bc2f10a479d9e054af56a75e535d1015b79 Mon Sep 17 00:00:00 2001 From: skal Date: Sat, 21 Feb 2026 10:24:24 +0100 Subject: docs: Update WGSL files to use shorter vector and matrix type aliases Replaced `vec2`, `vec3`, `vec4`, `mat4x4`, and `mat3x3` 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. --- workspaces/main/shaders/rotating_cube.wgsl | 78 +++++++++++++++--------------- 1 file changed, 39 insertions(+), 39 deletions(-) (limited to 'workspaces/main/shaders/rotating_cube.wgsl') diff --git a/workspaces/main/shaders/rotating_cube.wgsl b/workspaces/main/shaders/rotating_cube.wgsl index d7e4cae..0c75a13 100644 --- a/workspaces/main/shaders/rotating_cube.wgsl +++ b/workspaces/main/shaders/rotating_cube.wgsl @@ -1,65 +1,65 @@ // Rotating cube shader v2 (simplified, no masking) struct Uniforms { - view_proj: mat4x4, - inv_view_proj: mat4x4, - camera_pos_time: vec4, - params: vec4, - resolution: vec2, + view_proj: mat4x4f, + inv_view_proj: mat4x4f, + camera_pos_time: vec4f, + params: vec4f, + resolution: vec2f, aspect_ratio: f32, _pad: f32, }; struct ObjectData { - model: mat4x4, - inv_model: mat4x4, - color: vec4, - params: vec4, + model: mat4x4f, + inv_model: mat4x4f, + color: vec4f, + params: vec4f, }; @group(0) @binding(0) var uniforms: Uniforms; @group(0) @binding(1) var object: ObjectData; struct VSOut { - @builtin(position) pos: vec4, - @location(0) world_pos: vec3, - @location(1) normal: vec3, + @builtin(position) pos: vec4f, + @location(0) world_pos: vec3f, + @location(1) normal: vec3f, }; // Cube vertices (hardcoded) -fn get_cube_vertex(vid: u32) -> vec3 { - let positions = array, 36>( +fn get_cube_vertex(vid: u32) -> vec3f { + let positions = array( // Front face - vec3(-1, -1, 1), vec3( 1, -1, 1), vec3( 1, 1, 1), - vec3(-1, -1, 1), vec3( 1, 1, 1), vec3(-1, 1, 1), + vec3f(-1, -1, 1), vec3f( 1, -1, 1), vec3f( 1, 1, 1), + vec3f(-1, -1, 1), vec3f( 1, 1, 1), vec3f(-1, 1, 1), // Back face - vec3( 1, -1, -1), vec3(-1, -1, -1), vec3(-1, 1, -1), - vec3( 1, -1, -1), vec3(-1, 1, -1), vec3( 1, 1, -1), + vec3f( 1, -1, -1), vec3f(-1, -1, -1), vec3f(-1, 1, -1), + vec3f( 1, -1, -1), vec3f(-1, 1, -1), vec3f( 1, 1, -1), // Right face - vec3( 1, -1, 1), vec3( 1, -1, -1), vec3( 1, 1, -1), - vec3( 1, -1, 1), vec3( 1, 1, -1), vec3( 1, 1, 1), + vec3f( 1, -1, 1), vec3f( 1, -1, -1), vec3f( 1, 1, -1), + vec3f( 1, -1, 1), vec3f( 1, 1, -1), vec3f( 1, 1, 1), // Left face - vec3(-1, -1, -1), vec3(-1, -1, 1), vec3(-1, 1, 1), - vec3(-1, -1, -1), vec3(-1, 1, 1), vec3(-1, 1, -1), + vec3f(-1, -1, -1), vec3f(-1, -1, 1), vec3f(-1, 1, 1), + vec3f(-1, -1, -1), vec3f(-1, 1, 1), vec3f(-1, 1, -1), // Top face - vec3(-1, 1, 1), vec3( 1, 1, 1), vec3( 1, 1, -1), - vec3(-1, 1, 1), vec3( 1, 1, -1), vec3(-1, 1, -1), + vec3f(-1, 1, 1), vec3f( 1, 1, 1), vec3f( 1, 1, -1), + vec3f(-1, 1, 1), vec3f( 1, 1, -1), vec3f(-1, 1, -1), // Bottom face - vec3(-1, -1, -1), vec3( 1, -1, -1), vec3( 1, -1, 1), - vec3(-1, -1, -1), vec3( 1, -1, 1), vec3(-1, -1, 1) + vec3f(-1, -1, -1), vec3f( 1, -1, -1), vec3f( 1, -1, 1), + vec3f(-1, -1, -1), vec3f( 1, -1, 1), vec3f(-1, -1, 1) ); return positions[vid]; } -fn get_cube_normal(vid: u32) -> vec3 { +fn get_cube_normal(vid: u32) -> vec3f { let face_id = vid / 6u; - let normals = array, 6>( - vec3( 0, 0, 1), // Front - vec3( 0, 0, -1), // Back - vec3( 1, 0, 0), // Right - vec3(-1, 0, 0), // Left - vec3( 0, 1, 0), // Top - vec3( 0, -1, 0) // Bottom + let normals = array( + vec3f( 0, 0, 1), // Front + vec3f( 0, 0, -1), // Back + vec3f( 1, 0, 0), // Right + vec3f(-1, 0, 0), // Left + vec3f( 0, 1, 0), // Top + vec3f( 0, -1, 0) // Bottom ); return normals[face_id]; } @@ -68,22 +68,22 @@ fn get_cube_normal(vid: u32) -> vec3 { let local_pos = get_cube_vertex(vid); let local_normal = get_cube_normal(vid); - let world_pos = object.model * vec4(local_pos, 1.0); - let world_normal = normalize((object.model * vec4(local_normal, 0.0)).xyz); + let world_pos = object.model * vec4f(local_pos, 1.0); + let world_normal = normalize((object.model * vec4f(local_normal, 0.0)).xyz); let clip_pos = uniforms.view_proj * world_pos; return VSOut(clip_pos, world_pos.xyz, world_normal); } -@fragment fn fs_main(@location(0) world_pos: vec3, @location(1) normal: vec3) -> @location(0) vec4 { +@fragment fn fs_main(@location(0) world_pos: vec3f, @location(1) normal: vec3f) -> @location(0) vec4f { let N = normalize(normal); - let light_dir = normalize(vec3(1.0, 1.0, 1.0)); + let light_dir = normalize(vec3f(1.0, 1.0, 1.0)); let diffuse = max(dot(N, light_dir), 0.0); let ambient = 0.3; let lighting = ambient + diffuse * 0.7; let color = object.color.rgb * lighting; - return vec4(color, 1.0); + return vec4f(color, 1.0); } -- cgit v1.2.3