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 {
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

View File

@ -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);
}

View File

@ -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)]

View File

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