three.js icon indicating copy to clipboard operation
three.js copied to clipboard

Create Option to Have Spotlights Use Rectangular Projection

Open N8python opened this issue 3 years ago • 18 comments

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.

Screen Shot 2022-09-02 at 4 09 04 PM Screen Shot 2022-09-02 at 4 09 30 PM Screen Shot 2022-09-02 at 4 11 12 PM

N8python avatar Sep 02 '22 20:09 N8python

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.

mrdoob avatar Sep 02 '22 20:09 mrdoob

Btw... Make sure to not include the builds nor changes to package.json in the PR.

mrdoob avatar Sep 02 '22 20:09 mrdoob

Sorry about that! Still very new to the whole pull-requesting thing 😓

N8python avatar Sep 02 '22 20:09 N8python

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.

N8python avatar Sep 02 '22 20:09 N8python

Are we against calling this something like "ProjectorLight", then, if a SpotLight modification isn't acceptable? I agree that "RectLight" is a bit confusing.

gkjohnson avatar Sep 07 '22 05:09 gkjohnson

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.

N8python avatar Sep 07 '22 23:09 N8python

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!

gkjohnson avatar Sep 07 '22 23:09 gkjohnson

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.

N8python avatar Sep 08 '22 01:09 N8python

When we can use this function? I'm very looking foward.. :)

Suprhimp avatar Jun 12 '23 13:06 Suprhimp

I agree - this would be very useful! I'd be happy to redo the API here if its flawed haha.

N8python avatar Jun 12 '23 14:06 N8python

How about handle conflicts and fix code style first? for fast function merge!

Suprhimp avatar Jun 13 '23 02:06 Suprhimp

@N8python If you don't mind maby we can fix conflicts and code style, if you invite me at your forked three js code :)

Suprhimp avatar Jun 14 '23 12:06 Suprhimp

Just make a pull request?

N8python avatar Jun 14 '23 19:06 N8python