From a109983c194c45ad85f0e481232bc605c7cfd85b Mon Sep 17 00:00:00 2001 From: skal Date: Fri, 13 Feb 2026 08:34:24 +0100 Subject: Remediation: Implement shared common/shaders/ directory Eliminates 36 duplicate shader files across workspaces. Structure: - common/shaders/{math,render,compute}/ - Shared utilities (20 files) - workspaces/*/shaders/ - Workspace-specific only Changes: - Created common/shaders/ with math, render, compute subdirectories - Moved 20 common shaders from workspaces to common/ - Removed duplicates from test workspace - Updated assets.txt: ../../common/shaders/ references - Enhanced asset_packer.cc: filesystem path normalization for ../ resolution Implementation: Option 1 from SHADER_REUSE_INVESTIGATION.md - Single source of truth for common code - Workspace references via relative paths - Path normalization in asset packer handoff(Claude): Common shader directory implemented --- workspaces/test/shaders/math/common_utils.wgsl | 36 -------------------------- 1 file changed, 36 deletions(-) delete mode 100644 workspaces/test/shaders/math/common_utils.wgsl (limited to 'workspaces/test/shaders/math/common_utils.wgsl') diff --git a/workspaces/test/shaders/math/common_utils.wgsl b/workspaces/test/shaders/math/common_utils.wgsl deleted file mode 100644 index 7131216..0000000 --- a/workspaces/test/shaders/math/common_utils.wgsl +++ /dev/null @@ -1,36 +0,0 @@ -// Common utility functions for WGSL shaders. -// Reduces duplication across renderer_3d, mesh_render, etc. - -// Constants -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, normal_local: vec3) -> vec3 { - let normal_matrix = mat3x3(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) -> vec2 { - 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(u, v); -} - -// Spherical UV from direction vector (for skybox, etc.) -fn spherical_uv_from_dir(dir: vec3) -> vec2 { - 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(u, v); -} - -// Grid pattern for procedural texturing (checkerboard-like) -fn grid_pattern(uv: vec2) -> f32 { - let grid = 0.5 + 0.5 * sin(uv.x * PI) * sin(uv.y * PI); - return smoothstep(0.45, 0.55, grid); -} - -// NOTE: calc_sdf_normal_bumped() removed - too specialized, depends on get_dist() -// from scene_query snippets. Keep bump mapping code inline in shaders that use it. -- cgit v1.2.3