From 0f9291df7b463251c581ffd397b259478066d7ac Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 20 Jul 2026 13:27:36 +0300 Subject: [PATCH] add light --- src/lib.rs | 9 ++++++++- src/mesh.wgsl | 5 ++++- src/render.rs | 2 ++ ui/src/main_window.ui | 6 +++--- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index dd8e141..7b1eed6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -109,13 +109,20 @@ impl Core { let camera = camera::OrbitalCamera { position_yaw: args.camera_yaw, position_pitch: args.camera_pitch, - distance: 5. * args.shape.base_diameter, + distance: 160., + }; + let light = camera::OrbitalCamera { + position_yaw: args.light_yaw, + position_pitch: args.light_pitch, + distance: 1., }; let perspective = Mat4::perspective_lh(std::f32::consts::FRAC_PI_3, aspect, 1e1, 1e3); self.pipeline.set_look( &self.queue, render::LookParams { m: perspective * camera.transform(), + light: light.direction(), + bright: 1., }, ); self.queue.submit([]); // flush buffer updates diff --git a/src/mesh.wgsl b/src/mesh.wgsl index be4575f..be2088e 100644 --- a/src/mesh.wgsl +++ b/src/mesh.wgsl @@ -1,5 +1,7 @@ struct LookParams { m: mat4x4f, + light: vec3f, + bright: f32, } struct Vertex { @@ -23,5 +25,6 @@ fn on_vertex(in: Vertex) -> Varying { @fragment fn on_fragment(in: Varying) -> @location(0) vec4f { - return vec4f(0.5 + 0.5 * in.normal, 1.0); + let light = -dot(look.light, in.normal); + return vec4f(clamp(light, 0.01, 1.0) * vec3f(1.0), 1.0); } diff --git a/src/render.rs b/src/render.rs index 0b6228c..f05f96e 100644 --- a/src/render.rs +++ b/src/render.rs @@ -12,6 +12,8 @@ static MESH_SHADER: &str = include_str!("mesh.wgsl"); #[repr(C)] pub struct LookParams { pub m: Mat4, + pub light: Vec3, + pub bright: f32, } #[derive(Debug, Clone, Copy, Zeroable, Pod)] diff --git a/ui/src/main_window.ui b/ui/src/main_window.ui index 2e6c123..66825a7 100644 --- a/ui/src/main_window.ui +++ b/ui/src/main_window.ui @@ -274,9 +274,9 @@ - 85 - 170 - 255 + 0 + 0 + 0