diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-02 14:05:31 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-02 14:05:31 +0100 |
| commit | 9048115d66cb5ad18e37aad7d48cb6a708b3c3d5 (patch) | |
| tree | 2dfa84ef0ada61328247b949e1d27c408004a12d /src/3d | |
| parent | a5409a168d08552c0fc0ad2cff8a9f32199272a1 (diff) | |
fix(3d): Resolve shader validation error and tune shadows
- Fixed 'redefinition of light_dir' shader validation error by centralizing the light definition at the top of fs_main.
- Further brightened the floor in 'test_3d_render' for better shadow contrast.
- Reduced shadow bias and made the light more vertical to ensure shadows are clearly visible on all surfaces.
Diffstat (limited to 'src/3d')
| -rw-r--r-- | src/3d/renderer.cc | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/3d/renderer.cc b/src/3d/renderer.cc index 3280df7..cc2124e 100644 --- a/src/3d/renderer.cc +++ b/src/3d/renderer.cc @@ -151,7 +151,7 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> { var p: vec3<f32>; var normal: vec3<f32>; - let light_dir = normalize(vec3<f32>(1.0, 1.0, 1.0)); + let light_dir = normalize(vec3<f32>(0.2, 1.0, 0.2)); // More vertical light for easier shadow debugging if (obj_type == 0.0) { // Rasterized object p = in.world_pos; @@ -219,10 +219,9 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> { let n_local = normalize(vec3<f32>(d_x1 - d_x2, d_y1 - d_y2, d_z1 - d_z2)); - normal = normalize(mat3 * n_local); - } + let n_world = mat3 * n_local; + let normal = normalize(n_world); - let light_dir = normalize(vec3<f32>(0.2, 1.0, 0.2)); // More vertical light for easier shadow debugging let shadow = calc_shadow(p + normal * 0.01, light_dir, 0.0, 20.0); let lighting = (max(dot(normal, light_dir), 0.0) * shadow) + 0.1; |
