R2 Core Shaders

Data Structures | Functions
R2LightDirectional.h File Reference

Functions and types related to directional lighting. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Data Structures
struct | R2_light_directional_vectors_t
| Vectors used when calculating directional lighting. More...
struct | R2_light_directional_t
| A directional light type. More...

## Functions
R2_light_directional_vectors_t | R2_lightDirectionalVectors (const R2_light_directional_t light, const vec3 p, const vec3 n)
vec3 | R2_lightDirectionalDiffuseTerm (const R2_light_directional_t light, const R2_light_directional_vectors_t v)
vec3 | R2_lightDirectionalSpecularTerm (const R2_light_directional_t light, const R2_light_directional_vectors_t v, const vec3 specular_color, const float specular_exponent)

## Detailed Description

Functions and types related to directional lighting.

Definition in file R2LightDirectional.h.

## Function Documentation

## § R2_lightDirectionalDiffuseTerm()

vec3 R2_lightDirectionalDiffuseTerm | ( | const R2_light_directional_t | light,
|  | const R2_light_directional_vectors_t | v
| ) |  |

Calculate the diffuse term for a directional light.

Parameters

  light | The light parameters
  v | The calculated light vectors

Returns
  The diffuse term

Definition at line 59 of file R2LightDirectional.h.

62 {
63 float factor = max (0.0, dot (v.surface_to_light, v.normal));
64 return (light.color * light.intensity) * factor;
65 }
R2_light_directional_t::color
vec3 color
The light color. The components are assumed to be in the range [0, 1].
Definition: R2LightDirectional.h:24
R2_light_directional_vectors_t::surface_to_light
vec3 surface_to_light
Direction from surface to light source (referred to as L in most texts)
Definition: R2LightDirectional.h:13
R2_light_directional_vectors_t::normal
vec3 normal
The surface normal (referred to as N in most texts)
Definition: R2LightDirectional.h:15
R2_light_directional_t::intensity
float intensity
The light intensity.
Definition: R2LightDirectional.h:28

## § R2_lightDirectionalSpecularTerm()

vec3 R2_lightDirectionalSpecularTerm | ( | const R2_light_directional_t | light,
|  | const R2_light_directional_vectors_t | v,
|  | const vec3 | specular_color,
|  | const float | specular_exponent
| ) |  |

Calculate the specular term for a directional light

Parameters

  light | The light parameters
  v | The calculated light vectors
  specular_color | The surface specular color
  specular_exponent | The surface specular exponent

Returns
  The specular term

Definition at line 77 of file R2LightDirectional.h.

82 {
83 float base_factor =
84 max (0.0, dot (v.reflection, v.surface_to_light));
85 float factor =
86 pow (base_factor, specular_exponent);
87 vec3 color =
88 (light.color * light.intensity) * factor;
89 return color * specular_color;
90 }
R2_light_directional_t::color
vec3 color
The light color. The components are assumed to be in the range [0, 1].
Definition: R2LightDirectional.h:24
R2_light_directional_vectors_t::reflection
vec3 reflection
Reflection between observer and normal (referred to as R in most texts)
Definition: R2LightDirectional.h:17
R2_light_directional_vectors_t::surface_to_light
vec3 surface_to_light
Direction from surface to light source (referred to as L in most texts)
Definition: R2LightDirectional.h:13
R2_light_directional_t::intensity
float intensity
The light intensity.
Definition: R2LightDirectional.h:28

## § R2_lightDirectionalVectors()

R2_light_directional_vectors_t R2_lightDirectionalVectors | ( | const R2_light_directional_t | light,
|  | const vec3 | p,
|  | const vec3 | n
| ) |  |

Calculate the vectors required to calculate directional lighting.

Parameters

  light | The light parameters
  p | The surface position
  n | The surface normal

Returns
  A set of lighting vectors

Definition at line 40 of file R2LightDirectional.h.

44 {
45 vec3 observer_to_surface = normalize (p);
46 vec3 surface_to_light = normalize (-light.direction);
47 vec3 reflection = reflect (observer_to_surface, n);
48 return R2_light_directional_vectors_t (observer_to_surface, surface_to_light, n, reflection);
49 }
R2_light_directional_t::direction
vec3 direction
The light direction. Assumed to be normalized.
Definition: R2LightDirectional.h:26
R2_light_directional_vectors_t
Vectors used when calculating directional lighting.
Definition: R2LightDirectional.h:9