diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-21 09:33:40 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-21 09:33:40 +0100 |
| commit | 1dad17db104f671aa0e913143a95826078892ed5 (patch) | |
| tree | 6625feccf9d08cf22a438a9027a81d913bb4798a /workspaces/main/shaders | |
| parent | 25dc87528915fb0fd89181333324b215d77ad014 (diff) | |
split raymarching.wgsl in two: with id, or without id.
Diffstat (limited to 'workspaces/main/shaders')
| -rw-r--r-- | workspaces/main/shaders/scene1.wgsl | 32 | ||||
| -rw-r--r-- | workspaces/main/shaders/sdf_test.wgsl | 9 |
2 files changed, 9 insertions, 32 deletions
diff --git a/workspaces/main/shaders/scene1.wgsl b/workspaces/main/shaders/scene1.wgsl index f6a6c38..87949fa 100644 --- a/workspaces/main/shaders/scene1.wgsl +++ b/workspaces/main/shaders/scene1.wgsl @@ -7,7 +7,7 @@ #include "math/utils" #include "math/sdf_shapes" #include "math/common_utils" -#include "render/raymarching" +#include "render/raymarching_id" @group(0) @binding(2) var<uniform> uniforms: UniformsSequenceParams; @group(0) @binding(3) var<uniform> camera: CameraParams; @@ -24,18 +24,18 @@ const lightPos1 = vec3<f32>(10.0, 10.0, 10.0); const lightPos2 = vec3<f32>(-10.0, 10.0, -10.0); fn rayPlane(ray: Ray, plane: vec4<f32>) -> f32 { - return -(dot(ray.origin, plane.xyz) + plane.w) / dot(ray.direction, plane.xyz); + return (dot(ray.origin, plane.xyz) - plane.w) / dot(ray.direction, plane.xyz); } fn render0(ray: Ray) -> vec3<f32> { var col = vec3<f32>(0.0); let y = abs(ray.direction.y); - var sf = 1.0001 - max(dot(sunDir1, ray.direction), 0.0); + let sf = 1.0001 - max(dot(sunDir1, ray.direction), 0.0); col += skyCol * pow(y, 8.0); - col += clamp(vec3<f32>(mix(0.0025, 0.125, tanh_approx(0.005 / sf)) / y) * skylineCol, vec3<f32>(0.0), vec3<f32>(10.0)); - sf *= sf; - col += sunCol * 0.00005 / sf; + col += skylineCol * (mix(0.0025, 0.125, tanh_approx(0.005 / sf)) / y); + col += sunCol * 0.00005 / (sf * sf); +/* let tp1 = rayPlane(ray, vec4<f32>(0.0, -1.0, 0.0, 6.0)); if (tp1 > 0.0) { let pos = ray.origin + tp1 * ray.direction; @@ -44,7 +44,7 @@ fn render0(ray: Ray) -> vec3<f32> { col += vec3<f32>(4.0) * skyCol * y * y * smoothstep(0.25, 0.0, db); col += vec3<f32>(0.8) * skyCol * exp(-0.5 * max(db, 0.0)); } - +*/ return clamp(col, vec3<f32>(0.0), vec3<f32>(10.0)); } @@ -53,23 +53,9 @@ const OBJ_CUBE: f32 = 1.0; const OBJ_SPHERE: f32 = 2.0; const OBJ_PLANE: f32 = 3.0; +// TODO: remove! (issue with #include macros) fn df(p: vec3<f32>) -> f32 { - // Cube - var pc = p - vec3<f32>(-1.9, 0.0, 0.0); - let dCube = sdBox(pc, vec3<f32>(1.6)); - - // Sphere - var ps = p - vec3<f32>(1.3, 0.0, 0.0); - let dSphere = sdSphere(ps, 1.2); - - // Ground plane - let dPlane = p.y + 1.0; - - // Union - var d = min(dCube, dSphere); - d = min(d, dPlane); - - return d; + return 0.; } fn dfWithID(p: vec3<f32>) -> RayMarchResult { diff --git a/workspaces/main/shaders/sdf_test.wgsl b/workspaces/main/shaders/sdf_test.wgsl index 71310f2..3c97613 100644 --- a/workspaces/main/shaders/sdf_test.wgsl +++ b/workspaces/main/shaders/sdf_test.wgsl @@ -22,15 +22,6 @@ fn df(p: vec3<f32>) -> f32 { return min(d_sphere, d_box); } -// Two-pass distance function (required by raymarching.wgsl) -fn dfWithID(p: vec3<f32>) -> RayMarchResult { - var result: RayMarchResult; - result.distance = df(p); - result.distance_max = result.distance; - result.object_id = 0.0; - return result; -} - // Simple lighting fn shade(pos: vec3<f32>, rd: vec3<f32>) -> vec3<f32> { let n = normal(pos); |
