Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
Add lighting example
Browse files Browse the repository at this point in the history
  • Loading branch information
darthdeus committed Sep 23, 2023
1 parent 28ed87a commit 0c5bd21
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 10 deletions.
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion comfy-core/src/lighting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl LightingState {
}
}

pub fn add_light(light: Light) {
pub fn draw_light(light: Light) {
LIGHTS.borrow_mut().lights.push(light);
}

Expand Down
30 changes: 30 additions & 0 deletions comfy/examples/lighting.rs
Original file line number Diff line number Diff line change
@@ -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));
}
1 change: 1 addition & 0 deletions comfy/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
3 changes: 2 additions & 1 deletion comfy/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -992,6 +992,7 @@ impl EngineState {
mouse_world: mouse_world(),

flags: &self.flags,
lighting: &mut self.lighting,

meta: &mut self.meta,

Expand Down

0 comments on commit 0c5bd21

Please sign in to comment.