summaryrefslogtreecommitdiff
path: root/workspaces/main
diff options
context:
space:
mode:
Diffstat (limited to 'workspaces/main')
-rw-r--r--workspaces/main/shaders/scene1.wgsl52
1 files changed, 25 insertions, 27 deletions
diff --git a/workspaces/main/shaders/scene1.wgsl b/workspaces/main/shaders/scene1.wgsl
index ff21318..e98fae6 100644
--- a/workspaces/main/shaders/scene1.wgsl
+++ b/workspaces/main/shaders/scene1.wgsl
@@ -11,41 +11,38 @@
@group(0) @binding(2) var<uniform> uniforms: UniformsSequenceParams;
@group(0) @binding(3) var<uniform> camera: CameraParams;
-const PI: f32 = 3.141592654;
-const TAU: f32 = 6.283185307;
-
-// Colors (precomputed HSV conversions)
-const skyCol = vec3<f32>(0.176, 0.235, 0.25); // HSV(0.57, 0.90, 0.25)
-const skylineCol = vec3<f32>(0.5, 0.125, 0.025); // HSV(0.02, 0.95, 0.5)
-const sunCol = vec3<f32>(0.5, 0.163, 0.025); // HSV(0.07, 0.95, 0.5)
-const diffCol1 = vec3<f32>(0.4, 1.0, 1.0); // HSV(0.60, 0.90, 1.0)
-const diffCol2 = vec3<f32>(0.325, 1.0, 0.975); // HSV(0.55, 0.90, 1.0)
+const skyCol = vec3<f32>(0.176, 0.235, 0.25);
+const skylineCol = vec3<f32>(0.5, 0.125, 0.025);
+const sunCol = vec3<f32>(0.5, 0.163, 0.025);
+const diffCol1 = vec3<f32>(0.4, 1.0, 1.0);
+const diffCol2 = vec3<f32>(0.325, 1.0, 0.975);
// Lighting (normalized manually)
const sunDir1 = vec3<f32>(0.0, 0.04997, -0.99875); // normalize(0, 0.05, -1)
const lightPos1 = vec3<f32>(10.0, 10.0, 10.0);
const lightPos2 = vec3<f32>(-10.0, 10.0, -10.0);
-fn rayPlane(ro: vec3<f32>, rd: vec3<f32>, plane: vec4<f32>) -> f32 {
- return -(dot(ro, plane.xyz) + plane.w) / dot(rd, plane.xyz);
+fn rayPlane(ray: Ray, plane: vec4<f32>) -> f32 {
+ return -(dot(ray.origin, plane.xyz) + plane.w) / dot(ray.direction, plane.xyz);
}
var<private> g_rot0: mat2x2<f32>;
-fn render0(ro: vec3<f32>, rd: vec3<f32>) -> vec3<f32> {
+fn render0(ray: Ray) -> vec3<f32> {
var col = vec3<f32>(0.0);
- var sf = 1.0001 - max(dot(sunDir1, rd), 0.0);
- col += skyCol * pow((1.0 - abs(rd.y)), 8.0);
- col += clamp(vec3<f32>(mix(0.0025, 0.125, tanh_approx(0.005 / sf)) / abs(rd.y)) * skylineCol, vec3<f32>(0.0), vec3<f32>(10.0));
+ let y = abs(ray.direction.y);
+ var 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;
- let tp1 = rayPlane(ro, rd, vec4<f32>(0.0, -1.0, 0.0, 6.0));
+ let tp1 = rayPlane(ray, vec4<f32>(0.0, -1.0, 0.0, 6.0));
if (tp1 > 0.0) {
- let pos = ro + tp1 * rd;
+ let pos = ray.origin + tp1 * ray.direction;
let pp = pos.xz;
let db = sdBox2D(pp, vec2<f32>(5.0, 9.0)) - 3.0;
- col += vec3<f32>(4.0) * skyCol * rd.y * rd.y * smoothstep(0.25, 0.0, db);
+ 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));
}
@@ -138,8 +135,8 @@ fn boxCol(col: vec3<f32>, nsp: vec3<f32>, rd: vec3<f32>, nnor: vec3<f32>, nrcol:
return mix(col, scol, rf * smoothstep(90.0, 20.0, dot(nsp, nsp)));
}
-fn render1(ro: vec3<f32>, rd: vec3<f32>) -> vec3<f32> {
- let skyCol_local = render0(ro, rd);
+fn render1(ray: Ray) -> vec3<f32> {
+ let skyCol_local = render0(ray);
var col = skyCol_local;
var init: RayMarchResult;
@@ -147,24 +144,25 @@ fn render1(ro: vec3<f32>, rd: vec3<f32>) -> vec3<f32> {
init.distance_max = 0.0;
init.object_id = OBJ_BACKGROUND;
- let result = rayMarchWithID(ro, rd, init);
+ let result = rayMarchWithID(ray.origin, ray.direction, init);
if (result.distance < MAX_RAY_LENGTH) {
- let nsp = reconstructPosition(ro, rd, result);
+ let nsp = reconstructPosition(ray.origin, ray.direction, result);
let nnor = normalWithID(nsp);
- let nref = reflect(rd, nnor);
+ let nref = reflect(ray.direction, nnor);
var refl_init: RayMarchResult;
refl_init.distance = 0.2;
refl_init.distance_max = 0.2;
refl_init.object_id = OBJ_BACKGROUND;
let nrt_result = rayMarchWithID(nsp, nref, refl_init);
- var nrcol = render0(nsp, nref);
+ let rRay = Ray(nsp, nref);
+ var nrcol = render0(rRay);
if (nrt_result.distance < MAX_RAY_LENGTH) {
let nrsp = reconstructPosition(nsp, nref, nrt_result);
let nrnor = normalWithID(nrsp);
let nrref = reflect(nref, nrnor);
- nrcol = boxCol(nrcol, nrsp, nref, nrnor, render0(nrsp, nrref), 1.0, 1.0);
+ nrcol = boxCol(nrcol, nrsp, nref, nrnor, render0(Ray(nrsp, nrref)), 1.0, 1.0);
}
let light_dist1 = distance(lightPos1, nsp);
@@ -172,7 +170,7 @@ fn render1(ro: vec3<f32>, rd: vec3<f32>) -> vec3<f32> {
let nshd1 = mix(0.0, 1.0, shadowWithStoredDistance(nsp, normalize(lightPos1 - nsp), light_dist1));
let nshd2 = mix(0.0, 1.0, shadowWithStoredDistance(nsp, normalize(lightPos2 - nsp), light_dist2));
- col = boxCol(col, nsp, rd, nnor, nrcol, nshd1, nshd2);
+ col = boxCol(col, nsp, ray.direction, nnor, nrcol, nshd1, nshd2);
}
return col;
@@ -181,7 +179,7 @@ fn render1(ro: vec3<f32>, rd: vec3<f32>) -> vec3<f32> {
fn effect(p: vec2<f32>) -> vec3<f32> {
g_rot0 = rot(-0.2 * uniforms.time);
let ray = getCameraRay(camera, p);
- return render1(ray.origin, ray.direction);
+ return render1(ray);
}
#include "render/fullscreen_vs"