docs: Étape 14 (shadows) finale — bilan DRAFT, ROADMAP §4.2, README roadmap

- docs/DRAFT.md: document vidé (bilan Étape 14 archivé dans l'historique git)
- docs/ROADMAP.md §4.2: Shadows marqué [x] (Étape 14, mono-lumière PCF)
- README.md: item 12 de la roadmap (shadow mapping)
- cargo fmt --all sur les sources Étape 14
This commit is contained in:
Jérôme Bousquié
2026-09-19 19:04:12 +02:00
parent 9a51ff7602
commit bfe68f4393
8 changed files with 65 additions and 240 deletions
+19 -4
View File
@@ -13,7 +13,7 @@
//! proving the depth comparison is applied per-pixel.
//!
//! Run with: `cargo run -p wsg-lib --example shadow_test`
use glam::{Vec3};
use glam::Vec3;
use wsg_lib::resources::{Camera, Geometry};
use wsg_lib::utils::WsgError;
@@ -30,7 +30,12 @@ fn box_geometry(hx: f32, hy: f32, hz: f32) -> Geometry {
), // +Z
(
[0.0, 0.0, -1.0],
[[hx, -hy, -hz], [-hx, -hy, -hz], [-hx, hy, -hz], [hx, hy, -hz]],
[
[hx, -hy, -hz],
[-hx, -hy, -hz],
[-hx, hy, -hz],
[hx, hy, -hz],
],
), // -Z
(
[1.0, 0.0, 0.0],
@@ -38,7 +43,12 @@ fn box_geometry(hx: f32, hy: f32, hz: f32) -> Geometry {
), // +X
(
[-1.0, 0.0, 0.0],
[[-hx, -hy, hz], [-hx, hy, hz], [-hx, hy, -hz], [-hx, -hy, -hz]],
[
[-hx, -hy, hz],
[-hx, hy, hz],
[-hx, hy, -hz],
[-hx, -hy, -hz],
],
), // -X
(
[0.0, 1.0, 0.0],
@@ -46,7 +56,12 @@ fn box_geometry(hx: f32, hy: f32, hz: f32) -> Geometry {
), // +Y
(
[0.0, -1.0, 0.0],
[[-hx, -hy, hz], [hx, -hy, hz], [hx, -hy, -hz], [-hx, -hy, -hz]],
[
[-hx, -hy, hz],
[hx, -hy, hz],
[hx, -hy, -hz],
[-hx, -hy, -hz],
],
), // -Y
];
+11 -14
View File
@@ -27,7 +27,7 @@ use crate::pipeline::{
};
use crate::resources::uniform::{FRAME_UNIFORMS_SIZE, OBJECT_UNIFORM_SIZE, SHADOW_UNIFORM_SIZE};
use crate::resources::{
Camera, FrameUniforms, Lights, Material, Mesh, ObjectUniform, ShadowUniform, MAX_LIGHTS,
Camera, FrameUniforms, Lights, MAX_LIGHTS, Material, Mesh, ObjectUniform, ShadowUniform,
};
use crate::scene::Scene;
use crate::utils::conf::{
@@ -350,11 +350,9 @@ impl Renderer {
-light.position_dir.y,
-light.position_dir.z,
),
crate::resources::LightType::Spot { .. } => Vec3::new(
light.dir_angle.x,
light.dir_angle.y,
light.dir_angle.z,
),
crate::resources::LightType::Spot { .. } => {
Vec3::new(light.dir_angle.x, light.dir_angle.y, light.dir_angle.z)
}
crate::resources::LightType::Point => return None,
};
let r = SHADOW_SCENE_RADIUS;
@@ -371,8 +369,7 @@ impl Renderer {
// scene-radius behind the target, so the box [−r, r] around the target spans a depth range
// of [0, 2r] from the eye: `far = 2·r` covers the whole box (and the shadows cast behind
// it), whereas `far = r` would clip the far half.
let proj =
glam::camera::rh::proj::directx::orthographic(-r, r, -r, r, 0.0, 2.0 * r);
let proj = glam::camera::rh::proj::directx::orthographic(-r, r, -r, r, 0.0, 2.0 * r);
Some((index, proj * view))
}
@@ -525,8 +522,11 @@ impl Renderer {
None => return,
};
let shadow_uniform = ShadowUniform { view_proj: vp };
self.queue
.write_buffer(&self.shadow_uniform_buffer, 0, bytemuck::bytes_of(&shadow_uniform));
self.queue.write_buffer(
&self.shadow_uniform_buffer,
0,
bytemuck::bytes_of(&shadow_uniform),
);
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("shadow map render pass"),
@@ -654,10 +654,7 @@ fn create_depth_texture(
/// comparison sampler). Allocated once at the default resolution; resizing is deferred (D8).
/// Inputs: device (GPU resource creator), size (shadow map edge length in pixels).
/// Returns the (texture, view) pair; the caller keeps both alive.
fn create_shadow_map(
device: &wgpu::Device,
size: u32,
) -> (wgpu::Texture, wgpu::TextureView) {
fn create_shadow_map(device: &wgpu::Device, size: u32) -> (wgpu::Texture, wgpu::TextureView) {
let shadow_texture = device.create_texture(&wgpu::TextureDescriptor {
label: Some("shadow map"),
size: wgpu::Extent3d {
-1
View File
@@ -470,4 +470,3 @@ pub fn build_shadow_pipeline(
cache: None,
})
}
+2 -2
View File
@@ -27,8 +27,8 @@ pub use material::Material;
pub use mesh::Mesh;
pub use texture::{Texture, TextureError};
pub use uniform::{
FrameUniforms, Light, LightType, MAX_LIGHTS, ObjectUniform, ShadowUniform, FRAME_UNIFORMS_SIZE,
OBJECT_UNIFORM_SIZE, SHADOW_UNIFORM_SIZE,
FRAME_UNIFORMS_SIZE, FrameUniforms, Light, LightType, MAX_LIGHTS, OBJECT_UNIFORM_SIZE,
ObjectUniform, SHADOW_UNIFORM_SIZE, ShadowUniform,
};
pub use vertex::Vertex;
+8 -2
View File
@@ -204,8 +204,14 @@ mod tests {
offset_of!(FrameUniforms, num_directional),
160 + 64 * MAX_LIGHTS
);
assert_eq!(offset_of!(FrameUniforms, num_point), 160 + 64 * MAX_LIGHTS + 4);
assert_eq!(offset_of!(FrameUniforms, num_spot), 160 + 64 * MAX_LIGHTS + 8);
assert_eq!(
offset_of!(FrameUniforms, num_point),
160 + 64 * MAX_LIGHTS + 4
);
assert_eq!(
offset_of!(FrameUniforms, num_spot),
160 + 64 * MAX_LIGHTS + 8
);
assert_eq!(
offset_of!(FrameUniforms, shadow_light_index),
160 + 64 * MAX_LIGHTS + 12