R2 Core 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
17 R2_lightSphericalDiffuseLambertTerm (
18 const R2_light_positional_t light,
19 const R2_light_positional_vectors_t v)
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
35 R2_lightSphericalSpecularPhongTerm (
36 const R2_light_positional_t light,
37 const R2_light_positional_vectors_t v,
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
62 R2_lightSphericalSpecularBlinnPhongTerm (
63 const R2_light_positional_t light,
64 const R2_light_positional_vectors_t v,
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
R2_light_positional_t::color
vec3 color
The light color. The components are assumed to be in the range [0, 1].
Definition: R2LightPositional.h:26
R2_light_positional_vectors_t
Vectors used when calculating positional lighting.
Definition: R2LightPositional.h:9
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)
Definition: R2LightSpherical.h:62
R2_light_positional_vectors_t::surface_to_light
vec3 surface_to_light
Direction from surface to light source (referred to as L in most texts)
Definition: R2LightPositional.h:13
R2_light_positional_t::intensity
float intensity
The light intensity.
Definition: R2LightPositional.h:28
R2_lightSphericalDiffuseLambertTerm
vec3 R2_lightSphericalDiffuseLambertTerm(const R2_light_positional_t light, const R2_light_positional_vectors_t v)
Definition: R2LightSpherical.h:17
R2_light_positional_t
A positional light type.
Definition: R2LightPositional.h:24
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)
Definition: R2LightSpherical.h:35
R2_light_positional_vectors_t::observer_to_surface
vec3 observer_to_surface
Direction from observer to surface (referred to as V in most texts)
Definition: R2LightPositional.h:11
R2_light_positional_vectors_t::normal
vec3 normal
The surface normal (referred to as N in most texts)
Definition: R2LightPositional.h:17
R2LightPositional.h
Functions and types related to positional lighting.