summaryrefslogtreecommitdiff
path: root/common/shaders/render/raymarching_id.wgsl
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-28 09:08:57 +0100
committerskal <pascal.massimino@gmail.com>2026-02-28 09:08:57 +0100
commit9ee410594a52cbc699b13de2bde4860d70c959a3 (patch)
treed56adf5931d488abcf3ac8e24a828d2d5b02e8cc /common/shaders/render/raymarching_id.wgsl
parent6599a428cd69be6c66c5179e1f0fce42f561f935 (diff)
refactor: move common/shaders/ to src/shaders/
Relocates shared WGSL shaders under src/ where all source code lives, eliminating the top-level common/ directory. - Update asset references in workspaces/main/assets.txt and workspaces/test/assets.txt - Update docs: PROJECT_CONTEXT.md, ARCHITECTURE.md, WORKSPACE_SYSTEM.md, SHADER_REUSE_INVESTIGATION.md Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'common/shaders/render/raymarching_id.wgsl')
-rw-r--r--common/shaders/render/raymarching_id.wgsl83
1 files changed, 0 insertions, 83 deletions
diff --git a/common/shaders/render/raymarching_id.wgsl b/common/shaders/render/raymarching_id.wgsl
deleted file mode 100644
index d9f32b2..0000000
--- a/common/shaders/render/raymarching_id.wgsl
+++ /dev/null
@@ -1,83 +0,0 @@
-// Common functions for Signed Distance Field (SDF) raymarching with object ID.
-//
-// Required user-defined functions:
-// - dfWithID(vec3f) -> RayMarchResult
-//
-// Requires constants from raymarching.wgsl:
-// TOLERANCE, MAX_RAY_LENGTH, MAX_RAY_MARCHES, NORM_OFF
-#include "render/raymarching"
-
-// ============================================================================
-// Two-Pass Raymarching Support
-// ============================================================================
-// Design note: RayMarchResult is passed/returned by value (not pointer).
-// At 12 bytes (3×f32), return value optimization makes this efficient.
-// See doc/CODING_STYLE.md for rationale.
-
-struct RayMarchResult {
- distance: f32, // Distance to surface (MAX_RAY_LENGTH if miss)
- distance_max: f32, // Total distance marched (for fog/AO)
- object_id: f32, // Object identifier (0.0 = background)
-}
-
-// Raymarch with object ID tracking.
-fn rayMarchWithID(ro: vec3f, rd: vec3f, init: RayMarchResult) -> RayMarchResult {
- var t = init.distance;
- var result = init;
-
- for (var i = 0; i < MAX_RAY_MARCHES; i++) {
- if (t > MAX_RAY_LENGTH) {
- result.distance = MAX_RAY_LENGTH;
- result.distance_max = MAX_RAY_LENGTH;
- break;
- }
- let sample = dfWithID(ro + rd * t);
- if (sample.distance < TOLERANCE) {
- result.distance = t;
- result.distance_max = t;
- result.object_id = sample.object_id;
- break;
- }
- t += sample.distance;
- }
-
- return result;
-}
-
-// Reconstruct world position from stored result.
-fn reconstructPosition(ray: Ray, result: RayMarchResult) -> vec3f {
- return ray.origin + ray.direction * result.distance;
-}
-
-// Normal calculation using dfWithID.
-fn normalWithID(pos: vec3f) -> vec3f {
- let eps = vec2f(NORM_OFF, 0.0);
- 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;
- return normalize(nor);
-}
-
-// Shadow using stored intersection distance.
-fn shadowWithStoredDistance(lp: vec3f, ld: vec3f, stored_dist: f32) -> f32 {
- let ds = 1.0 - 0.4;
- var t = 0.01;
- var nd = 1e6;
- let soff = 0.05;
- let smul = 1.5;
- let MAX_SHD_MARCHES = 20;
-
- for (var i = 0; i < MAX_SHD_MARCHES; i++) {
- let p = lp + ld * t;
- let d = dfWithID(p).distance;
- if (d < TOLERANCE || t >= stored_dist) {
- let sd = 1.0 - exp(-smul * max(t / stored_dist - soff, 0.0));
- return select(mix(sd, 1.0, smoothstep(0.0, 0.025, nd)), sd, t >= stored_dist);
- }
- nd = min(nd, d);
- t += ds * d;
- }
- let sd = 1.0 - exp(-smul * max(t / stored_dist - soff, 0.0));
- return sd;
-}