R2 Shaders
R2EnvironmentReflection.h
Go to the documentation of this file.
1 #ifndef R2_ENVIRONMENT_REFLECTION_H
2 #define R2_ENVIRONMENT_REFLECTION_H
3 
4 #include "R2CubeMaps.h"
5 
6 ///
7 /// \file R2EnvironmentReflection.h
8 /// \brief Functions for environment-mapped reflections.
9 ///
10 
11 ///
12 /// Calculate a reflection based on the eye-space view direction \a v_eye
13 /// and eye-space surface normal \a n_eye. The reflection vector is transformed
14 /// to world-space using the inverse view transform \a view_inv and sampled
15 /// from the right-handed cube map \a t.
16 ///
17 /// @param t A right-handed cube map
18 /// @param v_eye An eye-space view direction
19 /// @param n_eye An eye-space surface normal
20 /// @param view_inv An eye-space-to-world-space matrix
21 ///
22 
23 vec4
25  const samplerCube t,
26  const vec3 v_eye,
27  const vec3 n_eye,
28  const mat4x4 view_inv)
29 {
30  vec3 v_eye_n = normalize (v_eye);
31  vec3 n_eye_n = normalize (n_eye);
32  vec3 r = reflect (v_eye_n, n_eye_n);
33  vec4 r_world = view_inv * vec4 (r, 0.0);
34  return R2_cubeMapTextureRH (t, r_world.xyz);
35 }
36 
37 #endif // R2_ENVIRONMENT_REFLECTION_H
Functions for dealing with cube maps.
vec4 R2_cubeMapTextureRH(const samplerCube t, const vec3 v)
Definition: R2CubeMaps.h:15
vec4 R2_environmentReflection(const samplerCube t, const vec3 v_eye, const vec3 n_eye, const mat4x4 view_inv)