zaycev / bevy-magic-light-2d Goto Github PK
View Code? Open in Web Editor NEWExperiment with computing 2D shading, lighting and shadows with Bevy Engine
License: Apache License 2.0
Experiment with computing 2D shading, lighting and shadows with Bevy Engine
License: Apache License 2.0
https://blog.demofox.org/2016/03/02/actually-making-signed-distance-field-textures-with-jfa/
This change will enable better flexibility and performance.
Looks like PR#28 causes rendering to break on my laptop
AdapterInfo { name: "NVIDIA GeForce RTX 3080 Ti Laptop GPU", vendor: 4318, device: 9248, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "517.40", backend: Vulkan }
SystemInfo { os: "Windows 11 Pro", kernel: "22621", cpu: "12th Gen Intel(R) Core(TM) i9-12900H", core_count: "14", memory: "31.7 GiB" }
In running cargo run --example krypta
, I get
thread 'main' panicked at 'Failed to initialize any backend! Wayland status: NoCompositorListening X11 status: "backend disabled"', /home/brettw/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.27.5/src/platform_impl/linux/mod.rs:719:9
I reckon that if the following queries used GlobalTransform
then we could have lights and occluders as children of entities whose transform is changing:
pub fn system_extract_pipeline_assets(
res_light_settings: Extract<Res<BevyMagicLight2DSettings>>,
res_target_sizes: Extract<Res<ComputedTargetSizes>>,
query_lights: Extract<Query<(&Transform, &OmniLightSource2D, &InheritedVisibility, &ViewVisibility)>>,
query_occluders: Extract<Query<(&LightOccluder2D, &Transform, &InheritedVisibility, &ViewVisibility)>>,
query_camera: Extract<Query<(&Camera, &GlobalTransform), With<FloorCamera>>>,
query_masks: Extract<Query<(&Transform, &SkylightMask2D)>>,
query_skylight_light: Extract<Query<&SkylightLight2D>>,
mut gpu_target_sizes: ResMut<ComputedTargetSizes>,
mut gpu_pipeline_assets: ResMut<LightPassPipelineAssets>,
mut gpu_frame_counter: Local<i32>,
)
Am I missing something?
The current system implementation does not contain suck type of materials as an emissive. The purpose of this issue is to add support for such materials
This would make it easier if some of this is going to be contributed back into bevy itself at some point.
Thanks for sharing the repo!
I get the impression the light occluder is just a rectangle? We should be able to rotate it.
It would be amazing if there was a way to use normal maps for sprites and atlas sprites
We should support some more basic shapes. This issue is for a circle.
This will really mess up a lot of standard bevy practices.
I spent a few hours on this but I am very new to shader programming and vfx in general, ended up getting stuck trying to figure out why this happens.
The screenshots show what i'm seeing here, but basically, there's a darkening that happens at around 400px into the camera from right to left and 24x top to bottom.
Any idea why this is the case? Is it an intentional effect?
You can also see this issue on the movement
example:
both an omni source and skylight:
just the skylight:
just the omni source:
Is it possible to add a categoryBitMask
to define what gets lit up and not?
This would help to prevent light leaving an enclosed room.
So a light component would define the mask and the surrounding sprites would update their masks to match.
To determine whether this sprite is lit by a light node, the sprite’s lightingBitMask property is tested against the light’s
categoryBitMask]
property by performing a logical AND operation. If the comparison results in a nonzero value, the sprite is lit by this light.
They also have shadowedBitMask
and shadowCastBitMask
:
This feature is supported by SpriteKit by Apple.
SpriteKit
We might be able to do this by simply adding together many rectangular polygons.
Hi, I like this project, its exactly what i've been searching for.
But it seems that ocluders ignore parent transformations.
Attaching a Rapier collider as children works jsut fine, they share the parents transformation, augmenting its own.
But the LightOccluder2D just doesnt seem to like it. To make it work, I had to get the current translation using query, and then set the SpatialBundle transform to the values of the parent.
Could that be a bug? Iam still learning my way around bevy, but it seems like the parents transformation should be applied to child as well.
Many thanks.
MK
The parent:
pub struct MapBundle {
pub tiled_map: Handle<TiledMap>, // tiled
pub storage: LayersStorage, // tiled
pub visibility: Visibility, // bevy
pub computed_visibility: ComputedVisibility, //bevy
pub transform: Transform, // bevy
pub global_transform: GlobalTransform, //bevy
pub module: MapModule, // my stuff
}
And my simplified functions for attaching a coliders to the MapBundle entity using my calculated collider rectangle as input.
// rapier
let id = world.spawn(Collider::cuboid(rect.half_size().x, rect.half_size().y))
.insert(TransformBundle::from(Transform::from_xyz(
rect.center().x,
rect.center().y,
2.
)))
.id();
world.entity_mut(map_id).add_child(id);
let t = world.entity(map_id).get::<Transform>().unwrap().translation; // the modification I had to do
// ocluders
let id = world.spawn(LightOccluder2D {h_size: rect.half_size()})
.insert(SpatialBundle::from_transform(Transform::from_xyz( // I had to use Spatial bundle, since simple transform bundle didnt work
rect.center().x + t.x,
rect.center().y + t.y,
2. + t.z
)))
.id();
world.entity_mut(map_id).add_child(id);
bevy-magic-light-2d/src/gi/mod.rs
Lines 50 to 58 in a52717f
https://discord.com/channels/691052431525675048/1054987696885473411/1056382176553353316
Thanks for the update! I noticed that it won't compile in my project without bevy_pbr
feature enabled in Cargo.toml:
2 | use bevy::pbr::{MAX_CASCADES_PER_LIGHT, MAX_DIRECTIONAL_LIGHTS};
| ^^^ could not find `pbr` in `bevy`
It is strange, because krypta
example working without any issues..
and if someone uses bevy/dynamic_linking, crate-type = ["cdylib", "lib", "staticlib"]
line in Cargo.toml causes this:
error: crate `bevy_dylib` required to be available in rlib format, but was not found in this form
Hi!
While zooming scene out the screen is being "split" into a "grid" and around each "grid cell" I observe black areas. The more I zoom out the larger black areas become.
Any ideas how to fix this?
Details provided below:
Here it is illustrated in krypta
demo app (I added zoom to fork main...morr:bevy-magic-light-2d:zoom-out-issue)
And this is how the issue looks in my bevy app where I try very large zoom.
For my game I need to know approximately how much light a light Occluder is receiving. Maybe a less accurate CPU bound process could accompany the GPU raymarch algorithm to provide this.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.