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

Add penumbra angle to spotLight #5080

Closed
wants to merge 1 commit into from

Conversation

sgrif
Copy link
Contributor

@sgrif sgrif commented Jul 17, 2014

Add an additional option to THREE.SpotLight called penumbraAngle.
This angle will be added to the angle of the spotlight to create a
"falloff" cone. The area within both cones is lit as normal. The area
outside of the falloff code is not lit. The area between the inner and
falloff cones is smoothly faded away as it approaches the edge of the
falloff cone.

Before:

screen shot 2014-07-17 at 9 52 16 am

After (10 degree penumbra):

screen shot 2014-07-17 at 9 52 13 am

Add an additional option to `THREE.SpotLight` called `penumbraAngle`.
This angle will be added to the angle of the spotlight to create a
"falloff" cone. The area within both cones is lit as normal. The area
outside of the falloff code is not lit. The area between the inner and
falloff cones is smoothly faded away as it approaches the edge of the
falloff cone.
@sgrif
Copy link
Contributor Author

sgrif commented Jul 17, 2014

@WestLangley continuing...

I am just concerned about the parameter combinations, and maybe your modeling approach.

Can you elaborate a bit? I'm not sure I understand your meaning there.

The exponent parameter was supposed to be modeling this effect already -- at least that was my understanding.

The TL;DR version is that the exponent parameter is capable of modeling this:

full

which is not how light from a spot light spreads. The penumbra falloff is capable of representing something closer to this:

edge

If you would be willing to add DAT.GUI sliders to to your example

Added a general "spotlights" example with sliders.

@WestLangley
Copy link
Collaborator

OK, this looks pretty good to me, and I like it better than what we have now.

@sgrif Your 2nd demo with the sliders is much more useful than your first demo, IMHO. On my end, I hacked it to add OrbitControls, remove the texture which was not necessary, moved the light around a bit, added light and shadow camera helpers, and experimented. I like your penumbra better than the exponent parameter we have now. I do not think the exponent param is needed if the penumbra is added.

Would you be willing to expand your 2nd demo, add a camera controller, and add more light params and light and shadow helpers to the GUI so @mrdoob and others can easily experiment with your proposal?

Also, the light helper and shadow map helper need to be consistent with any changes made here... I wonder if the penumbra should be on the "inside" rather than the "outside"... Maybe it is OK as proposed...

@sgrif
Copy link
Contributor Author

sgrif commented Jul 17, 2014

@WestLangley Yes, I will add that.

Also, the light helper and shadow map helper need to be consistent with any changes made here... I wonder if the penumbra should be on the "inside" rather than the "outside"... Maybe it is OK as proposed...

I think the best solution is adding support for negative angles as well, which would be inside.

@WestLangley
Copy link
Collaborator

I think the best solution is adding support for negative angles as well, which would be inside.

What is the physical model that justifies negative penumbra angles?

@sgrif
Copy link
Contributor Author

sgrif commented Jul 17, 2014

What is the physical model that justifies negative penumbra angles?

There isn't it's a convenience. The effect is equivalent to subtracting the penumbra angle from the light angle. (e.g. swapping the two cones). Makes it easier to tweak the exact way that you're looking for the light to display.

@WestLangley
Copy link
Collaborator

I would not be in favor of negative penumbra angles, per se.

I would be in favor of declaring the that spotLight.angle is the maximum extent of the spotlight (as it is now), and that the penumbra is on the inside, instead of on the outside.

The effect would be to simply replace the exponential decay ( spotEffect ) in the shader with a new function that is more physically appealing.

After thinking about it a bit, I think this is the best approach.

@WestLangley
Copy link
Collaborator

I see that your same model has been implemented elsewhere (http://www.ozone3d.net/tutorials/glsl_lighting_phong_p3.php).

By keeping the penumbra on the inside, no shadows are cast outside the cone, and you can implement your penumbra model by changing only the falloff function ( i.e., the spotEffect calculation ).

You can define the falloff function via a parameter that replaces exponent, and takes a range in [ 0, 1 ]. For example, if it were 0.10, the falloff would begin at 90% of the light.angle.

@sgrif
Copy link
Contributor Author

sgrif commented Jul 18, 2014

I would personally expect the parameter to be an angle in radians, not a percentage.

@WestLangley
Copy link
Collaborator

I would personally expect the parameter to be an angle in radians, not a percentage.

That is an option. However, having parameters that are co-dependent can be problematic.

You are simply specifying a function that defines the intensity as a function of angle. That function has one parameter in your proposed model. You can parameterize it any way you want to, but having that parameter independent of the other model parameters is best, IMO.

@sgrif
Copy link
Contributor Author

sgrif commented Jul 18, 2014

but having that parameter independent of the other model parameters is best, IMO.

How is a percentage independent? It is by definition dependent on the value of angle.

@WestLangley
Copy link
Collaborator

How is a percentage independent? It is by definition dependent on the value of angle.

The percentage can go from 0 to 1 independently of the value of the spotlight angle.

Your proposal to use an angle for both parameters has merit. I just personally think that having two angles, with one required to be less than the other, is not a good model parameterization. Your call, though. I am just telling you what I think. : - )

@mrdoob
Copy link
Owner

mrdoob commented Jul 18, 2014

I think 2 angles is fine. It allows people to experiment with incorrect values if they want (one can find interesting styles like that).

@mrdoob
Copy link
Owner

mrdoob commented Jul 25, 2014

@sgrif Is this PR ready to be merged? I wasn't sure if you were planning to do anything else with it.

@sgrif
Copy link
Contributor Author

sgrif commented Jul 25, 2014

Yes, I haven't had a chance to update with @WestLangley's feedback. Should get a chance today or tomorrow.

@sgrif
Copy link
Contributor Author

sgrif commented Jul 25, 2014

Er yes, I am planning on doing more with it. No it is not ready to be merged.

@mrdoob
Copy link
Owner

mrdoob commented Feb 8, 2016

Ended up implementing this but with @WestLangley percentage suggestion. Looks really good!

screen shot 2016-02-08 at 12 54 13

Thanks guys!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants