-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adds LightOccluder2d component * Adds SDF Pass * Use fixed size uniform buffer in WebGL2 Dynamic arrays aren't supported in WebGL2, so we have to fall back to a fixed size array in a uniform binding. Co-Authored-By: Miguel Albernaz <[email protected]> * Almost setup ray marching? :) Co-Authored-By: Miguel Albernaz <[email protected]> * Kill bevy_pbr PBR is for 3D stuff. It's nice to not need it. We'll want to clean up our view conversion definitions in the future. Co-Authored-By: Miguel Albernaz <[email protected]> * Add isolated light map pass The resulting texture isn't used yet, but it's being written to. Co-Authored-By: Miguel Albernaz <[email protected]> * Use light map Now we're using our light map, blended with our main texture. Co-Authored-By: Miguel Albernaz <[email protected]> * Fix ambient light Co-Authored-By: Miguel Albernaz <[email protected]> * Check occluder visibility Co-Authored-By: Miguel Albernaz <[email protected]> * Use separate node for SDF passo Not strictly necessary, but I do like having an explicit render graph, especially if it's something someone else ever wanted to tweak. Co-Authored-By: Miguel Albernaz <[email protected]> * Use enum for light occluder shapes This will allow us to sanely expand our API as we introduce more occluder shapes. Co-Authored-By: Miguel Albernaz <[email protected]> * Pull out light map node A refactor, again getting us to a world of a proper render graph. Co-Authored-By: Miguel Albernaz <[email protected]> * Move sdf shader to sdf module Co-Authored-By: Miguel Albernaz <[email protected]> * Use SDF specific component for texture Nice to split this one up, rather than all the textures living on one component. Co-Authored-By: Miguel Albernaz <[email protected]> * Add separate light map texture component Now we can completely isolate our light map and sdf textures. Co-Authored-By: Miguel Albernaz <[email protected]> * Hoist types shader This shader isn't specific to any one pipeline, so let's pull it up. Co-Authored-By: Miguel Albernaz <[email protected]> * Use shared shader types Co-Authored-By: Miguel Albernaz <[email protected]> * Remove lighting settings No blur yet. Will add this back later. Co-Authored-By: Miguel Albernaz <[email protected]> * Fix comment Co-Authored-By: Miguel Albernaz <[email protected]> * Pull view transformations to separate shader Co-Authored-By: Miguel Albernaz <[email protected]> * Add occluders to changelog Co-Authored-By: Miguel Albernaz <[email protected]> * Add light occlusion example Co-Authored-By: Miguel Albernaz <[email protected]> * Fix occluder field order These were wrong! * Add more occluders to occlusion example * Use texture sample level Missed this when porting things over. * Fix ambient light * Split up shape from light occluder This will allow us to encode more information into an occluder, such as information on how shadows should be cast. * Allow shadows to be toggled on a per light basis * Update docs * Remove future goals --------- Co-authored-by: Miguel Albernaz <[email protected]>
- Loading branch information
Showing
30 changed files
with
1,065 additions
and
208 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
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
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
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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use bevy::prelude::*; | ||
use bevy_light_2d::prelude::*; | ||
|
||
fn main() { | ||
App::new() | ||
.add_plugins((DefaultPlugins, Light2dPlugin)) | ||
.add_systems(Startup, setup) | ||
.add_systems(Update, move_lights) | ||
.run(); | ||
} | ||
|
||
fn setup(mut commands: Commands) { | ||
commands.spawn(Camera2dBundle::default()); | ||
|
||
commands.spawn(PointLight2dBundle { | ||
point_light: PointLight2d { | ||
intensity: 20.0, | ||
radius: 1000.0, | ||
falloff: 10.0, | ||
cast_shadows: true, | ||
..default() | ||
}, | ||
transform: Transform { | ||
translation: Vec3::new(0.0, 100.0, 0.0), | ||
..default() | ||
}, | ||
..default() | ||
}); | ||
|
||
commands.spawn(LightOccluder2dBundle { | ||
light_occluder: LightOccluder2d { | ||
shape: LightOccluder2dShape::Rectangle { | ||
half_size: Vec2::splat(25.0), | ||
}, | ||
}, | ||
transform: Transform::from_xyz(-400.0, -50.0, 0.0), | ||
..default() | ||
}); | ||
|
||
commands.spawn(LightOccluder2dBundle { | ||
light_occluder: LightOccluder2d { | ||
shape: LightOccluder2dShape::Rectangle { | ||
half_size: Vec2::splat(25.0), | ||
}, | ||
}, | ||
transform: Transform::from_xyz(-200.0, -50.0, 0.0), | ||
..default() | ||
}); | ||
|
||
commands.spawn(LightOccluder2dBundle { | ||
light_occluder: LightOccluder2d { | ||
shape: LightOccluder2dShape::Rectangle { | ||
half_size: Vec2::splat(25.0), | ||
}, | ||
}, | ||
transform: Transform::from_xyz(0.0, -50.0, 0.0), | ||
..default() | ||
}); | ||
|
||
commands.spawn(LightOccluder2dBundle { | ||
light_occluder: LightOccluder2d { | ||
shape: LightOccluder2dShape::Rectangle { | ||
half_size: Vec2::splat(25.0), | ||
}, | ||
}, | ||
transform: Transform::from_xyz(200.0, -50.0, 0.0), | ||
..default() | ||
}); | ||
|
||
commands.spawn(LightOccluder2dBundle { | ||
light_occluder: LightOccluder2d { | ||
shape: LightOccluder2dShape::Rectangle { | ||
half_size: Vec2::splat(25.0), | ||
}, | ||
}, | ||
transform: Transform::from_xyz(400.0, -50.0, 0.0), | ||
..default() | ||
}); | ||
} | ||
|
||
fn move_lights(mut query: Query<&mut Transform, With<PointLight2d>>, time: Res<Time>) { | ||
for mut light_transform in &mut query { | ||
light_transform.translation.x = time.elapsed_seconds().sin() * 500. | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//! A module which contains occluder components. | ||
use bevy::{ | ||
ecs::{bundle::Bundle, component::Component}, | ||
math::Vec2, | ||
render::view::{InheritedVisibility, ViewVisibility, Visibility}, | ||
transform::components::{GlobalTransform, Transform}, | ||
}; | ||
|
||
/// A light occluder that prevents light passing through it, casting shadows. | ||
/// | ||
/// This is commonly used as a component within [`LightOcluder2dBundle`]. | ||
#[derive(Default, Component)] | ||
pub struct LightOccluder2d { | ||
/// The shape of the light occluder. | ||
pub shape: LightOccluder2dShape, | ||
} | ||
|
||
/// Shape data for a light occluder. | ||
pub enum LightOccluder2dShape { | ||
/// A rectangular light occluder. | ||
Rectangle { | ||
/// Half of the width and height of the rectangle. | ||
half_size: Vec2, | ||
}, | ||
} | ||
|
||
impl Default for LightOccluder2dShape { | ||
fn default() -> Self { | ||
Self::Rectangle { | ||
half_size: Vec2::splat(0.0), | ||
} | ||
} | ||
} | ||
|
||
/// A bundle of components for rendering a [`LightOccluder2d`] entity. | ||
#[derive(Bundle, Default)] | ||
pub struct LightOccluder2dBundle { | ||
/// Specifies the rendering properties of the light occluder | ||
pub light_occluder: LightOccluder2d, | ||
/// The local transform of the light occluder, relative to its parent. | ||
pub transform: Transform, | ||
/// The absolute transform of the light occluder. This should generally not be written to directly. | ||
pub global_transform: GlobalTransform, | ||
/// User indication of whether an entity is visible. | ||
pub visibility: Visibility, | ||
/// Inherited visibility of an entity. | ||
pub inherited_visibility: InheritedVisibility, | ||
/// Algorithmically-computed indication of whether an entity is visible and should be extracted for rendering. | ||
pub view_visibility: ViewVisibility, | ||
} |
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.