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 --- common/shaders/lighting.wgsl | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 common/shaders/lighting.wgsl (limited to 'common/shaders/lighting.wgsl') diff --git a/common/shaders/lighting.wgsl b/common/shaders/lighting.wgsl new file mode 100644 index 0000000..ac2142b --- /dev/null +++ b/common/shaders/lighting.wgsl @@ -0,0 +1,24 @@ +fn get_normal_basic(p: vec3, obj_params: vec4) -> vec3 { + let obj_type = obj_params.x; + if (obj_type == 1.0) { return normalize(p); } + let e = vec2(0.001, 0.0); + return normalize(vec3( + get_dist(p + e.xyy, obj_params) - get_dist(p - e.xyy, obj_params), + get_dist(p + e.yxy, obj_params) - get_dist(p - e.yxy, obj_params), + get_dist(p + e.yyx, obj_params) - get_dist(p - e.yyx, obj_params) + )); +} + +fn calc_shadow(ro: vec3, rd: vec3, tmin: f32, tmax: f32, skip_idx: u32) -> f32 { + var res = 1.0; + var t = tmin; + if (t < 0.05) { t = 0.05; } + for (var i = 0; i < 32; i = i + 1) { + let h = map_scene(ro + rd * t, skip_idx); + if (h < 0.001) { return 0.0; } + res = min(res, 16.0 * h / t); + t = t + clamp(h, 0.02, 0.4); + if (t > tmax) { break; } + } + return clamp(res, 0.0, 1.0); +} -- cgit v1.2.3