R2 Core Shaders

R2LightProjective.h
Go to the documentation of this file.
1 #ifndef R2_LIGHT_PROJECTIVE_H
2 #define R2_LIGHT_PROJECTIVE_H
3
4 /// \file R2LightProjective.h
5 /// \brief Functions and types related to projective lighting
6
7 #include "R2LightPositional.h"
8
9 /// Vectors used when calculating projective lighting
10
11 struct R2_light_projective_vectors_t {
12 /// The vectors for positional lighting
13 R2_light_positional_vectors_t positional;
14
15 /// The surface position in light-eye-space
16 vec4 surface_light_eye;
17
18 /// The surface position in light-clip-space
19 vec4 surface_light_clip;
20
21 /// The surface position as NDC coordinates from the perspective of the light
22 vec3 surface_light_ndc;
23
24 /// The surface position as UV coordinates from the perspective of the light
25 vec2 surface_light_uv;
26
27 /// A value that indicates whether or not the light fragment is back projected (0.0 means back projected, 1.0 means not)
28 float back_projected;
29 };
30
31 /// Calculate the vectors required to calculate projective lighting.
32 ///
33 /// @param light The light parameters
34 /// @param p The surface position (eye-space)
35 /// @param n The surface normal (eye-space)
36 /// @param m_eye_to_light_eye A matrix to transform eye-space positions to light-eye-space
37 /// @param m_light_projection The light's projection matrix
38 ///
39 /// @return A set of lighting vectors
40
41 R2_light_projective_vectors_t
42 R2_lightProjectiveVectors(
43 const R2_light_positional_t light,
44 const vec3 p,
45 const vec3 n,
46 const mat4x4 m_eye_to_light_eye,
47 const mat4x4 m_light_projection)
48 {
49 R2_light_positional_vectors_t positional =
50 R2_lightPositionalVectors (light, p, n);
51
52 vec4 surface_hom =
53 vec4 (p, 1.0);
54 vec4 surface_light_eye =
55 m_eye_to_light_eye * surface_hom;
56 vec4 surface_light_clip =
57 m_light_projection * surface_light_eye;
58 vec3 surface_light_ndc =
59 surface_light_clip.xyz / surface_light_clip.w;
60 vec2 surface_light_uv =
61 (surface_light_ndc.xy + 1.0) * 0.5;
62
63 // Back-projection test.
64 float back_projected =
65 (surface_light_clip.w < 0.0) ? 0.0 : 1.0;
66
67 return R2_light_projective_vectors_t (
68 positional,
69 surface_light_eye,
70 surface_light_clip,
71 surface_light_ndc,
72 surface_light_uv,
73 back_projected
74 );
75 }
76
77 #endif // R2_LIGHT_PROJECTIVE_H
R2_light_projective_vectors_t::surface_light_eye
vec4 surface_light_eye
The surface position in light-eye-space.
Definition: R2LightProjective.h:16
R2_light_projective_vectors_t::surface_light_clip
vec4 surface_light_clip
The surface position in light-clip-space.
Definition: R2LightProjective.h:19
R2_light_projective_vectors_t
Vectors used when calculating projective lighting.
Definition: R2LightProjective.h:11
R2_light_positional_vectors_t
Vectors used when calculating positional lighting.
Definition: R2LightPositional.h:9
R2_light_projective_vectors_t::surface_light_ndc
vec3 surface_light_ndc
The surface position as NDC coordinates from the perspective of the light.
Definition: R2LightProjective.h:22
R2_lightProjectiveVectors
R2_light_projective_vectors_t R2_lightProjectiveVectors(const R2_light_positional_t light, const vec3 p, const vec3 n, const mat4x4 m_eye_to_light_eye, const mat4x4 m_light_projection)
Definition: R2LightProjective.h:42
R2_light_projective_vectors_t::surface_light_uv
vec2 surface_light_uv
The surface position as UV coordinates from the perspective of the light.
Definition: R2LightProjective.h:25
R2_light_positional_t
A positional light type.
Definition: R2LightPositional.h:24
R2_lightPositionalVectors
R2_light_positional_vectors_t R2_lightPositionalVectors(const R2_light_positional_t light, const vec3 p, const vec3 n)
Definition: R2LightPositional.h:46
R2LightPositional.h
Functions and types related to positional lighting.
R2_light_projective_vectors_t::positional
R2_light_positional_vectors_t positional
The vectors for positional lighting.
Definition: R2LightProjective.h:13
R2_light_projective_vectors_t::back_projected
float back_projected
A value that indicates whether or not the light fragment is back projected (0.0 means back projected...
Definition: R2LightProjective.h:28