-
Notifications
You must be signed in to change notification settings - Fork 6
Lights #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Lights #67
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
55f0741
Light Example
catilac 0783556
Directional, Point, and Spot Lights
catilac 473840c
Use bevy::color::Color as an argument to lighting methods
catilac d2f9935
set MaterialKey unlit = false
catilac b62b456
Make light create accept a geometry entity to grab render layers.
tychedelia 6eac1ec
All lights working in lights example
catilac 8a3e3d2
remove positional arguments in favor of using transform_set_position
catilac 6d7874e
example with all lights
catilac 064e5c2
ffi methods
catilac 7c5ac5c
Update crates/processing_render/src/render/material.rs
tychedelia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,86 @@ | ||
| //! A light in Processing | ||
| //! | ||
|
|
||
| use bevy::{camera::visibility::RenderLayers, prelude::*}; | ||
|
|
||
| use crate::{error::ProcessingError, graphics::Graphics}; | ||
|
|
||
| pub struct LightPlugin; | ||
|
|
||
| impl Plugin for LightPlugin { | ||
| fn build(&self, _app: &mut App) {} | ||
| } | ||
|
|
||
| pub fn create_directional( | ||
| In((entity, color, illuminance)): In<(Entity, Color, f32)>, | ||
| mut commands: Commands, | ||
| graphics: Query<&RenderLayers, With<Graphics>>, | ||
| ) -> Result<Entity, ProcessingError> { | ||
| let layer = graphics | ||
| .get(entity) | ||
| .map_err(|_| ProcessingError::GraphicsNotFound)?; | ||
| Ok(commands | ||
| .spawn(( | ||
| DirectionalLight { | ||
| illuminance, | ||
| color, | ||
| ..default() | ||
| }, | ||
| layer.clone(), | ||
| )) | ||
| .id()) | ||
| } | ||
|
|
||
| pub fn create_point( | ||
| In((entity, color, intensity, range, radius)): In<(Entity, Color, f32, f32, f32)>, | ||
| mut commands: Commands, | ||
| graphics: Query<&RenderLayers, With<Graphics>>, | ||
| ) -> Result<Entity, ProcessingError> { | ||
| let layer = graphics | ||
| .get(entity) | ||
| .map_err(|_| ProcessingError::GraphicsNotFound)?; | ||
| Ok(commands | ||
| .spawn(( | ||
| PointLight { | ||
| intensity, | ||
| color, | ||
| range, | ||
| radius, | ||
| ..default() | ||
| }, | ||
| layer.clone(), | ||
| )) | ||
| .id()) | ||
| } | ||
|
|
||
| pub fn create_spot( | ||
| In((entity, color, intensity, range, radius, inner_angle, outer_angle)): In<( | ||
| Entity, | ||
| Color, | ||
| f32, | ||
| f32, | ||
| f32, | ||
| f32, | ||
| f32, | ||
| )>, | ||
| mut commands: Commands, | ||
| graphics: Query<&RenderLayers, With<Graphics>>, | ||
| ) -> Result<Entity, ProcessingError> { | ||
| let layer = graphics | ||
| .get(entity) | ||
| .map_err(|_| ProcessingError::GraphicsNotFound)?; | ||
| Ok(commands | ||
| .spawn(( | ||
| SpotLight { | ||
| color, | ||
| intensity, | ||
| range, | ||
| radius, | ||
| inner_angle, | ||
| outer_angle, | ||
| ..default() | ||
| }, | ||
| layer.clone(), | ||
| )) | ||
| .id()) | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,98 @@ | ||
| mod glfw; | ||
|
|
||
| use glfw::GlfwContext; | ||
| use processing::prelude::*; | ||
| use processing_render::render::command::DrawCommand; | ||
|
|
||
| fn main() { | ||
| match sketch() { | ||
| Ok(_) => { | ||
| eprintln!("Sketch completed successfully"); | ||
| exit(0).unwrap(); | ||
| } | ||
| Err(e) => { | ||
| eprintln!("Sketch error: {:?}", e); | ||
| exit(1).unwrap(); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| fn sketch() -> error::Result<()> { | ||
| let mut glfw_ctx = GlfwContext::new(400, 400)?; | ||
| init(Config::default())?; | ||
|
|
||
| let width = 400; | ||
| let height = 400; | ||
| let scale_factor = 1.0; | ||
|
|
||
| let surface = glfw_ctx.create_surface(width, height, scale_factor)?; | ||
| let graphics = graphics_create(surface, width, height)?; | ||
| let box_geo = geometry_box(100.0, 100.0, 100.0)?; | ||
|
|
||
| // We will only declare lights in `setup` | ||
| // rather than calling some sort of `light()` method inside of `draw` | ||
|
|
||
| // create a directional light | ||
| let _dir_light = | ||
| light_create_directional(graphics, bevy::color::Color::srgb(0.35, 0.25, 0.5), 500.0)?; | ||
|
|
||
| // create a point light | ||
| let point_light_a = light_create_point( | ||
| graphics, | ||
| bevy::color::Color::srgb(1.0, 0.5, 0.25), | ||
| 1_000_000.0, | ||
| 200.0, | ||
| 0.5, | ||
| )?; | ||
| transform_set_position(point_light_a, -25.0, 5.0, 51.0)?; | ||
| transform_look_at(point_light_a, 0.0, 0.0, 0.0)?; | ||
|
|
||
| // create another point light | ||
| let point_light_b = light_create_point( | ||
| graphics, | ||
| bevy::color::Color::srgb(0.0, 0.5, 0.75), | ||
| 2_000_000.0, | ||
| 200.0, | ||
| 0.25, | ||
| )?; | ||
| transform_set_position(point_light_b, 0.0, 5.0, 50.5)?; | ||
| transform_look_at(point_light_b, 0.0, 0.0, 0.0)?; | ||
|
|
||
| // and a spot light, too! | ||
| let spot_light = light_create_spot( | ||
| graphics, | ||
| bevy::color::Color::srgb(0.25, 0.8, 0.19), | ||
| 15.0 * 1_000_000.0, | ||
| 200.0, | ||
| 0.84, | ||
| 0.0, | ||
| core::f32::consts::FRAC_PI_4, | ||
| )?; | ||
| transform_set_position(spot_light, 40.0, 0.0, 70.0)?; | ||
| transform_look_at(spot_light, 0.0, 0.0, 0.0)?; | ||
|
|
||
| graphics_mode_3d(graphics)?; | ||
| transform_set_position(graphics, 100.0, 100.0, 300.0)?; | ||
| transform_look_at(graphics, 0.0, 0.0, 0.0)?; | ||
|
|
||
| let mut angle = 0.0; | ||
|
|
||
| while glfw_ctx.poll_events() { | ||
| graphics_begin_draw(graphics)?; | ||
|
|
||
| graphics_record_command( | ||
| graphics, | ||
| DrawCommand::BackgroundColor(bevy::color::Color::srgb(0.18, 0.20, 0.15)), | ||
| )?; | ||
|
|
||
| graphics_record_command(graphics, DrawCommand::PushMatrix)?; | ||
| graphics_record_command(graphics, DrawCommand::Rotate { angle })?; | ||
| graphics_record_command(graphics, DrawCommand::Geometry(box_geo))?; | ||
| graphics_record_command(graphics, DrawCommand::PopMatrix)?; | ||
|
|
||
| graphics_end_draw(graphics)?; | ||
|
|
||
| angle += 0.02; | ||
| } | ||
| Ok(()) | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.