Skip to content
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

Lights don't respect RenderLayer #3462

Closed
HackerFoo opened this issue Dec 28, 2021 · 3 comments · Fixed by #10742
Closed

Lights don't respect RenderLayer #3462

HackerFoo opened this issue Dec 28, 2021 · 3 comments · Fixed by #10742
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior

Comments

@HackerFoo
Copy link
Contributor

What problem does this solve or what need does it fill?

From manko on Discord: "by the way, is there a way to make light sources not affect some meshes? I'm noticed RenderLayers does not affect light sources and the lights are shared between my worlds, which is mildly annoying"

Also encountered in #3412

What solution would you like?

RenderLayers control visibility of lights as they do for other entities.

@HackerFoo HackerFoo added C-Feature A new feature, making something new possible S-Needs-Triage This issue needs to be labelled labels Dec 28, 2021
@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior and removed C-Feature A new feature, making something new possible S-Needs-Triage This issue needs to be labelled labels Dec 28, 2021
@dcz-self
Copy link

I reported this, for the record. Tested on 0.5.0, and with 80% certainty that I didn't mess up anything.

@asafigan
Copy link
Contributor

asafigan commented Sep 1, 2022

I ran into this issue when working on my Bevy Jam 2 submission. I would be willing to work on this but I would probably need help because I have only done some basics graphic programming mostly in OpenGL.

@alice-i-cecile
Copy link
Member

Checking in just before the launch of Bevy 0.10; this is still an issue.

github-merge-queue bot pushed a commit that referenced this issue Dec 12, 2023
# Objective

add `RenderLayers` awareness to lights. lights default to
`RenderLayers::layer(0)`, and must intersect the camera entity's
`RenderLayers` in order to affect the camera's output.

note that lights already use renderlayers to filter meshes for shadow
casting. this adds filtering lights per view based on intersection of
camera layers and light layers.

fixes #3462 

## Solution

PointLights and SpotLights are assigned to individual views in
`assign_lights_to_clusters`, so we simply cull the lights which don't
match the view layers in that function.

DirectionalLights are global, so we 
- add the light layers to the `DirectionalLight` struct
- add the view layers to the `ViewUniform` struct
- check for intersection before processing the light in
`apply_pbr_lighting`

potential issue: when mesh/light layers are smaller than the view layers
weird results can occur. e.g:
camera = layers 1+2
light = layers 1
mesh = layers 2

the mesh does not cast shadows wrt the light as (1 & 2) == 0.
the light affects the view as (1+2 & 1) != 0. 
the view renders the mesh as (1+2 & 2) != 0.

so the mesh is rendered and lit, but does not cast a shadow. 

this could be fixed (so that the light would not affect the mesh in that
view) by adding the light layers to the point and spot light structs,
but i think the setup is pretty unusual, and space is at a premium in
those structs (adding 4 bytes more would reduce the webgl point+spot
light max count to 240 from 256).

I think typical usage is for cameras to have a single layer, and
meshes/lights to maybe have multiple layers to render to e.g. minimaps
as well as primary views.

if there is a good use case for the above setup and we should support
it, please let me know.

---

## Migration Guide

Lights no longer affect all `RenderLayers` by default, now like cameras
and meshes they default to `RenderLayers::layer(0)`. To recover the
previous behaviour and have all lights affect all views, add a
`RenderLayers::all()` component to the light entity.
rlidwka added a commit to rlidwka/bevy_egui that referenced this issue May 23, 2024
Issue bevyengine/bevy#3462 has been fixed. So since Bevy 0.13, render lights can be specified per RenderLayer.

I've decided to reuse the same light by specifying `RenderLayers::all()`, although adding a separate one (with preview_pass_layer and without) is also fine.
vladbat00 pushed a commit to vladbat00/bevy_egui that referenced this issue Jun 2, 2024
Issue bevyengine/bevy#3462 has been fixed. So since Bevy 0.13, render lights can be specified per RenderLayer.

I've decided to reuse the same light by specifying `RenderLayers::all()`, although adding a separate one (with preview_pass_layer and without) is also fine.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants