-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
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
Implement Projectors to support textured lighting #13057
Conversation
Adds a new light-type `ProjectorLight`. ProjectorLights are lights with an rectangular beam with arbitrary aspect and rotation that can be textured using a regular texture. Example: var projector = new THREE.ProjectorLight(0xffffff, 1); projector.fov = 20; // vertical FOV in degrees projector.aspect = 16 / 9; // texture aspect-ratio projector.map = new THREE.TextureLoader().load(textureUrl); scene.add(projector);
Looks interesting... |
An altered SpotLight is always useful. |
This is great! Bat-signal implemented with a grayscale RGB texture. One suggestion would be to attenuate the intensity with the alpha channel as well. vec4 texture = texture2D( projectorTexture, projectorUv );
directLight.color = projectorLight.color;
directLight.color *= texture.rgb;
directLight.color *= texture.a; // attenuate I also think support for texture |
@usefulthink Thanks a lot! Nice! I would aim into merging it as it is, and improve it on new pull requests! |
@WestLangley thinking out loud here, but shouldn't it be possible with relatively few changes to support both perspective and orthographic modes (i.e. Good point with the attenuation from alpha-channel, added that. |
This is a great addition. Would it be better to add a We could add a |
I prefer adding projective map property rather than adding a new light type if it works fine. |
I would keep these new lights as separate classes and separate from each other at first, and merge the feature set into existing lights later only if it makes sense. |
@WestLangley that sounds like a way to grow THREE.Legacy.js even faster. Is there a reason why it doesn't make sense now? We should agree on a final API before merging new features, rather than adding something that we intend to change later. |
I tend to vote for @WestLangley's suggestion. |
also added support for @looeee @takahirox I first tried implementing it as a parameter for the spotlight, but it turns out that it effectively results in mostly seperate code-paths and lots of complications within the shaders and in |
"if it works fine" I mentioned meant "I prefer map property approach if we can easily do", so that's ok if it's difficult. (I haven't read through the implementation yet). BTW, curious to know if similar project-light type exists in other engines, for example unity. |
As far as i know, Unity has no separate light types for this. One concept they use is Cookies. See https://www.youtube.com/watch?v=WERan6gjEn4 It's also possible to create similar effects with Projector, although this entity is focused on material/shadow projection. |
I searched through some of the docs:
So yes, all of them seem to implement it as part of the regular lights, and I think we could probably get there at some point. |
Thanks
👍 |
If we would enhance the basic light types, i would vote for the Cookies approach of Unity. This would only work grayscale textures but you could achieve the same effect like in @WestLangley's demo (with a |
@Mugen87 is that for performance reasons? Seems a shame to limit this to B&W if we can do full color and videos. |
From a conceptual point of view, it might be a good idea to treat such maps as pure shaped masks, like mentioned in the Unity docs. For shadow and material/texture projections (which can also be used to fake light effects) Unity uses a more general Projector class. I've worked a little bit with Unity in the past and i liked this separation. So it's just a personal preference 😊 . More information about Projectors: https://www.youtube.com/watch?v=44Nad3QwuoA& |
I was thinking of it more in terms of modelling of a physical process - that is, a light being partially or fully occluded while shining past / through objects in front of it. In the case of a real world projector, the occluding object is a semi-transparent LCD screen. Other examples are stained glass or a narrow window. Since unity cookies allow grayscale, they are not actually just cutouts and are modelling a limited version of this physical process. On the other hand, I presume that the reason cookies and projectors are separate in Unity is that cookies just multiply the light's intensity by the gray level of the cookie image, which is probably a cheap operation. |
This would be the best approach in my opinion. |
I like the It could support both perspective an orthographic frustums, and a color-map, cookie, or video. It would serve as an additional light source and cast shadows. A shortcoming may be the specular highlights generated by the projector. They may not be correct. As I said, I would keep it as a separate class and leave existing lights alone until this is sorted out. |
Just a little addition on Cookies. They are actually alpha maps but Unity offers an option to convert the luminosity expressed in a grayscale texture to alpha. If we ever add Cookies to |
Good points here, I did go with @WestLangley and removed the Regarding the specular highlights, I don't think I can solve that with my current knowledge of how the BSDFs work. I'm updating the IncidentLight with the color seen at the fragment, and to me the highlights look quite plausible, what am I missing? |
I'm not exactly sure what you are asking, but if it pertains to adding a Real projectors use lenses to emit nearly-parallel beams of light. Our spotlights and directional lights are modeled as such emitters.
|
What about adding SpotRectLight? Or adding a parameter to SpotLight to control the frustum shape? |
As I said before,this "projector" is an altered SpotLight and in my opinion the best approach would be to add a few more parameters for this light.
|
I have to disagree here. It completely depends on what kind of effect you're trying to achieve of course, but imagine having a "roster" in front of your lights, it would project the texture precisely as you'd expect without the need of using "real" shadows. I vote for adding the extra properties to the existing lights, as @RemusMar said. |
@haroldiedema An image added to a Sorry, I do not understand what you are trying to say. What do you mean by "roster", and what does it have to do with shadows? |
Oh my apologies, then I misinterpret the implementation of
I mean that with this, you can effectively fake shadows. |
Right. And that is a compelling reason for this PR. |
No no, I'm proposing creating a new type of light ( I think we're all suggesting the same. |
Why Rect if this is a Spot? |
🤔 |
@mrdoob I would like to focus the name more on the texturing than on the beam-shape, you can achieve any shape you want with it... What do think about Also, would you prefer a fully integrated approach (i.e. additional properties on |
Or maybe a "roundish" shadow frustum for a better SPOT. |
So in that case, I would propose implementing it like this (hopefully I can tackle that over the weekend):
I dind't think too much about other light-types yet (and will probably not implement them right away). |
I would highly recommend a simpler solution if you want to add a map property to You only need to add one property, Also, it is very important that the shadow frustum be separate from this frustum so we can still support tight, quality shadows.
If you want to propose that, please, please do it in a separate PR.
This seams to be an extra feature you are pushing for. I would omit it. Just add the map. Texture maps can be rotated now, which achieves the same effect.
I'm not sure about |
Square is also a better option for textures. |
@WestLangley I think we are thinking about different usage-scenarios. What would you think about adding a map-property to the SpotLight (working in a simplified way as you described) and keeping this class (renamed to whatever we decide on) for the full-fledged projector use-case?
A square frustum with the normal round beam would be the default, but I wouldn't want to stop there as it doesn't really cover what I am about to do: I want to simulate actual projectors, so I need for instance a beam with 16:9 aspect-ratio using a texture from a 16:9 video-source. I don't see how that could be achieved with a square-beam without having to resample the video to a size that fits inside the spotlights beam. Also note that supporting the aspect/shape cases won't necessarily need much extra-work in the shaders and no extra uniforms (well, at least if it's implemented the way I did it, there may be more efficient ways).
I will consider that, but I would still try to provide a default that covers the whole light-volume of the light, ideally nothing more.
Will do.
😄 it is, mostly because I think it wouldn't be complete if we left a useful degree-of-freedom inaccessible to the user. Not sure about that "same effect" – especially the shadow-camera will not know that the texture was rotated. What I don't like about the texture-rotation is that it doesn't work well with a shadow-camera that is synchronized with the light-volume (which should be the default behaviour). |
A new light projector class is fine with me (leaving the existing lights as-is), but the others in this thread prefer you just add a map property to In real life, studio lights have "barn doors", as I mentioned. You can model those with "cookies", so the conical frustum is masked, and renders as a rectangular one. Your other option is to continue to argue for the separate |
Jip. Will give that a try then. I'd still hope to keep the full projector-implementation around :) The only question I have regarding the
but only assign a texture to one of the indices, would that waste any gpu-resources for the lights without textures? |
#14621 has a proposal to add the @mrdoob , @WestLangley, which alternative would you prefer getting merged ? as a new Light type (this PR) or as a SpotLight with a map property (#14621, to be reviewed) ? |
@mbredif Based on the discussion in this thread, adding |
Any news about this? |
@usefulthink Thanks for your great work here! But according to #13057 (comment), closing this in favor of #14621. |
@Mugen87 Sure thing! Apologies for not finding the time and energy to move this ahead. Awesome that someone else did push it through! |
Adds a new light-type
ProjectorLight
, a light-source with a textured rectangular beam with configurable aspect and rotation.Example: https://cdn.rawgit.com/usefulthink/three.js/projector-lights-preview/examples/webgl_lights_projectorlight.html
Usage:
Note: this PR is not yet fully completed and there are some minor parts I am not really happy with. I am posting it mostly to get some early feedback on general interest from other developers and feedback on implementation details.