three.js
three.js copied to clipboard
Create Option to Have Spotlights Use Rectangular Projection
With the new mapping capabilities of spotlights, many people will want to use them as movie-projectors. However, their shape is purely circular - this pull request allows you to set the projector boolean on a spot light to have it attenuate based off its shadowcam's frustum. It also includes the projectorAspect attribute to allow varying the width of the projection.
It also supports the use of the penumbra parameter for attenuation (see image 3). This is accomplished via a signed distance function.
We'll have to refactor the code a bit...
I think it'd be more intuitive to introduce a RectLight but we'll still need to a aspect property.
Btw... Make sure to not include the builds nor changes to package.json in the PR.
Sorry about that! Still very new to the whole pull-requesting thing 😓
All right the files are no longer being overwritten! How would you recommend I refactor things?
I would be against a RectLight - One, because there's already RectAreaLight, and two, adding another light type would mean a large codebase overhaul.
Are we against calling this something like "ProjectorLight", then, if a SpotLight modification isn't acceptable? I agree that "RectLight" is a bit confusing.
Are we against calling this something like "ProjectorLight", then, if a SpotLight modification isn't acceptable? I agree that "RectLight" is a bit confusing.
I think ProjectorLight would make the most sense. Another thing I was thinking is perhaps having an attenuation mode for spotlights that can toggle between this and the traditional circle attenuation - maybe THREE.CircleAttenuation and THREE.RectAttenuation. Maybe that would be more "idiomatic", or in the style of threejs.
As I said before, I'm not sure the additional code complexity warranted by a ProjectorLight would be worth it - given how simple the modifications to the SpotLight are.
As I said before, I'm not sure the additional code complexity warranted by a ProjectorLight would be worth it - given how simple the modifications to the SpotLight are.
If an "attenuation" field like you've suggested is not acceptable for the public API then I would think it would still be okay to implement it that way internally while the public facing API separates the lights into "Spot" and "Projector" lights. Best of both worlds!
As I said before, I'm not sure the additional code complexity warranted by a ProjectorLight would be worth it - given how simple the modifications to the SpotLight are.
If an "attenuation" field like you've suggested is not acceptable for the public API then I would think it would still be okay to implement it that way internally while the public facing API separates the lights into "Spot" and "Projector" lights. Best of both worlds!
You, my friend, are a genius. ProjectorLight is a subclass of SpotLight that internally is just a SpotLight with an attenuated field.
When we can use this function? I'm very looking foward.. :)
I agree - this would be very useful! I'd be happy to redo the API here if its flawed haha.
How about handle conflicts and fix code style first? for fast function merge!
@N8python If you don't mind maby we can fix conflicts and code style, if you invite me at your forked three js code :)
Just make a pull request?