bevy/src/render/light.rs

36 lines
962 B
Rust
Raw Normal View History

2019-12-03 17:01:15 +00:00
use crate::{math, render::camera, Translation};
2019-12-02 04:03:04 +00:00
use std::ops::Range;
use zerocopy::{AsBytes, FromBytes};
pub struct Light {
pub color: wgpu::Color,
pub fov: f32,
pub depth: Range<f32>,
pub target_view: Option<wgpu::TextureView>,
2019-12-02 04:03:04 +00:00
}
#[repr(C)]
#[derive(Clone, Copy, AsBytes, FromBytes)]
pub struct LightRaw {
pub proj: [[f32; 4]; 4],
pub pos: [f32; 4],
pub color: [f32; 4],
}
2019-12-03 17:01:15 +00:00
impl LightRaw {
pub fn from(light: &Light, transform: &math::Mat4, translation: &Translation) -> LightRaw {
2019-12-04 08:11:14 +00:00
let proj = camera::get_projection_matrix(light.fov, 1.0, light.depth.start, light.depth.end) * *transform;
let (x, y, z) = translation.0.into();
2019-12-02 04:03:04 +00:00
LightRaw {
2019-12-04 08:11:14 +00:00
proj: proj.to_cols_array_2d(),
pos: [x, y, z, 1.0],
2019-12-02 04:03:04 +00:00
color: [
2019-12-03 17:01:15 +00:00
light.color.r as f32,
light.color.g as f32,
light.color.b as f32,
2019-12-02 04:03:04 +00:00
1.0,
],
}
}
}