Ray Tracer  2020
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
LightSource Class Referenceabstract

Abstract base class for LightSources. More...

#include <LightSource.h>

Inheritance diagram for LightSource:
AmbientLightSource DirectionalLightSource PointLightSource

Public Member Functions

virtual Colour getIlluminationAt (const Point &point) const =0
 Determine how much light reaches a Point from this LightSource. More...
 
virtual double getDistanceToLight (const Point &point) const =0
 Determine how far away the light source is from a given Point. More...
 
virtual Direction getLightDirection (const Point &point) const =0
 Direction from light source to a point. More...
 

Protected Member Functions

 LightSource (const Colour &colour)
 LightSource constructor. More...
 
 LightSource (const LightSource &lightSource)
 LightSource copy constructor. More...
 
virtual ~LightSource ()
 LightSource destructor. More...
 
LightSourceoperator= (const LightSource &lightSource)
 LightSource assignment operator. More...
 

Protected Attributes

Colour colour_
 The Colour of this LightSource's illumination. More...
 

Detailed Description

Abstract base class for LightSources.

LightSources provide illumination to the scene. All light sources have a Colour, but other properties may vary.

As an abstract base class, you cannot create a LightSource directly. Instead one of its concrete subclasses must be created.

Constructor & Destructor Documentation

◆ LightSource() [1/2]

LightSource::LightSource ( const Colour colour)
protected

LightSource constructor.

Parameters
colourThe Colour of this LightSource's illumination.

◆ LightSource() [2/2]

LightSource::LightSource ( const LightSource lightSource)
protected

LightSource copy constructor.

Parameters
lightSourceThe LightSource to copy.

◆ ~LightSource()

LightSource::~LightSource ( )
protectedvirtual

LightSource destructor.

Member Function Documentation

◆ getDistanceToLight()

virtual double LightSource::getDistanceToLight ( const Point point) const
pure virtual

Determine how far away the light source is from a given Point.

This is a bit tricky, to get around the fact that there are several general types of light. There are basically three types we are interested in:

  • AmbientLightSource, which does not have a location, and which does not create shadows.
  • PointLightSource and SpotLightSource, which have a fixed location, so cast shadows when an object is between the point of interest and the light source's location.
  • DirectionalLightSource, which does not have a specific location, and casts shadows if there's anything blocking that direction to the point of interest.

For a PointLightSource or SpotLightSource the direction is well defined. For a DirectionalLightSource we can return infinity. For an AmbientLightSource we can return -1. This is never a valid distance, so can be used to indicate that we can skip the lighting computations for this source.

Returns
The distance to the light source (with special values as above).
See also
getDirectionToLight()

Implemented in PointLightSource, DirectionalLightSource, and AmbientLightSource.

◆ getIlluminationAt()

virtual Colour LightSource::getIlluminationAt ( const Point point) const
pure virtual

Determine how much light reaches a Point from this LightSource.

The amount of light emitted by a LightSource is determined by its colour property, but this generally varies across the Scene. This method returns a scaled value to apply to the colour of the light at a given Point in the Scene.

Parameters
pointThe Point at which light is measured.
Returns
The illumination that reaches the Point.

Implemented in PointLightSource, DirectionalLightSource, and AmbientLightSource.

◆ getLightDirection()

virtual Direction LightSource::getLightDirection ( const Point point) const
pure virtual

Direction from light source to a point.

Return a Direction pointing from the given point towards the light source. For most light sources this is well-defined, but for AmbientLightSources it is not. This Direction is used for lighting and shadow calculations, however, so this is not a problem. We can return any value for AmbientLightSource, since it will never be used.

Parameters
pointThe point where the ray is being computed.
Returns
The Direction from the point towards the light.
See also
getDistanceToLight()

Implemented in PointLightSource, DirectionalLightSource, and AmbientLightSource.

◆ operator=()

LightSource & LightSource::operator= ( const LightSource lightSource)
protected

LightSource assignment operator.

Parameters
lightSourceThe LightSource to assign to this.
Returns
A reference to this to allow for chaining of assignment.

Member Data Documentation

◆ colour_

Colour LightSource::colour_
protected

The Colour of this LightSource's illumination.


The documentation for this class was generated from the following files: