diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-21 09:44:17 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-21 09:50:09 +0100 |
| commit | de9bc553ed0e8bda42057ac441936c20a8185f60 (patch) | |
| tree | 1d7417510512b670bf3ce14c18020b45e5baec24 /common/shaders | |
| parent | e0f326e23f6b96f31ce9e8bbd5b5f2233e6a90ba (diff) | |
refactor(wgsl): Use vec*f alias for vector types
Replaces all instances of `vec<f32>` with the more concise `vec*f` alias (e.g., `vec3f`) across all `.wgsl` shaders. This improves readability and aligns with common graphics programming conventions.
Also adds a new coding style rule to `doc/CODING_STYLE.md` to enforce this standard going forward.
Finally, this commit fixes a build error in `test_effect_base.cc` by replacing a call to the non-existent `wgpuDeviceTick` with `wgpuDevicePoll`, which resolves the test failure.
Diffstat (limited to 'common/shaders')
| -rw-r--r-- | common/shaders/camera_common.wgsl | 24 | ||||
| -rw-r--r-- | common/shaders/combined_postprocess.wgsl | 2 | ||||
| -rw-r--r-- | common/shaders/math/common_utils.wgsl | 6 | ||||
| -rw-r--r-- | common/shaders/render/raymarching.wgsl | 10 | ||||
| -rw-r--r-- | common/shaders/render/raymarching_id.wgsl | 12 |
5 files changed, 27 insertions, 27 deletions
diff --git a/common/shaders/camera_common.wgsl b/common/shaders/camera_common.wgsl index bd29775..c7daebf 100644 --- a/common/shaders/camera_common.wgsl +++ b/common/shaders/camera_common.wgsl @@ -9,17 +9,17 @@ struct CameraParams { } struct Ray { - origin: vec3<f32>, - direction: vec3<f32>, + origin: vec3f, + direction: vec3f, } // Generate camera ray for given UV coordinates (-1 to 1) fn getCameraRay(cam: CameraParams, uv: vec2<f32>) -> Ray { - let cam_pos = vec3<f32>(cam.inv_view[3].x, cam.inv_view[3].y, cam.inv_view[3].z); + let cam_pos = vec3f(cam.inv_view[3].x, cam.inv_view[3].y, cam.inv_view[3].z); // Compute ray direction from FOV and aspect ratio let tan_fov = tan(cam.fov * 0.5); - let ndc = vec3<f32>(uv.x * cam.aspect_ratio * tan_fov, uv.y * tan_fov, -1.0); + let ndc = vec3f(uv.x * cam.aspect_ratio * tan_fov, uv.y * tan_fov, -1.0); // Transform direction by inverse view matrix (rotation only) let dir = normalize( @@ -32,21 +32,21 @@ fn getCameraRay(cam: CameraParams, uv: vec2<f32>) -> Ray { } // Extract camera position from inverse view matrix -fn getCameraPosition(cam: CameraParams) -> vec3<f32> { - return vec3<f32>(cam.inv_view[3].x, cam.inv_view[3].y, cam.inv_view[3].z); +fn getCameraPosition(cam: CameraParams) -> vec3f { + return vec3f(cam.inv_view[3].x, cam.inv_view[3].y, cam.inv_view[3].z); } // Extract camera forward vector (view direction) -fn getCameraForward(cam: CameraParams) -> vec3<f32> { - return -normalize(vec3<f32>(cam.inv_view[2].x, cam.inv_view[2].y, cam.inv_view[2].z)); +fn getCameraForward(cam: CameraParams) -> vec3f { + return -normalize(vec3f(cam.inv_view[2].x, cam.inv_view[2].y, cam.inv_view[2].z)); } // Extract camera up vector -fn getCameraUp(cam: CameraParams) -> vec3<f32> { - return normalize(vec3<f32>(cam.inv_view[1].x, cam.inv_view[1].y, cam.inv_view[1].z)); +fn getCameraUp(cam: CameraParams) -> vec3f { + return normalize(vec3f(cam.inv_view[1].x, cam.inv_view[1].y, cam.inv_view[1].z)); } // Extract camera right vector -fn getCameraRight(cam: CameraParams) -> vec3<f32> { - return normalize(vec3<f32>(cam.inv_view[0].x, cam.inv_view[0].y, cam.inv_view[0].z)); +fn getCameraRight(cam: CameraParams) -> vec3f { + return normalize(vec3f(cam.inv_view[0].x, cam.inv_view[0].y, cam.inv_view[0].z)); } diff --git a/common/shaders/combined_postprocess.wgsl b/common/shaders/combined_postprocess.wgsl index ea65761..d56386e 100644 --- a/common/shaders/combined_postprocess.wgsl +++ b/common/shaders/combined_postprocess.wgsl @@ -28,7 +28,7 @@ struct VertexOutput { // Apply effects in sequence (customize as needed) // color = apply_solarize(color, 0.4, 0.4, uniforms.time); - // color = apply_theme(color, vec3<f32>(1.0, 0.8, 0.6), 0.3); + // color = apply_theme(color, vec3f(1.0, 0.8, 0.6), 0.3); color = apply_vignette(color, in.uv, 0.6, 0.1, uniforms.audio_intensity); // color = apply_flash(color, uniforms.beat_phase * 0.2); diff --git a/common/shaders/math/common_utils.wgsl b/common/shaders/math/common_utils.wgsl index 49aaead..b8446b4 100644 --- a/common/shaders/math/common_utils.wgsl +++ b/common/shaders/math/common_utils.wgsl @@ -6,21 +6,21 @@ const PI: f32 = 3.14159265359; const TAU: f32 = 6.28318530718; // Transform normal from local to world space using inverse model matrix -fn transform_normal(inv_model: mat4x4<f32>, normal_local: vec3<f32>) -> vec3<f32> { +fn transform_normal(inv_model: mat4x4<f32>, normal_local: vec3f) -> vec3f { let normal_matrix = mat3x3<f32>(inv_model[0].xyz, inv_model[1].xyz, inv_model[2].xyz); return normalize(normal_matrix * normal_local); } // Spherical UV mapping (sphere or any radial surface) // Returns UV in [0,1] range -fn spherical_uv(p: vec3<f32>) -> vec2<f32> { +fn spherical_uv(p: vec3f) -> vec2<f32> { let u = atan2(p.x, p.z) / TAU + 0.5; let v = acos(clamp(p.y / length(p), -1.0, 1.0)) / PI; return vec2<f32>(u, v); } // Spherical UV from direction vector (for skybox, etc.) -fn spherical_uv_from_dir(dir: vec3<f32>) -> vec2<f32> { +fn spherical_uv_from_dir(dir: vec3f) -> vec2<f32> { let u = atan2(dir.z, dir.x) / TAU + 0.5; let v = asin(clamp(dir.y, -1.0, 1.0)) / PI + 0.5; return vec2<f32>(u, v); diff --git a/common/shaders/render/raymarching.wgsl b/common/shaders/render/raymarching.wgsl index fb96348..4e0327b 100644 --- a/common/shaders/render/raymarching.wgsl +++ b/common/shaders/render/raymarching.wgsl @@ -1,7 +1,7 @@ // Common functions for Signed Distance Field (SDF) raymarching. // // Required user-defined functions: -// - df(vec3<f32>) -> f32 +// - df(vec3f) -> f32 // Distance field for single-pass rendering (rayMarch, normal, shadow) // // For two-pass rendering with object IDs, see raymarching_id.wgsl @@ -15,9 +15,9 @@ const MAX_RAY_MARCHES: i32 = 80; const NORM_OFF: f32 = 0.005; // Computes the surface normal of the distance field at a point `pos`. -fn normal(pos: vec3<f32>) -> vec3<f32> { +fn normal(pos: vec3f) -> vec3f { let eps = vec2<f32>(NORM_OFF, 0.0); - var nor: vec3<f32>; + var nor: vec3f; nor.x = df(pos + eps.xyy) - df(pos - eps.xyy); nor.y = df(pos + eps.yxy) - df(pos - eps.yxy); nor.z = df(pos + eps.yyx) - df(pos - eps.yyx); @@ -26,7 +26,7 @@ fn normal(pos: vec3<f32>) -> vec3<f32> { // Performs the raymarching operation. // Returns the distance along the ray to the surface, or MAX_RAY_LENGTH if no surface is hit. -fn rayMarch(ro: vec3<f32>, rd: vec3<f32>, tmin: f32) -> f32 { +fn rayMarch(ro: vec3f, rd: vec3f, tmin: f32) -> f32 { var t = tmin; for (var i = 0; i < MAX_RAY_MARCHES; i++) { if (t > MAX_RAY_LENGTH) { @@ -43,7 +43,7 @@ fn rayMarch(ro: vec3<f32>, rd: vec3<f32>, tmin: f32) -> f32 { } // Computes a soft shadow for a given point. -fn shadow(lp: vec3<f32>, ld: vec3<f32>, mint: f32, maxt: f32) -> f32 { +fn shadow(lp: vec3f, ld: vec3f, mint: f32, maxt: f32) -> f32 { let ds = 1.0 - 0.4; var t = mint; var nd = 1e6; diff --git a/common/shaders/render/raymarching_id.wgsl b/common/shaders/render/raymarching_id.wgsl index d16445e..42be02d 100644 --- a/common/shaders/render/raymarching_id.wgsl +++ b/common/shaders/render/raymarching_id.wgsl @@ -1,7 +1,7 @@ // Common functions for Signed Distance Field (SDF) raymarching with object ID. // // Required user-defined functions: -// - dfWithID(vec3<f32>) -> RayMarchResult +// - dfWithID(vec3f) -> RayMarchResult // // Requires constants from raymarching.wgsl: // TOLERANCE, MAX_RAY_LENGTH, MAX_RAY_MARCHES, NORM_OFF @@ -21,7 +21,7 @@ struct RayMarchResult { } // Raymarch with object ID tracking. -fn rayMarchWithID(ro: vec3<f32>, rd: vec3<f32>, init: RayMarchResult) -> RayMarchResult { +fn rayMarchWithID(ro: vec3f, rd: vec3f, init: RayMarchResult) -> RayMarchResult { var t = init.distance; var result = init; @@ -45,14 +45,14 @@ fn rayMarchWithID(ro: vec3<f32>, rd: vec3<f32>, init: RayMarchResult) -> RayMarc } // Reconstruct world position from stored result. -fn reconstructPosition(ray: Ray, result: RayMarchResult) -> vec3<f32> { +fn reconstructPosition(ray: Ray, result: RayMarchResult) -> vec3f { return ray.origin + ray.direction * result.distance; } // Normal calculation using dfWithID. -fn normalWithID(pos: vec3<f32>) -> vec3<f32> { +fn normalWithID(pos: vec3f) -> vec3f { let eps = vec2<f32>(NORM_OFF, 0.0); - var nor: vec3<f32>; + var nor: vec3f; nor.x = dfWithID(pos + eps.xyy).distance - dfWithID(pos - eps.xyy).distance; nor.y = dfWithID(pos + eps.yxy).distance - dfWithID(pos - eps.yxy).distance; nor.z = dfWithID(pos + eps.yyx).distance - dfWithID(pos - eps.yyx).distance; @@ -60,7 +60,7 @@ fn normalWithID(pos: vec3<f32>) -> vec3<f32> { } // Shadow using stored intersection distance. -fn shadowWithStoredDistance(lp: vec3<f32>, ld: vec3<f32>, stored_dist: f32) -> f32 { +fn shadowWithStoredDistance(lp: vec3f, ld: vec3f, stored_dist: f32) -> f32 { let ds = 1.0 - 0.4; var t = 0.01; var nd = 1e6; |
