From 1dad17db104f671aa0e913143a95826078892ed5 Mon Sep 17 00:00:00 2001 From: skal Date: Sat, 21 Feb 2026 09:33:40 +0100 Subject: split raymarching.wgsl in two: with id, or without id. --- workspaces/main/shaders/scene1.wgsl | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) (limited to 'workspaces/main/shaders/scene1.wgsl') 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 uniforms: UniformsSequenceParams; @group(0) @binding(3) var camera: CameraParams; @@ -24,18 +24,18 @@ const lightPos1 = vec3(10.0, 10.0, 10.0); const lightPos2 = vec3(-10.0, 10.0, -10.0); fn rayPlane(ray: Ray, plane: vec4) -> 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 { var col = vec3(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(mix(0.0025, 0.125, tanh_approx(0.005 / sf)) / y) * skylineCol, vec3(0.0), vec3(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(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 { col += vec3(4.0) * skyCol * y * y * smoothstep(0.25, 0.0, db); col += vec3(0.8) * skyCol * exp(-0.5 * max(db, 0.0)); } - +*/ return clamp(col, vec3(0.0), vec3(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 { - // Cube - var pc = p - vec3(-1.9, 0.0, 0.0); - let dCube = sdBox(pc, vec3(1.6)); - - // Sphere - var ps = p - vec3(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) -> RayMarchResult { -- cgit v1.2.3