mirror of https://github.com/Leinnan/doppler.git
DirectionalLight struct
This commit is contained in:
parent
1544f55bbd
commit
a6ace9894a
|
|
@ -188,7 +188,7 @@ impl Client for ExampleClient {
|
||||||
.opened(&mut show_window)
|
.opened(&mut show_window)
|
||||||
.build(&ui, || {
|
.build(&ui, || {
|
||||||
ui.drag_int(im_str!("id"), &mut id).min(0).max(max).build();
|
ui.drag_int(im_str!("id"), &mut id).min(0).max(max).build();
|
||||||
// id = if id < 0 { 0 } else if id > max { max } else { id };
|
|
||||||
let mut selected_mut = vec![&mut self.models[id as usize].transform];
|
let mut selected_mut = vec![&mut self.models[id as usize].transform];
|
||||||
<Transform as imgui_inspect::InspectRenderStruct<Transform>>::render_mut(
|
<Transform as imgui_inspect::InspectRenderStruct<Transform>>::render_mut(
|
||||||
&mut selected_mut,
|
&mut selected_mut,
|
||||||
|
|
@ -209,11 +209,23 @@ impl Client for ExampleClient {
|
||||||
.size([250.0, 250.0], Condition::FirstUseEver)
|
.size([250.0, 250.0], Condition::FirstUseEver)
|
||||||
.opened(&mut show_window)
|
.opened(&mut show_window)
|
||||||
.build(&ui, || {
|
.build(&ui, || {
|
||||||
|
{
|
||||||
|
let mut selected_mut = vec![&mut self.lighting_system.directional_light];
|
||||||
|
<DirectionalLight as imgui_inspect::InspectRenderStruct<
|
||||||
|
DirectionalLight,
|
||||||
|
>>::render_mut(
|
||||||
|
&mut selected_mut,
|
||||||
|
"DirectionalLightInfo",
|
||||||
|
&ui,
|
||||||
|
&InspectArgsStruct::default(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
ui.separator();
|
||||||
ui.drag_int(im_str!("Light ID"), &mut id)
|
ui.drag_int(im_str!("Light ID"), &mut id)
|
||||||
.min(0)
|
.min(0)
|
||||||
.max(max)
|
.max(max)
|
||||||
.build();
|
.build();
|
||||||
// id = if id < 0 { 0 } else if id > max { max } else { id };
|
{
|
||||||
let mut selected_mut =
|
let mut selected_mut =
|
||||||
vec![&mut self.lighting_system.point_lights[id as usize]];
|
vec![&mut self.lighting_system.point_lights[id as usize]];
|
||||||
<PointLight as imgui_inspect::InspectRenderStruct<PointLight>>::render_mut(
|
<PointLight as imgui_inspect::InspectRenderStruct<PointLight>>::render_mut(
|
||||||
|
|
@ -222,8 +234,6 @@ impl Client for ExampleClient {
|
||||||
&ui,
|
&ui,
|
||||||
&InspectArgsStruct::default(),
|
&InspectArgsStruct::default(),
|
||||||
);
|
);
|
||||||
if ui.button(im_str!("Print light info"), [0.0, 0.0]) {
|
|
||||||
println!("{:?}",selected_mut);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
self.light_info_id = id;
|
self.light_info_id = id;
|
||||||
|
|
|
||||||
|
|
@ -79,9 +79,62 @@ impl Default for PointLight {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Inspect, Clone, Copy, Debug)]
|
||||||
|
pub struct DirectionalLight {
|
||||||
|
#[inspect(proxy_type = "CgmathVec3f32")]
|
||||||
|
pub direction: Vector3<f32>,
|
||||||
|
#[inspect(proxy_type = "CgmathVec3f32")]
|
||||||
|
pub ambient: Vector3<f32>,
|
||||||
|
#[inspect(proxy_type = "CgmathVec3f32")]
|
||||||
|
pub diffuse: Vector3<f32>,
|
||||||
|
#[inspect(proxy_type = "CgmathVec3f32")]
|
||||||
|
pub specular: Vector3<f32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for DirectionalLight {
|
||||||
|
fn default() -> Self {
|
||||||
|
DirectionalLight {
|
||||||
|
direction: vec3(-0.3, -1.0, -0.3),
|
||||||
|
ambient: vec3(0.14, 0.14, 0.14),
|
||||||
|
diffuse: vec3(0.4, 0.4, 0.4),
|
||||||
|
specular: vec3(0.5, 0.5, 0.5),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DirectionalLight {
|
||||||
|
pub unsafe fn shader_update(&self, shader: &Shader) {
|
||||||
|
shader.set_vec3(
|
||||||
|
c_str!("dirLight.direction"),
|
||||||
|
self.direction.x,
|
||||||
|
self.direction.y,
|
||||||
|
self.direction.z,
|
||||||
|
);
|
||||||
|
shader.set_vec3(
|
||||||
|
c_str!("dirLight.ambient"),
|
||||||
|
self.ambient.x,
|
||||||
|
self.ambient.y,
|
||||||
|
self.ambient.z,
|
||||||
|
);
|
||||||
|
shader.set_vec3(
|
||||||
|
c_str!("dirLight.diffuse"),
|
||||||
|
self.diffuse.x,
|
||||||
|
self.diffuse.y,
|
||||||
|
self.diffuse.z,
|
||||||
|
);
|
||||||
|
shader.set_vec3(
|
||||||
|
c_str!("dirLight.specular"),
|
||||||
|
self.specular.x,
|
||||||
|
self.specular.y,
|
||||||
|
self.specular.z,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct LightingSystem {
|
pub struct LightingSystem {
|
||||||
pub shader: Shader,
|
pub shader: Shader,
|
||||||
pub point_lights: [PointLight; 4],
|
pub point_lights: [PointLight; 4],
|
||||||
|
pub directional_light: DirectionalLight,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LightingSystem {
|
impl LightingSystem {
|
||||||
|
|
@ -93,32 +146,13 @@ impl LightingSystem {
|
||||||
) {
|
) {
|
||||||
self.shader.use_program();
|
self.shader.use_program();
|
||||||
|
|
||||||
use inline_tweak::*;
|
|
||||||
self.shader.set_mat4(c_str!("projection"), projection);
|
self.shader.set_mat4(c_str!("projection"), projection);
|
||||||
self.shader.set_mat4(c_str!("view"), view);
|
self.shader.set_mat4(c_str!("view"), view);
|
||||||
self.shader.set_vector3(c_str!("viewPos"), view_pos);
|
self.shader.set_vector3(c_str!("viewPos"), view_pos);
|
||||||
self.shader.setFloat(c_str!("material.shininess"), 32.0);
|
self.shader.setFloat(c_str!("material.shininess"), 32.0);
|
||||||
|
|
||||||
self.shader.set_vec3(
|
self.directional_light.shader_update(&self.shader);
|
||||||
c_str!("dirLight.direction"),
|
|
||||||
tweak!(-0.3),
|
|
||||||
tweak!(-1.0),
|
|
||||||
tweak!(-0.3),
|
|
||||||
);
|
|
||||||
self.shader.set_vec3(
|
|
||||||
c_str!("dirLight.ambient"),
|
|
||||||
tweak!(0.14),
|
|
||||||
tweak!(0.14),
|
|
||||||
tweak!(0.14),
|
|
||||||
);
|
|
||||||
self.shader.set_vec3(
|
|
||||||
c_str!("dirLight.diffuse"),
|
|
||||||
tweak!(0.4),
|
|
||||||
tweak!(0.4),
|
|
||||||
tweak!(0.4),
|
|
||||||
);
|
|
||||||
self.shader
|
|
||||||
.set_vec3(c_str!("dirLight.specular"), 0.5, 0.5, 0.5);
|
|
||||||
for (i, v) in self.point_lights.iter().enumerate() {
|
for (i, v) in self.point_lights.iter().enumerate() {
|
||||||
v.shader_update(i, &self.shader);
|
v.shader_update(i, &self.shader);
|
||||||
}
|
}
|
||||||
|
|
@ -146,6 +180,7 @@ impl Default for LightingSystem {
|
||||||
..PointLight::default()
|
..PointLight::default()
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
directional_light: DirectionalLight::default(),
|
||||||
shader: Shader::from_file(
|
shader: Shader::from_file(
|
||||||
"resources/shaders/multiple_lights.vs",
|
"resources/shaders/multiple_lights.vs",
|
||||||
"resources/shaders/multiple_lights.fs",
|
"resources/shaders/multiple_lights.fs",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue