From de9bc553ed0e8bda42057ac441936c20a8185f60 Mon Sep 17 00:00:00 2001 From: skal Date: Sat, 21 Feb 2026 09:44:17 +0100 Subject: refactor(wgsl): Use vec*f alias for vector types Replaces all instances of `vec` 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. --- common/shaders/render/raymarching.wgsl | 10 +++++----- common/shaders/render/raymarching_id.wgsl | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'common/shaders/render') 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 +// - 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) -> vec3 { +fn normal(pos: vec3f) -> vec3f { let eps = vec2(NORM_OFF, 0.0); - var nor: vec3; + 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) -> vec3 { // 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, rd: vec3, 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, rd: vec3, tmin: f32) -> f32 { } // Computes a soft shadow for a given point. -fn shadow(lp: vec3, ld: vec3, 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) -> 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, rd: vec3, 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, rd: vec3, init: RayMarchResult) -> RayMarc } // Reconstruct world position from stored result. -fn reconstructPosition(ray: Ray, result: RayMarchResult) -> vec3 { +fn reconstructPosition(ray: Ray, result: RayMarchResult) -> vec3f { return ray.origin + ray.direction * result.distance; } // Normal calculation using dfWithID. -fn normalWithID(pos: vec3) -> vec3 { +fn normalWithID(pos: vec3f) -> vec3f { let eps = vec2(NORM_OFF, 0.0); - var nor: vec3; + 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) -> vec3 { } // Shadow using stored intersection distance. -fn shadowWithStoredDistance(lp: vec3, ld: vec3, 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; -- cgit v1.2.3