diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-28 10:02:05 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-28 10:02:05 +0100 |
| commit | 21d8a0b86ceda19812e9869a72e49c56c90ae3da (patch) | |
| tree | 915876ba09b29947b5ce3f7edbc62f7b684d708a | |
| parent | b9fd4058db9575267c67acfa03386ebd75428013 (diff) | |
fix(scene2): rewrite broken WGSL shader to fix test_demo_effects crash
scene2.wgsl was invalid WGSL (mixed GLSL syntax, wrong function signatures,
undeclared variables, no return statement). Rewrote as valid WGSL preserving
the original volumetric cloud raymarching logic. 11/11 effects now pass.
handoff(Claude): scene2.wgsl fixed, all tests green.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| -rw-r--r-- | workspaces/main/shaders/scene2.wgsl | 52 |
1 files changed, 23 insertions, 29 deletions
diff --git a/workspaces/main/shaders/scene2.wgsl b/workspaces/main/shaders/scene2.wgsl index 486f41e..7df91c3 100644 --- a/workspaces/main/shaders/scene2.wgsl +++ b/workspaces/main/shaders/scene2.wgsl @@ -1,4 +1,4 @@ -// Scene2 effect shader - ShaderToy conversion +// Scene2 effect shader - ShaderToy conversion (volumetric clouds) // Generated by convert_shadertoy.py // NOTE: Manual review recommended - conversion is basic @@ -7,37 +7,31 @@ @group(0) @binding(2) var<uniform> uniforms: UniformsSequenceParams; - -fn N(vec3f a, vec3f p) { return abs(dot(sin(uniforms.time+.1*p.z+.3*p / a), vec3f(a+a))); } -const NUM_LAYERS: f32 = 12.; - - +fn N(a: vec3f, p: vec3f) -> f32 { + return abs(dot(sin(uniforms.time + 0.1 * p.z + 0.3 * p / a), a + a)); +} @fragment fn fs_main(in: VertexOutput) -> @location(0) vec4f { - // Flip Y to match ShaderToy convention (origin at bottom-left) - let flipped = vec2f(in.position.x, uniforms.resolution.y - in.position.y); - let q = flipped / uniforms.resolution; - var coord = -1.0 + 2.0 * q; - coord.x *= uniforms.resolution.x / uniforms.resolution.y; - - f32 i,s; - vec3f p = vec3f[0),r = uniforms.resolution; + let r = uniforms.resolution; + let frag_coord = vec2f(in.position.x, r.y - in.position.y); + let u = (frag_coord + frag_coord - r) / r.y; - vec2f uv = (u-.5*uniforms.resolution.xy)/uniforms.resolution.y; + var p = vec3f(0.0); + var col = vec4f(0.0); + var s: f32 = 0.0; - f32 t = uniforms.time*.0; - vec3f col = vec3f(0); + for (var i: f32 = 0.0; i < 100.0; i += 1.0) { + p += vec3f(u * s, s); + s = 6.0 + p.y; + s -= N(vec3f(0.08), p); + s -= N(vec3f(0.2), p); + s -= N(vec3f(0.6), p); + s = 0.1 + abs(s) * 0.2; + col += vec4f(4.0, 2.0, 1.0, 0.0) / s; + } - u = (u+u-r.xy)/r.y; - for(o*=i; i++<1e2; ) { - p += vec3f(u * s, s); - s = 6.+(p.y); - s -= N(.08); - s -= N(.2); - s -= N(.6); - s = .1 + abs(s)*.2; - o += vec4f(4,2,1,0)/s; - } - o *= smoothstep(0.8, 0.75, abs(u.y)); - o = tanh(o / 2e3 / length(u)); + col *= smoothstep(0.8, 0.75, abs(u.y)); + let len_u = max(length(u), 0.0001); + col = tanh(col / 2000.0 / len_u); + return vec4f(col.rgb, 1.0); } |
