2.14
Lighting: Spherical

- 2.14.1. Overview
- 2.14.2. Attenuation
- 2.14.3. Application
- 2.14.4. Types

2.14.1
Overview
1
A spherical light in the r2 package is a light that emits rays of light in all directions from a given origin specified in eye space up to a given maximum radius.
2.14.1.2 Spherical lighting
3
The term spherical comes from the fact that the light has a defined radius. Most rendering systems instead use point lights that specify multiple attenuation constants to control how light is attenuated over distance. The problem with this approach is that it requires solving a quadratic equation to determine a minimum bounding sphere that can contain the light. Essentially, the programmer/artist is forced to determine "at which radius does the contribution from this light effectively reach zero?". With spherical lights, the maximum radius is declared up front, and a single falloff value is used to determine the attenuation curve within that radius. This makes spherical lights more intuitive to use: The programmer/artist simply places a sphere within the scene and knows exactly from the radius which objects are lit by it. It also means that bounding light volumes can be trivially constructed from unit spheres by simply scaling those spheres by the light radius, when performing deferred rendering.
2.14.2
Attenuation
1
The light supports attenuation using the radius as the maximum range.
2.14.3
Application
1
The final light applied to the surface is given by spherical (Spherical.hs), where sr, sg, sb are the red, green, and blue channels, respectively, of the surface being lit. The surface-to-light vector stl is calculated by normalizing the negation of the difference between the the current eye space surface_position and the eye space origin of the light.
2.14.3.2 Spherical lighting (Application)

    module Spherical where

    import qualified Attenuation
    import qualified Color4
    import qualified Direction
    import qualified LightDiffuse
    import qualified LightSpecular
    import qualified LightSpherical
    import qualified Normal
    import qualified Position3
    import qualified Specular
    import qualified Spaces
    import qualified Vector3f
    import qualified Vector4f

    spherical :: Direction.T Spaces.Eye -> Normal.T -> Position3.T Spaces.Eye -> LightSpherical.T -> Specular.T -> Color4.T -> Vector3f.T
    spherical view n surface_position light specular (Vector4f.V4 sr sg sb _) =
      let
        position_diff   = Position3.sub3 surface_position (LightSpherical.origin light)
        stl             = Vector3f.normalize (Vector3f.negation position_diff)
        distance        = Vector3f.magnitude (position_diff)
        attenuation     = Attenuation.attenuation (LightSpherical.radius light) (LightSpherical.falloff light) distance
        light_color     = LightSpherical.color light
        light_intensity = LightSpherical.intensity light
        light_d         = LightDiffuse.diffuse stl n light_color light_intensity
        light_s         = LightSpecular.specularBlinnPhong stl view n light_color light_intensity specular
        light_da        = Vector3f.scale light_d attenuation
        light_sa        = Vector3f.scale light_s attenuation
        lit_d           = Vector3f.mult3 (Vector3f.V3 sr sg sb) light_da
        lit_s           = Vector3f.add3 lit_d light_sa
      in
        lit_s

2.14.4
Types
1
Spherical lights are represented in the r2 package by the R2LightSphericalSingle type.