R2 Shaders
Functions
R2LightSpherical.h File Reference

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

#include "R2LightPositional.h"
Include dependency graph for R2LightSpherical.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

vec3 R2_lightSphericalDiffuseLambertTerm (const R2_light_positional_t light, const R2_light_positional_vectors_t v)
 
vec3 R2_lightSphericalSpecularPhongTerm (const R2_light_positional_t light, const R2_light_positional_vectors_t v, const vec3 specular_color, const float specular_exponent)
 
vec3 R2_lightSphericalSpecularBlinnPhongTerm (const R2_light_positional_t light, const R2_light_positional_vectors_t v, const vec3 specular_color, const float specular_exponent)
 

Detailed Description

Functions and types related to spherical lighting.

Definition in file R2LightSpherical.h.

Function Documentation

§ R2_lightSphericalDiffuseLambertTerm()

vec3 R2_lightSphericalDiffuseLambertTerm ( const R2_light_positional_t  light,
const R2_light_positional_vectors_t  v 
)

Calculate the Lambert diffuse term for a spherical light.

Parameters
lightThe light parameters
vThe calculated light vectors
Returns
The diffuse term

Definition at line 17 of file R2LightSpherical.h.

20 {
21  float factor = max (0.0, dot (v.surface_to_light, v.normal));
22  return (light.color * light.intensity) * factor;
23 }
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)
float intensity
The light intensity.
vec3 normal
The surface normal (referred to as N in most texts)

§ R2_lightSphericalSpecularBlinnPhongTerm()

vec3 R2_lightSphericalSpecularBlinnPhongTerm ( const R2_light_positional_t  light,
const R2_light_positional_vectors_t  v,
const vec3  specular_color,
const float  specular_exponent 
)

Calculate the specular Blinn-Phong term for a spherical 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 62 of file R2LightSpherical.h.

67 {
68  vec3 half_v =
69  normalize ((-v.observer_to_surface) + v.surface_to_light);
70  float base_factor =
71  max (0.0, dot (v.normal, half_v));
72  float factor =
73  pow (base_factor, specular_exponent);
74  vec3 color =
75  (light.color * light.intensity) * factor;
76  return color * specular_color;
77 }
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)
float intensity
The light intensity.
vec3 observer_to_surface
Direction from observer to surface (referred to as V in most texts)
vec3 normal
The surface normal (referred to as N in most texts)

§ R2_lightSphericalSpecularPhongTerm()

vec3 R2_lightSphericalSpecularPhongTerm ( const R2_light_positional_t  light,
const R2_light_positional_vectors_t  v,
const vec3  specular_color,
const float  specular_exponent 
)

Calculate the specular Phong term for a spherical 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 35 of file R2LightSpherical.h.

40 {
41  vec3 reflection =
42  reflect (v.observer_to_surface, v.normal);
43  float base_factor =
44  max (0.0, dot (reflection, v.surface_to_light));
45  float factor =
46  pow (base_factor, specular_exponent);
47  vec3 color =
48  (light.color * light.intensity) * factor;
49  return color * specular_color;
50 }
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)
float intensity
The light intensity.
vec3 observer_to_surface
Direction from observer to surface (referred to as V in most texts)
vec3 normal
The surface normal (referred to as N in most texts)