summaryrefslogtreecommitdiff
path: root/workspaces/main
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-21 09:33:40 +0100
committerskal <pascal.massimino@gmail.com>2026-02-21 09:33:40 +0100
commit1dad17db104f671aa0e913143a95826078892ed5 (patch)
tree6625feccf9d08cf22a438a9027a81d913bb4798a /workspaces/main
parent25dc87528915fb0fd89181333324b215d77ad014 (diff)
split raymarching.wgsl in two: with id, or without id.
Diffstat (limited to 'workspaces/main')
-rw-r--r--workspaces/main/assets.txt1
-rw-r--r--workspaces/main/shaders/scene1.wgsl32
-rw-r--r--workspaces/main/shaders/sdf_test.wgsl9
3 files changed, 10 insertions, 32 deletions
diff --git a/workspaces/main/assets.txt b/workspaces/main/assets.txt
index 8c62ea4..61d65d0 100644
--- a/workspaces/main/assets.txt
+++ b/workspaces/main/assets.txt
@@ -71,6 +71,7 @@ SHADER_RENDER_FULLSCREEN_VS, NONE, ../../common/shaders/render/fullscreen_vs.wgs
SHADER_MATH_COLOR, NONE, ../../common/shaders/math/color.wgsl, "Color Functions"
SHADER_MATH_UTILS, NONE, ../../common/shaders/math/utils.wgsl, "Math Utilities"
SHADER_RENDER_RAYMARCHING, NONE, ../../common/shaders/render/raymarching.wgsl, "Raymarching Functions"
+SHADER_RENDER_RAYMARCHING_ID, NONE, ../../common/shaders/render/raymarching_id.wgsl, "Raymarching-ID Functions"
SHADER_VIGNETTE, NONE, shaders/vignette.wgsl, "Vignette Shader"
SHADER_COMPUTE_GEN_NOISE, NONE, ../../common/shaders/compute/gen_noise.wgsl, "GPU Noise Compute Shader"
SHADER_COMPUTE_GEN_PERLIN, NONE, ../../common/shaders/compute/gen_perlin.wgsl, "GPU Perlin Noise Compute Shader"
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);