summaryrefslogtreecommitdiff
path: root/workspaces
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-21 08:42:13 +0100
committerskal <pascal.massimino@gmail.com>2026-02-21 08:42:13 +0100
commit25dc87528915fb0fd89181333324b215d77ad014 (patch)
tree5994db01a9d68a8d4166fa9ee5058c2b793b9795 /workspaces
parentfc40d39ac302fae6f5fe726c6bc077f53580c052 (diff)
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.
Diffstat (limited to 'workspaces')
-rw-r--r--workspaces/main/shaders/scene1.wgsl18
1 files changed, 6 insertions, 12 deletions
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<uniform> uniforms: UniformsSequenceParams;
@@ -136,7 +137,7 @@ fn render1(ray: Ray) -> vec3<f32> {
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<f32> {
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<f32> {
return col;
}
-fn effect(p: vec2<f32>) -> vec3<f32> {
-// 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<f32>) -> @location(0) vec4<f32> {
- 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<f32>(col, 1.0);