jonathanhogg/flitter

It would be great if point lights could have a radius

Closed this issue · 4 comments

This would improve the realism of specular reflections where a light is relatively large compared to the distance of it from a surface. At the moment it is treated as infinitely small (that would be the definition of a "point" then) and so the reflections will look like small dots at close distances.

Have been thinking about how to do this off-and-on and wondering about the following:

  • Reflect the view ray off the surface normal to get a (normalised) reflection direction
  • Calculate closest point on this ray to the position of the light: dot product of fragment-to-light vector and reflection direction, multiplied by reflection direction, plus fragment position
  • Offset light along vector towards closest point by a maximum of the light radius
  • Attenuate light by some amount based on offset (not sure what the calculation for this should be)

This ought to give more believable specular reflections while not being too complicated to calculate.

A second possibility is just offsetting the light by its radius towards the fragment. Might be worth trying this first to see what that looks like…

A second possibility is just offsetting the light by its radius towards the fragment. Might be worth trying this first to see what that looks like…

OK, yeah, tried that. It doesn't work.

The winning solution was the second comment above: offsetting the point towards the reflection ray by up to radius. I am not attenuating the light at all, however, as I realised this doesn't make any sense. It would affect all light falling on objects from point lights and mess up the diffuse calculations as well. At the moment this means that reflections of ball lights off of shiny surfaces are a little crisp – I can revisit perhaps in the future.