pub struct ShadowMap {
pub width: u32,
pub height: u32,
pub depth_buffer: Vec<f32>,
pub view_projection: Mat4,
pub near: f32,
pub far: f32,
}Expand description
A single 2D depth buffer for shadow mapping.
Fields§
§width: u32Width of the depth buffer in texels.
height: u32Height of the depth buffer in texels.
depth_buffer: Vec<f32>Depth values stored as a flat row-major array. 1.0 = far, 0.0 = near.
view_projection: Mat4View-projection matrix used when rendering to this shadow map.
near: f32Near plane distance.
far: f32Far plane distance.
Implementations§
Source§impl ShadowMap
impl ShadowMap
Sourcepub fn write_depth(&mut self, x: u32, y: u32, depth: f32)
pub fn write_depth(&mut self, x: u32, y: u32, depth: f32)
Write a depth value at the given texel coordinates.
Sourcepub fn read_depth(&self, x: u32, y: u32) -> f32
pub fn read_depth(&self, x: u32, y: u32) -> f32
Read the depth at the given texel coordinates.
Sourcepub fn sample_bilinear(&self, u: f32, v: f32) -> f32
pub fn sample_bilinear(&self, u: f32, v: f32) -> f32
Sample depth with bilinear filtering at normalized UV coordinates.
Sourcepub fn project_point(&self, world_pos: Vec3) -> (f32, f32, f32)
pub fn project_point(&self, world_pos: Vec3) -> (f32, f32, f32)
Project a world-space point into shadow map UV + depth.
Sourcepub fn is_in_shadow(&self, world_pos: Vec3, bias: f32) -> bool
pub fn is_in_shadow(&self, world_pos: Vec3, bias: f32) -> bool
Test if a world-space point is in shadow (simple depth comparison).
Sourcepub fn rasterize_triangle(&mut self, v0: Vec3, v1: Vec3, v2: Vec3)
pub fn rasterize_triangle(&mut self, v0: Vec3, v1: Vec3, v2: Vec3)
Rasterize a triangle into the shadow map depth buffer.
Sourcepub fn texel_count(&self) -> usize
pub fn texel_count(&self) -> usize
Get the total number of texels.
Sourcepub fn memory_bytes(&self) -> usize
pub fn memory_bytes(&self) -> usize
Get memory usage in bytes (approximate).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ShadowMap
impl RefUnwindSafe for ShadowMap
impl Send for ShadowMap
impl Sync for ShadowMap
impl Unpin for ShadowMap
impl UnsafeUnpin for ShadowMap
impl UnwindSafe for ShadowMap
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.