R2 Shaders
R2LightSpherical.h
Go to the documentation of this file.
1 #ifndef R2_LIGHT_SPHERICAL_H
2 #define R2_LIGHT_SPHERICAL_H
3 
4 /// \file R2LightSpherical.h
5 /// \brief Functions and types related to spherical lighting
6 
7 #include "R2LightPositional.h"
8 
9 /// Calculate the Lambert diffuse term for a spherical light.
10 ///
11 /// @param light The light parameters
12 /// @param v The calculated light vectors
13 ///
14 /// @return The diffuse term
15 
16 vec3
18  const R2_light_positional_t light,
20 {
21  float factor = max (0.0, dot (v.surface_to_light, v.normal));
22  return (light.color * light.intensity) * factor;
23 }
24 
25 /// Calculate the specular Phong term for a spherical light
26 ///
27 /// @param light The light parameters
28 /// @param v The calculated light vectors
29 /// @param specular_color The surface specular color
30 /// @param specular_exponent The surface specular exponent
31 ///
32 /// @return The specular term
33 
34 vec3
36  const R2_light_positional_t light,
38  const vec3 specular_color,
39  const float specular_exponent)
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 }
51 
52 /// Calculate the specular Blinn-Phong term for a spherical light
53 ///
54 /// @param light The light parameters
55 /// @param v The calculated light vectors
56 /// @param specular_color The surface specular color
57 /// @param specular_exponent The surface specular exponent
58 ///
59 /// @return The specular term
60 
61 vec3
63  const R2_light_positional_t light,
65  const vec3 specular_color,
66  const float specular_exponent)
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 }
78 
79 #endif // R2_LIGHT_SPHERICAL_H
vec3 color
The light color. The components are assumed to be in the range [0, 1].
Vectors used when calculating positional lighting.
vec3 R2_lightSphericalSpecularBlinnPhongTerm(const R2_light_positional_t light, const R2_light_positional_vectors_t v, const vec3 specular_color, const float specular_exponent)
vec3 surface_to_light
Direction from surface to light source (referred to as L in most texts)
float intensity
The light intensity.
vec3 R2_lightSphericalDiffuseLambertTerm(const R2_light_positional_t light, const R2_light_positional_vectors_t v)
A positional light type.
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 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)
Functions and types related to positional lighting.