-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some thoughts for a 2d lighting pipeline
- Loading branch information
1 parent
d90fe7d
commit 4b9aa9e
Showing
6 changed files
with
123 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,72 @@ | ||
use common::{Camera, Color, Vec2}; | ||
use common::{vec3, Camera, Color, Vec2, Vec3, AABB}; | ||
|
||
use crate::{RenderFrame, RenderPass, RenderScene, RenderTarget}; | ||
use crate::{ | ||
CullableObject, ObjectBounds, RenderFrame, RenderPass, RenderScene, RenderTarget, RenderTargetDescriptor, | ||
RenderTextureDescriptor, TargetError, TextureFormat, TextureOptions, | ||
}; | ||
|
||
/// A point light in 2 space. | ||
pub struct PointLight { | ||
pub position: Vec2, | ||
pub color: Color, | ||
pub intensity: f32, | ||
pub radius: f32, | ||
/// A light in 2 space. | ||
pub enum Light { | ||
PointLight { | ||
position: Vec2, | ||
color: Color, | ||
intensity: f32, | ||
radius: f32, | ||
}, | ||
} | ||
|
||
/// A render pass that renders all lights in the scene. | ||
pub struct LightPass { | ||
pub lights: Vec<PointLight>, | ||
cascade_1: RenderTarget, | ||
cascade_2: RenderTarget, | ||
cascade_3: RenderTarget, | ||
cascade_4: RenderTarget, | ||
} | ||
|
||
impl LightPass { | ||
/// Creates a new light pass. | ||
pub fn new() -> Result<Self, TargetError> { | ||
let base_descriptor = RenderTargetDescriptor { | ||
color_attachment: RenderTextureDescriptor { | ||
width: 1920, | ||
height: 1080, | ||
options: TextureOptions { | ||
format: TextureFormat::RGBA8, | ||
..Default::default() | ||
}, | ||
}, | ||
depth_attachment: None, | ||
stencil_attachment: None, | ||
}; | ||
|
||
lighting_cascade_1: RenderTarget, | ||
lighting_cascade_2: RenderTarget, | ||
lighting_cascade_3: RenderTarget, | ||
Ok(Self { | ||
cascade_1: RenderTarget::new(&base_descriptor.with_size(1024, 1024))?, | ||
cascade_2: RenderTarget::new(&base_descriptor.with_size(512, 512))?, | ||
cascade_3: RenderTarget::new(&base_descriptor.with_size(256, 256))?, | ||
cascade_4: RenderTarget::new(&base_descriptor.with_size(128, 128))?, | ||
}) | ||
} | ||
} | ||
|
||
impl RenderPass for LightPass { | ||
fn begin_frame(&self, scene: &dyn RenderScene, frame: &mut RenderFrame<'_>) { | ||
todo!() | ||
fn render_camera(&self, scene: &dyn RenderScene, camera: &dyn Camera, frame: &mut RenderFrame<'_>) { | ||
let frustum = camera.frustum(); | ||
|
||
// TODO: render lights | ||
} | ||
} | ||
|
||
fn render_camera(&self, scene: &dyn RenderScene, camera: &dyn Camera, frame: &mut RenderFrame<'_>) { | ||
todo!() | ||
impl CullableObject for Light { | ||
fn compute_bounds(&self) -> ObjectBounds { | ||
match self { | ||
Light::PointLight { position, radius, .. } => { | ||
let position = vec3(position.x, 0.0, position.y); | ||
|
||
let min = position - Vec3::splat(*radius); | ||
let max = position + Vec3::splat(*radius); | ||
|
||
ObjectBounds::AABB(AABB::from_min_max(min, max)) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.