refactor examples

This commit is contained in:
Jérôme Bousquié
2026-09-25 10:19:24 +02:00
parent ab3f056dbb
commit 35aeb769a8
37 changed files with 3430 additions and 457 deletions
+38 -1
View File
@@ -20,6 +20,10 @@
//! `AppBuilder::with_hdr(ToneMapper::Aces)`. The main pass renders to an offscreen
//! `Rgba16Float` texture, then a fullscreen TM pass compresses it to [0,1] and writes
//! to the sRGB surface — highlights are softly rolled off instead of clipping to white.
//! * **Exposure** (Étape 22, 6.1): keys `+` / `-` adjust the tone mapping exposure live
//! (×1.3 / ÷1.3 per press), `0` resets to 1.0.
//! * **Emissive** (Étape 22, 6.2): a small glowing orange sphere sits at the center
//! (emissive intensity 2.0 → HDR glow, visible even in shadow).
//!
//! Doc (this header) follows the English convention used for examples; internal comments stay
//! concise and French where helpful. Run with:
@@ -31,10 +35,12 @@ use winit::event::MouseButton;
use winit::keyboard::KeyCode;
use wsg_lib::AppHandler;
use wsg_lib::app::AppBuilder;
use wsg_lib::core::BloomConfig;
use wsg_lib::core::ToneMapper;
use wsg_lib::core::Transform;
use wsg_lib::mesh::{cone, cube, cylinder, icosphere, plane, torus, uv_sphere};
use wsg_lib::resources::{CameraController, Texture};
use wsg_lib::camera::CameraController;
use wsg_lib::resources::Texture;
use wsg_lib::utils::WsgError;
/// Generates an 8×8 RGBA checkerboard (white / brick) as raw bytes for `Texture::from_rgba8`.
@@ -169,6 +175,24 @@ impl AppHandler for Demo {
place("cone_e", "cone_mesh", app, 4);
place("torus_e", "torus_mesh", app, 5);
// 4b. Étape 22 (6.2): emissive demo — a small glowing sphere at the center.
// The material has emissive = [1.0, 0.3, 0.05, 2.0] (orange, intensity 2.0 = HDR glow).
// IMPORTANT: set emissive BEFORE create_mesh (the mesh captures the Arc at creation).
app.scene
.add_material_texture("glow_mat", "standard", "checker_texture")
.unwrap();
app.scene
.set_material_emissive("glow_mat", [1.0, 0.3, 0.05, 2.0])
.unwrap();
app.scene
.create_mesh("glow_mesh", icosphere(0.3, 3), Some("glow_mat"))
.unwrap();
let mut glow_tf = Transform::identity();
glow_tf.translation = Vec3::new(0.0, 0.5, 0.0);
app.scene
.add_entity_with_transform("glow_e", "glow_mesh", glow_tf)
.unwrap();
// 5. Lights: a shadow-casting directional + a warm point + a green spot.
// Start from the default list (directional +Z) so we keep it and add the rest.
let toward_light = Vec3::new(1.0, 1.2, 1.0).normalize();
@@ -239,6 +263,18 @@ impl AppHandler for Demo {
}
self.camera.apply_to(app.scene.camera_mut());
// ---- Étape 22 (6.1): exposure control ----
// `+` / `-`: multiply/divide by 1.3 (visible step). `0`: reset to 1.0.
if app.input.key_pressed(KeyCode::Equal) {
app.set_exposure(app.exposure() * 1.3);
}
if app.input.key_pressed(KeyCode::Minus) {
app.set_exposure(app.exposure() / 1.3);
}
if app.input.key_pressed(KeyCode::Digit0) {
app.set_exposure(1.0);
}
// ---- Slow rotation of the primitives so lighting/shadow read clearly ----
self.angle += 0.008;
let base = *app
@@ -281,6 +317,7 @@ async fn main() -> Result<(), WsgError> {
.title("WSG Demo")
.with_culling(true)
.with_hdr(ToneMapper::Aces)
.with_bloom(BloomConfig::default())
.build()
.await?;
app.run(Demo {