From 535b63d608948c5a9a85e96d1e8c7e475b00ede0 Mon Sep 17 00:00:00 2001 From: skal Date: Wed, 4 Feb 2026 09:45:17 +0100 Subject: 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). --- assets/final/shaders/common_uniforms.wgsl | 3 ++- assets/final/shaders/skybox.wgsl | 22 +++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) (limited to 'assets') diff --git a/assets/final/shaders/common_uniforms.wgsl b/assets/final/shaders/common_uniforms.wgsl index cefa3b2..4b5cf33 100644 --- a/assets/final/shaders/common_uniforms.wgsl +++ b/assets/final/shaders/common_uniforms.wgsl @@ -1,5 +1,6 @@ struct GlobalUniforms { view_proj: mat4x4, + inv_view_proj: mat4x4, camera_pos_time: vec4, params: vec4, resolution: vec2, @@ -12,4 +13,4 @@ struct ObjectData { }; struct ObjectsBuffer { objects: array, -}; +}; \ No newline at end of file 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) -> @location(0) vec4 { - return textureSample(sky_tex, sky_sampler, frag_pos.xy / globals.resolution); -} +fn fs_main(in: VertexOutput) -> @location(0) vec4 { + // 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(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(u, v)); +} \ No newline at end of file -- cgit v1.2.3