diff options
Diffstat (limited to 'workspaces')
| -rw-r--r-- | workspaces/main/shaders/scene1.wgsl | 44 | ||||
| -rw-r--r-- | workspaces/main/shaders/sdf_test.wgsl | 16 |
2 files changed, 30 insertions, 30 deletions
diff --git a/workspaces/main/shaders/scene1.wgsl b/workspaces/main/shaders/scene1.wgsl index 87949fa..8cc36cd 100644 --- a/workspaces/main/shaders/scene1.wgsl +++ b/workspaces/main/shaders/scene1.wgsl @@ -12,23 +12,23 @@ @group(0) @binding(2) var<uniform> uniforms: UniformsSequenceParams; @group(0) @binding(3) var<uniform> camera: CameraParams; -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); +const skyCol = vec3f(0.176, 0.235, 0.25); +const skylineCol = vec3f(0.5, 0.125, 0.025); +const sunCol = vec3f(0.5, 0.163, 0.025); +const diffCol1 = vec3f(0.4, 1.0, 1.0); +const diffCol2 = vec3f(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); +const sunDir1 = vec3f(0.0, 0.04997, -0.99875); // normalize(0, 0.05, -1) +const lightPos1 = vec3f(10.0, 10.0, 10.0); +const lightPos2 = vec3f(-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); } -fn render0(ray: Ray) -> vec3<f32> { - var col = vec3<f32>(0.0); +fn render0(ray: Ray) -> vec3f { + var col = vec3f(0.0); let y = abs(ray.direction.y); let sf = 1.0001 - max(dot(sunDir1, ray.direction), 0.0); col += skyCol * pow(y, 8.0); @@ -41,11 +41,11 @@ fn render0(ray: Ray) -> vec3<f32> { 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 * y * y * smoothstep(0.25, 0.0, db); - col += vec3<f32>(0.8) * skyCol * exp(-0.5 * max(db, 0.0)); + col += vec3f(4.0) * skyCol * y * y * smoothstep(0.25, 0.0, db); + col += vec3f(0.8) * skyCol * exp(-0.5 * max(db, 0.0)); } */ - return clamp(col, vec3<f32>(0.0), vec3<f32>(10.0)); + return clamp(col, vec3f(0.0), vec3f(10.0)); } const OBJ_BACKGROUND: f32 = 0.0; @@ -54,17 +54,17 @@ const OBJ_SPHERE: f32 = 2.0; const OBJ_PLANE: f32 = 3.0; // TODO: remove! (issue with #include macros) -fn df(p: vec3<f32>) -> f32 { +fn df(p: vec3f) -> f32 { return 0.; } -fn dfWithID(p: vec3<f32>) -> RayMarchResult { +fn dfWithID(p: vec3f) -> RayMarchResult { // Cube - var pc = p - vec3<f32>(-1.9, 0.0, 0.0); - let dCube = sdBox(pc, vec3<f32>(1.6)); + var pc = p - vec3f(-1.9, 0.0, 0.0); + let dCube = sdBox(pc, vec3f(1.6)); // Sphere - var ps = p - vec3<f32>(1.3, 0.0, 0.0); + var ps = p - vec3f(1.3, 0.0, 0.0); let dSphere = sdSphere(ps, 1.2); // Ground plane @@ -89,7 +89,7 @@ fn dfWithID(p: vec3<f32>) -> RayMarchResult { return result; } -fn boxCol(col: vec3<f32>, nsp: vec3<f32>, rd: vec3<f32>, nnor: vec3<f32>, nrcol: vec3<f32>, nshd1: f32, nshd2: f32) -> vec3<f32> { +fn boxCol(col: vec3f, nsp: vec3f, rd: vec3f, nnor: vec3f, nrcol: vec3f, nshd1: f32, nshd2: f32) -> vec3f { var nfre = 1.0 + dot(rd, nnor); nfre *= nfre; @@ -102,17 +102,17 @@ fn boxCol(col: vec3<f32>, nsp: vec3<f32>, rd: vec3<f32>, nnor: vec3<f32>, nrcol: var ndif2 = max(dot(nld2, nnor), 0.0); ndif2 *= ndif2; - var scol = vec3<f32>(0.0); + var scol = vec3f(0.0); let rf = smoothstep(1.0, 0.9, nfre); scol += diffCol1 * ndif1 * nshd1; scol += diffCol2 * ndif2 * nshd2; scol += 0.1 * (skyCol + skylineCol); - scol += nrcol * 0.75 * mix(vec3<f32>(0.25), vec3<f32>(0.5, 0.5, 1.0), nfre); + scol += nrcol * 0.75 * mix(vec3f(0.25), vec3f(0.5, 0.5, 1.0), nfre); return mix(col, scol, rf * smoothstep(90.0, 20.0, dot(nsp, nsp))); } -fn render1(ray: Ray) -> vec3<f32> { +fn render1(ray: Ray) -> vec3f { let skyCol_local = render0(ray); var col = skyCol_local; diff --git a/workspaces/main/shaders/sdf_test.wgsl b/workspaces/main/shaders/sdf_test.wgsl index 3c97613..3b63fef 100644 --- a/workspaces/main/shaders/sdf_test.wgsl +++ b/workspaces/main/shaders/sdf_test.wgsl @@ -10,27 +10,27 @@ @group(0) @binding(1) var<uniform> camera: CameraParams; // Scene distance function -fn df(p: vec3<f32>) -> f32 { +fn df(p: vec3f) -> f32 { // Animated sphere - let sphere_pos = vec3<f32>(sin(uniforms.beat_time * 0.5) * 2.0, 0.0, 0.0); + let sphere_pos = vec3f(sin(uniforms.beat_time * 0.5) * 2.0, 0.0, 0.0); let d_sphere = sdSphere(p - sphere_pos, 1.0); // Static box - let box_pos = vec3<f32>(0.0, -2.0, 0.0); - let d_box = sdBox(p - box_pos, vec3<f32>(3.0, 0.5, 3.0)); + let box_pos = vec3f(0.0, -2.0, 0.0); + let d_box = sdBox(p - box_pos, vec3f(3.0, 0.5, 3.0)); return min(d_sphere, d_box); } // Simple lighting -fn shade(pos: vec3<f32>, rd: vec3<f32>) -> vec3<f32> { +fn shade(pos: vec3f, rd: vec3f) -> vec3f { let n = normal(pos); - let light_dir = normalize(vec3<f32>(1.0, 1.0, -1.0)); + let light_dir = normalize(vec3f(1.0, 1.0, -1.0)); let diff = max(dot(n, light_dir), 0.0); let amb = 0.2; // Color based on position - let col = mix(vec3<f32>(0.2, 0.6, 0.9), vec3<f32>(0.9, 0.3, 0.2), + let col = mix(vec3f(0.2, 0.6, 0.9), vec3f(0.9, 0.3, 0.2), smoothstep(-2.0, 2.0, pos.x)); return col * (diff + amb); @@ -56,7 +56,7 @@ fn fs_main(@builtin(position) pos: vec4<f32>) -> @location(0) vec4<f32> { let t = rayMarch(ray.origin, ray.direction, 0.0); // Background color - var col = vec3<f32>(0.1, 0.1, 0.15); + var col = vec3f(0.1, 0.1, 0.15); // Shade hit point if (t < MAX_RAY_LENGTH) { |
