diff --git a/Makefile b/Makefile index 206cdb9..5f3bbbb 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,17 @@ # EXAMPLE=animated_shapes # EXAMPLE=animated_text -EXAMPLE=custom_fonts -# EXAMPLE=sprite -# EXAMPLE=text +# EXAMPLE=custom_fonts +# EXAMPLE=ecs_sprite +# EXAMPLE=ecs_topdown_game +# EXAMPLE=music +EXAMPLE=lighting # EXAMPLE=particles +# EXAMPLE=particle_systems # EXAMPLE=post_processing +# EXAMPLE=sprite # EXAMPLE=shapes # EXAMPLE=sound -# EXAMPLE=music -# EXAMPLE=ecs_sprite -# EXAMPLE=ecs_topdown_game -# EXAMPLE=particle_systems +# EXAMPLE=text # default: build-examples # default: wasm-build diff --git a/README.md b/README.md index 0574cbe..8fe7b86 100644 --- a/README.md +++ b/README.md @@ -252,6 +252,8 @@ The following goals are not in any particular order, but should come reasonably soon. Comfy is not an aetheral project that will only materialize in 2 years. Only features that require maximum few weeks of work are listed here. +- Improved lighting. Right now we do have 2d lights, but they're basic, + ugly in some scenarios, and not very flexible. - Configurable bloom. Currently bloom is hard-coded to simplify a few things and always enabled. We don't want to delay the release to fix this since it does make games look better by default, but it is one of the first few things @@ -343,7 +345,7 @@ comfy is free and open source and dual licensed under MIT and Apache 2.0 license - [x] simple particles - [ ] lighting example - [ ] combat text example -- [ ] font loading +- [x] font loading - [x] particle systems - [x] text - [ ] blood canvas diff --git a/comfy-core/src/lighting.rs b/comfy-core/src/lighting.rs index 31017df..9457cc7 100644 --- a/comfy-core/src/lighting.rs +++ b/comfy-core/src/lighting.rs @@ -18,7 +18,7 @@ impl LightingState { } } -pub fn add_light(light: Light) { +pub fn draw_light(light: Light) { LIGHTS.borrow_mut().lights.push(light); } diff --git a/comfy/examples/lighting.rs b/comfy/examples/lighting.rs new file mode 100644 index 0000000..770f625 --- /dev/null +++ b/comfy/examples/lighting.rs @@ -0,0 +1,30 @@ +use comfy::*; + +simple_game!("Lighting Example", setup, update); + +fn setup(c: &mut EngineContext) { + c.load_texture_from_bytes( + // Every texture gets a string name later used to reference it. + "comfy", + include_bytes!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/../assets/comfy.png" + )), + wgpu::AddressMode::ClampToEdge, + ); + + c.lighting.ambient_light_intensity = 0.1; +} + +fn update(_c: &mut EngineContext) { + draw_rect(Vec2::ZERO, splat(40.0), DARKRED, 0); + draw_sprite(texture_id("comfy"), Vec2::ZERO, WHITE, 1, splat(5.0)); + + let t = get_time() as f32; + + let t1 = t * 2.0; + let pos = 3.0 * vec2(t1.cos(), t1.sin()); + + draw_light(Light::simple(pos, 2.0, 2.0)); + draw_light(Light::simple(vec2(3.0, 0.0), 8.0, 0.5)); +} diff --git a/comfy/src/context.rs b/comfy/src/context.rs index dc20c32..e2c86d9 100644 --- a/comfy/src/context.rs +++ b/comfy/src/context.rs @@ -43,6 +43,7 @@ pub struct EngineContext<'a> { pub dt_stats: &'a mut MovingStats, pub fps_stats: &'a mut MovingStats, + pub lighting: &'a mut GlobalLightingParams, pub meta: &'a mut AnyMap, diff --git a/comfy/src/engine.rs b/comfy/src/engine.rs index 589b0b2..381d459 100644 --- a/comfy/src/engine.rs +++ b/comfy/src/engine.rs @@ -590,7 +590,7 @@ impl EngineState { for (_, (transform, light)) in c.world_mut().query_mut::<(&Transform, &PointLight)>() { - add_light(Light::simple( + draw_light(Light::simple( transform.position, light.radius * light.radius_mod, light.strength * light.strength_mod, @@ -992,6 +992,7 @@ impl EngineState { mouse_world: mouse_world(), flags: &self.flags, + lighting: &mut self.lighting, meta: &mut self.meta,