From 25dc87528915fb0fd89181333324b215d77ad014 Mon Sep 17 00:00:00 2001 From: skal Date: Sat, 21 Feb 2026 08:42:13 +0100 Subject: refactor(wgsl): Factorize getScreenCoord helper Factorizes the screen coordinate calculation from scene1.wgsl into a reusable getScreenCoord function in common/shaders/math/common_utils.wgsl. This improves code reuse and simplifies fragment shaders. --- workspaces/main/shaders/scene1.wgsl | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'workspaces/main') diff --git a/workspaces/main/shaders/scene1.wgsl b/workspaces/main/shaders/scene1.wgsl index a47413b..f6a6c38 100644 --- a/workspaces/main/shaders/scene1.wgsl +++ b/workspaces/main/shaders/scene1.wgsl @@ -6,6 +6,7 @@ #include "math/color" #include "math/utils" #include "math/sdf_shapes" +#include "math/common_utils" #include "render/raymarching" @group(0) @binding(2) var uniforms: UniformsSequenceParams; @@ -136,7 +137,7 @@ fn render1(ray: Ray) -> vec3 { let result = rayMarchWithID(ray.origin, ray.direction, init); if (result.distance < MAX_RAY_LENGTH) { - let nsp = reconstructPosition(ray.origin, ray.direction, result); + let nsp = reconstructPosition(ray, result); let nnor = normalWithID(nsp); let nref = reflect(ray.direction, nnor); @@ -149,7 +150,7 @@ fn render1(ray: Ray) -> vec3 { var nrcol = render0(rRay); if (nrt_result.distance < MAX_RAY_LENGTH) { - let nrsp = reconstructPosition(nsp, nref, nrt_result); + let nrsp = reconstructPosition(Ray(nsp, nref), nrt_result); let nrnor = normalWithID(nrsp); let nrref = reflect(nref, nrnor); nrcol = boxCol(nrcol, nrsp, nref, nrnor, render0(Ray(nrsp, nrref)), 1.0, 1.0); @@ -166,19 +167,12 @@ fn render1(ray: Ray) -> vec3 { return col; } -fn effect(p: vec2) -> vec3 { -// g_rot0 = rot(-0.2 * uniforms.time); - let ray = getCameraRay(camera, p); - return render1(ray); -} - #include "render/fullscreen_vs" @fragment fn fs_main(@builtin(position) p: vec4) -> @location(0) vec4 { - let q = p.xy / uniforms.resolution; - var coord = -1.0 + 2.0 * q; - coord.x *= uniforms.resolution.x / uniforms.resolution.y; - var col = effect(coord); + let coord = getScreenCoord(p, uniforms.resolution); + let ray = getCameraRay(camera, coord); + var col = render1(ray); col = aces_approx(col); col = sRGB(col); return vec4(col, 1.0); -- cgit v1.2.3