-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
Selective lighting #5180
Comments
What I am saying is basically having a Or maybe it could be added not to the Mesh itself, but to separate faces of the mesh geometry. |
Sounds like you want to use shadows? |
Well, I could achieve something like that with shadows (and I've already tried), but it gives different side effects and I feel that it is a hack, because I don't need to light some objects and then cast shadow on them. I must not light them in the first place. What I need is that a specific light source doesn't affect one set of meshes, but affects the other set. Usually I do this using a technique like that: Example discussion thread:
So it looks like a different feature than just shadows. Or am I missing something? |
Yes... I think this can indeed be handy. Not sure how the API for it should look like though. |
Maybe the most simple solution could be the most effective here:
What do you think? |
Maybe the 'affectedByLightChannel' is too long and something like 'lightChannel' would do, but I think it would be convenient: just channel numbers on light source and receivers. Like that:
|
If So it would be fully backward compatible with current behavior. |
That may be a bit too hard to understand... Maybe it's better something like this: cube.lightInfluences = [ light1, light2 ]; |
Seems absolutely fine to me. Maybe it is a bit more difficult to use in some cases, but it is easier to understand, obviously. |
What about a simple integer mask property for meshes and lights?
Objects are then only lit by lights if the logical AND of their masks is non- zero. A mask default of 0xffffffff would not affect existing code. |
What @satori99 said. Although, I think Also, the property could alternatively be named |
The problem of the channel/mask approach is that the user will need to understand bitwise operations. A bit too intense if you compare it to the rest of the API. What's something you can do with masks that you can't do with the array approach? |
I could give an example from the task with two rooms above. The main point of using the channel approach over the array approach is that simple operations like 'move light1 from room 1 to room 2' become more complicated if you use arrays. Instead of just setting
(previously it was set to 1) you would have to find all objects in room 1 that had light1 in lightInfluences array previously, then remove the light from their arrays, then add it to all objects in the room 2. Same story with the simple operation like 'move object 1 from room 1 to room 2'. Instead of setting its influenceChannel from 1 to 2, you would need to find all the lights in that room, then remove them from its influence array, then find all lights in room two and add them. It's not that it can't be done, that's why I said that the lightInfluences approach is absolutely fine to me. But the channel stuff would be the first thing that I would implement above it for myself just to make common operations as simple as 1 assignment. |
I think it should be implemented as a mask. (Whether is it implemented on the CPU or GPU is an issue for later discussion.) We can show via examples how to set it, and users can follow the pattern. If you think that is still too complicated, then we can create a
Same methods for |
I like that API :) |
Only materials respond to lights. This would have to be a property of the material, I would think. |
I agree on this with @WestLangley. Lights are dependent on materials. |
Well, that's a problem. |
But why? Is it a technical limitation? Because it kind of invalidates the whole idea of all that. Because there can be different objects, which reuse the same material, but one of them should be lit and the other -- shouldn't. |
No. It is because objects do not respond to lights. Only materials do.
You can use the same material for all objects in the scene -- just |
Can this be handled somewhat easily in the GPU directly? |
Yes, you would need to pass in the additional |
How about a layer management system? I'd group the meshes into layers and apply the masks from there (could affect lights, shadows, visibility, etc), unity would be a good example? |
Shadows is also a related topic. I think there should also be something like selective shadow casting. Like 'receiveShadowFrom = ...' (and list of sources) instead of just 'receiveShadow = true'. Because when you set lights that only affect a specific room (in my example), you would also immediately want those lights to cast shadows only on this room objects. |
Shadows attributes should really be on the materials and not the objects for the same reasons as above in this thread. |
Yes, it makes sense! |
Are there any plans for including this feature (like a planned target release for the first draft)? |
@ErikBehar a PR would be great! |
@tiesselune I'll look into moving it as you suggest, or feel free to push a PR on my fork lol = ] and I'll post the PR soon @mrdoob |
What's the status on this? I've merged the r94dev code from @ErikBehar into r94, then merged r97 into it, only a couple very straightforward conflicts (version change, a few variables for selective lighting, and the hash creation in renderers/WebGLRenderer.js; I'd be happy to put in a PR. @tiesselune if you can give me some idea where you intended the selective lighting state to go, I'd be happy to move it, test, and put in a PR. EDIT: |
@VaelynPhi I'd think that, regardless of whether they are willing to accept @ErikBehar 's code or not, it is good idea to submit the PR, just to replace the outdated one in case other people will want it, like you yourself did |
Sorry to drop the ball on this guys = / ... @VaelynPhi can you post your fork / branch ? |
No worries; I understand being busy. Alas, I couldn't get even the branch you had working, @ErikBehar; I settled on reading through the code to try and break it down so I could move the state to the appropriate location and hopefully fix any bugs. I have yet to get to a working port state even on v94. Perhaps I can clean it up and put in the PR just to update it as @makc suggests. Give me a bit; I'm super busy. :) At the very least maybe that'll help highlight the changes that need to be made to pull selective lighting into the recent version. |
added a PR based on: |
Hey guys, what's the status on this one? @tiesselune @ErikBehar Might I help you with something? Would be nice to implement it finally after 4 years 😄💯 |
This comment was marked as abuse.
This comment was marked as abuse.
@ttiimmaacc it is pretty much "nice to have, but please just use multiple scenes instead" |
@makc while using multiple scenes, without setting any background it works fine. But once I change the Background it does not, do you have any idea? |
@adityakailash0399 Idk, have an empty scene with the background set render before all the others, maybe |
Hi, I also checking on the selective light feature for baked / dynamic light system , by mistake I thought it was supported on three js layer, but layers is only camera <> object filter and not light <> object <> camera. |
+1 on the need for selective lighting. This would also enable cool stuff via Spotlight texture projection (similarly to how the shadow projector works in Unity). For example, you could render your character top-down into a render texture, paint it black and project that onto to the environment to have a dynamic character shadow, while keeping |
three.js.examples.-.Google.Chrome.2024-06-12.20-47-08.mp4Just got this working for Point Lights. Going to make a draft PR shortly. Works by adding uniforms and testing the light mask vs the object mask in shader. |
Some issues: satellites are not really clear in the night: I cannot add an ambient light because of this: mrdoob/three.js#5180
Selective lighting is supported in
|
I'm not sure whether this is already a planned feature or maybe even a finished one, so I'll try to explain the task first.
I need to do selective lighting for different rooms. For example, I have two rooms. One light must only affect objects and inner walls of one room. The second room must not be affected by this light.
Currently, if I add a light to the scene, it affects all objects in its distance. And I get strange effect when light comes "through the wall" of the second room.
So I think I need some kind of groups or channels for lighting, so that I could set the objects that are affected by one light source and objects that are affected by another.
I haven't found anything like that in either lights or objects, so I thought that maybe it could be a good feature to have.
And, btw, if it is not implemented yet, what is the recommended approach to solve such tasks using current state of three.js?
The text was updated successfully, but these errors were encountered: