add light

This commit is contained in:
numzero 2026-07-20 13:27:36 +03:00
parent e28bb305d6
commit 0f9291df7b
4 changed files with 17 additions and 5 deletions

View File

@ -109,13 +109,20 @@ impl Core {
let camera = camera::OrbitalCamera { let camera = camera::OrbitalCamera {
position_yaw: args.camera_yaw, position_yaw: args.camera_yaw,
position_pitch: args.camera_pitch, 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); let perspective = Mat4::perspective_lh(std::f32::consts::FRAC_PI_3, aspect, 1e1, 1e3);
self.pipeline.set_look( self.pipeline.set_look(
&self.queue, &self.queue,
render::LookParams { render::LookParams {
m: perspective * camera.transform(), m: perspective * camera.transform(),
light: light.direction(),
bright: 1.,
}, },
); );
self.queue.submit([]); // flush buffer updates self.queue.submit([]); // flush buffer updates

View File

@ -1,5 +1,7 @@
struct LookParams { struct LookParams {
m: mat4x4f, m: mat4x4f,
light: vec3f,
bright: f32,
} }
struct Vertex { struct Vertex {
@ -23,5 +25,6 @@ fn on_vertex(in: Vertex) -> Varying {
@fragment @fragment
fn on_fragment(in: Varying) -> @location(0) vec4f { 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);
} }

View File

@ -12,6 +12,8 @@ static MESH_SHADER: &str = include_str!("mesh.wgsl");
#[repr(C)] #[repr(C)]
pub struct LookParams { pub struct LookParams {
pub m: Mat4, pub m: Mat4,
pub light: Vec3,
pub bright: f32,
} }
#[derive(Debug, Clone, Copy, Zeroable, Pod)] #[derive(Debug, Clone, Copy, Zeroable, Pod)]

View File

@ -274,9 +274,9 @@
<widget class="KColorCombo" name="inBackground"> <widget class="KColorCombo" name="inBackground">
<property name="color"> <property name="color">
<color> <color>
<red>85</red> <red>0</red>
<green>170</green> <green>0</green>
<blue>255</blue> <blue>0</blue>
</color> </color>
</property> </property>
</widget> </widget>