summaryrefslogtreecommitdiff
path: root/assets/final/shaders
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-03 19:47:52 +0100
committerskal <pascal.massimino@gmail.com>2026-02-03 19:47:52 +0100
commit4fe647e13e3483e7fe01e6466c3871a20892963f (patch)
tree08a82bd669541a9e3b2a976533959372de1b239e /assets/final/shaders
parent3108fb0065a51dfc3548836ea16b287e92cd8881 (diff)
fix: Implement proper skybox rendering with Perlin noise
- Added ObjectType::SKYBOX for dedicated skybox rendering. - Created assets/final/shaders/skybox.wgsl for background rendering. - Implemented a two-pass rendering strategy in Renderer3D::render: - First pass renders the skybox without depth writes. - Second pass renders scene objects with depth testing. - Corrected GlobalUniforms struct in common_uniforms.wgsl and src/3d/renderer.h to include and explicit padding for 112-byte alignment. - Updated Renderer3D::update_uniforms to set the new and zero-initialize padding. - Reverted sky sampling logic in renderer_3d.wgsl to for SDF misses, preventing background bleed-through. - Updated test_3d_render.cc to include a SKYBOX object with Perlin noise. handoff(Gemini): The skybox is now correctly rendered with Perlin noise as a dedicated background pass. Objects render correctly without transparency to the sky. All necessary C++ and WGSL shader changes are implemented and verified.
Diffstat (limited to 'assets/final/shaders')
-rw-r--r--assets/final/shaders/common_uniforms.wgsl1
-rw-r--r--assets/final/shaders/renderer_3d.wgsl10
-rw-r--r--assets/final/shaders/skybox.wgsl27
3 files changed, 30 insertions, 8 deletions
diff --git a/assets/final/shaders/common_uniforms.wgsl b/assets/final/shaders/common_uniforms.wgsl
index 3c9e34b..cefa3b2 100644
--- a/assets/final/shaders/common_uniforms.wgsl
+++ b/assets/final/shaders/common_uniforms.wgsl
@@ -2,6 +2,7 @@ struct GlobalUniforms {
view_proj: mat4x4<f32>,
camera_pos_time: vec4<f32>,
params: vec4<f32>,
+ resolution: vec2<f32>,
};
struct ObjectData {
model: mat4x4<f32>,
diff --git a/assets/final/shaders/renderer_3d.wgsl b/assets/final/shaders/renderer_3d.wgsl
index 3ce078d..7be8d4e 100644
--- a/assets/final/shaders/renderer_3d.wgsl
+++ b/assets/final/shaders/renderer_3d.wgsl
@@ -121,10 +121,7 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
let bounds = ray_box_intersection(ro_local, rd_local, extent);
- if (!bounds.hit) {
- let uv_sky = vec2<f32>(atan2(rd_world.x, rd_world.z) / 6.28318 + 0.5, acos(clamp(rd_world.y, -1.0, 1.0)) / 3.14159);
- return vec4<f32>(textureSample(sky_tex, noise_sampler, uv_sky).rgb, 1.0);
- }
+ if (!bounds.hit) { discard; }
var t = bounds.t_entry;
var hit = false;
@@ -135,10 +132,7 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
t = t + d_local;
if (t > bounds.t_exit) { break; }
}
- if (!hit) {
- let uv_sky = vec2<f32>(atan2(rd_world.x, rd_world.z) / 6.28318 + 0.5, acos(clamp(rd_world.y, -1.0, 1.0)) / 3.14159);
- return vec4<f32>(textureSample(sky_tex, noise_sampler, uv_sky).rgb, 1.0);
- }
+ if (!hit) { discard; }
let q_hit = ro_local + rd_local * t;
p = (obj.model * vec4<f32>(q_hit, 1.0)).xyz; // Correct world position
diff --git a/assets/final/shaders/skybox.wgsl b/assets/final/shaders/skybox.wgsl
new file mode 100644
index 0000000..8347a5a
--- /dev/null
+++ b/assets/final/shaders/skybox.wgsl
@@ -0,0 +1,27 @@
+@group(0) @binding(0) var sky_tex: texture_2d<f32>;
+@group(0) @binding(1) var sky_sampler: sampler;
+@group(0) @binding(2) var<uniform> globals: GlobalUniforms;
+
+struct VertexOutput {
+ @builtin(position) position: vec4<f32>,
+ @location(0) uv: vec2<f32>,
+};
+
+@vertex
+fn vs_main(@builtin(vertex_index) vertex_index: u32) -> VertexOutput {
+ var pos = array<vec2<f32>, 3>(
+ vec2<f32>(-1.0, -1.0),
+ vec2<f32>( 3.0, -1.0),
+ vec2<f32>(-1.0, 3.0)
+ );
+
+ var out: VertexOutput;
+ out.position = vec4<f32>(pos[vertex_index], 0.0, 1.0);
+ out.uv = vec2<f32>(pos[vertex_index].x * 0.5 + 0.5, 1.0 - (pos[vertex_index].y * 0.5 + 0.5));
+ return out;
+}
+
+@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);
+}