summaryrefslogtreecommitdiff
path: root/assets/final/shaders/skybox.wgsl
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-04 09:45:17 +0100
committerskal <pascal.massimino@gmail.com>2026-02-04 09:45:36 +0100
commit535b63d608948c5a9a85e96d1e8c7e475b00ede0 (patch)
tree58e02774a773abe364fbe72682237203d22f45b6 /assets/final/shaders/skybox.wgsl
parentfdbeddc369d4b55d2098ebdb2e9ef160c0f50368 (diff)
handoff(Claude): Stabilize 3D renderer with rotating skybox and two-pass architecture
- Fixed black screen by ensuring clear operations in Pass 2 when Skybox pass is skipped. - Resolved WebGPU validation errors by synchronizing depth-stencil state. - Implemented rotating skybox using world-space ray unprojection (inv_view_proj). - Improved procedural noise generation (multi-octave Value Noise). - Restored scene integrity by correcting object indexing and removing artifacts. - Updated documentation (TODO.md, PROJECT_CONTEXT.md).
Diffstat (limited to 'assets/final/shaders/skybox.wgsl')
-rw-r--r--assets/final/shaders/skybox.wgsl22
1 files changed, 19 insertions, 3 deletions
diff --git a/assets/final/shaders/skybox.wgsl b/assets/final/shaders/skybox.wgsl
index 8347a5a..6becc1a 100644
--- a/assets/final/shaders/skybox.wgsl
+++ b/assets/final/shaders/skybox.wgsl
@@ -22,6 +22,22 @@ fn vs_main(@builtin(vertex_index) vertex_index: u32) -> VertexOutput {
}
@fragment
-fn fs_main(@builtin(position) frag_pos: vec4<f32>) -> @location(0) vec4<f32> {
- return textureSample(sky_tex, sky_sampler, frag_pos.xy / globals.resolution);
-}
+fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
+ // Convert UV to NDC
+ let ndc_x = in.uv.x * 2.0 - 1.0;
+ let ndc_y = (1.0 - in.uv.y) * 2.0 - 1.0; // Un-flip Y for NDC (Y-up)
+
+ // Unproject to find world direction
+ // We want the direction from camera to the far plane at this pixel
+ let clip_pos = vec4<f32>(ndc_x, ndc_y, 1.0, 1.0);
+ let world_pos_h = globals.inv_view_proj * clip_pos;
+ let world_pos = world_pos_h.xyz / world_pos_h.w;
+
+ let ray_dir = normalize(world_pos - globals.camera_pos_time.xyz);
+
+ // Spherical Mapping
+ let u = atan2(ray_dir.z, ray_dir.x) / 6.28318 + 0.5;
+ let v = asin(clamp(ray_dir.y, -1.0, 1.0)) / 3.14159 + 0.5;
+
+ return textureSample(sky_tex, sky_sampler, vec2<f32>(u, v));
+} \ No newline at end of file