R2 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 
12  /// The vectors for positional lighting
14 
15  /// The surface position in light-eye-space
17 
18  /// The surface position in light-clip-space
20 
21  /// The surface position as NDC coordinates from the perspective of the light
23 
24  /// The surface position as UV coordinates from the perspective of the light
26 
27  /// A value that indicates whether or not the light fragment is back projected (0.0 means back projected, 1.0 means not)
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 
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 {
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 
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
vec4 surface_light_eye
The surface position in light-eye-space.
vec4 surface_light_clip
The surface position in light-clip-space.
Vectors used when calculating projective lighting.
Vectors used when calculating positional lighting.
vec3 surface_light_ndc
The surface position as NDC coordinates from the perspective of the light.
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)
vec2 surface_light_uv
The surface position as UV coordinates from the perspective of the light.
A positional light type.
R2_light_positional_vectors_t R2_lightPositionalVectors(const R2_light_positional_t light, const vec3 p, const vec3 n)
Functions and types related to positional lighting.
R2_light_positional_vectors_t positional
The vectors for positional lighting.
float back_projected
A value that indicates whether or not the light fragment is back projected (0.0 means back projected...