R2 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
lightThe light parameters
vThe 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 }
vec3 color
The light color. The components are assumed to be in the range [0, 1].
vec3 surface_to_light
Direction from surface to light source (referred to as L in most texts)
vec3 normal
The surface normal (referred to as N in most texts)
float intensity
The light intensity.

§ 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
lightThe light parameters
vThe calculated light vectors
specular_colorThe surface specular color
specular_exponentThe 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 }
vec3 color
The light color. The components are assumed to be in the range [0, 1].
vec3 reflection
Reflection between observer and normal (referred to as R in most texts)
vec3 surface_to_light
Direction from surface to light source (referred to as L in most texts)
float intensity
The light intensity.

§ 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
lightThe light parameters
pThe surface position
nThe 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 }
vec3 direction
The light direction. Assumed to be normalized.
Vectors used when calculating directional lighting.