R2 Core Shaders

R2PositionReconstruction.h
Go to the documentation of this file.
1 #ifndef R2_POSITION_RECONSTRUCTION_H
2 #define R2_POSITION_RECONSTRUCTION_H
3
4 /// \file R2PositionReconstruction.h
5 /// \brief Functions for performing position reconstruction during deferred rendering.
6
7 #include "R2Bilinear.h"
8 #include "R2ViewRays.h"
9
10 ///
11 /// Reconstruct an eye-space position from the given parameters.
12 ///
13 /// @param eye_z The eye-space Z value of the position
14 /// @param uv The current position on the screen in UV coordinates
15 /// @param view_rays The current set of view rays
16 ///
17
18 vec4
19 R2_positionReconstructFromEyeZ(
20 const float eye_z,
21 const vec2 uv,
22 const R2_view_rays_t view_rays)
23 {
24 vec3 origin =
25 R2_bilinearInterpolate3(
26 view_rays.origin_x0y0,
27 view_rays.origin_x1y0,
28 view_rays.origin_x0y1,
29 view_rays.origin_x1y1,
30 uv
31 );
32
33 vec3 ray_normal =
34 R2_bilinearInterpolate3(
35 view_rays.ray_x0y0,
36 view_rays.ray_x1y0,
37 view_rays.ray_x0y1,
38 view_rays.ray_x1y1,
39 uv
40 );
41
42 vec3 ray =
43 (ray_normal * eye_z) + origin;
44
45 return vec4 (ray, 1.0);
46 }
47
48 #endif // R2_POSITION_RECONSTRUCTION_H
R2ViewRays.h
View ray types.
R2_view_rays_t::ray_x0y1
vec3 ray_x0y1
The view ray pointing out of the top left origin.
Definition: R2ViewRays.h:23
R2_view_rays_t::ray_x1y1
vec3 ray_x1y1
The view ray pointing out of the top right origin.
Definition: R2ViewRays.h:25
R2_view_rays_t::ray_x0y0
vec3 ray_x0y0
The view ray pointing out of the bottom left origin.
Definition: R2ViewRays.h:19
R2Bilinear.h
Functions for performing bilinear interpolation.
R2_view_rays_t::origin_x1y1
vec3 origin_x1y1
The top right origin.
Definition: R2ViewRays.h:17
R2_view_rays_t::ray_x1y0
vec3 ray_x1y0
The view ray pointing out of the bottom right origin.
Definition: R2ViewRays.h:21
R2_view_rays_t::origin_x0y0
vec3 origin_x0y0
The bottom left origin.
Definition: R2ViewRays.h:11
R2_view_rays_t::origin_x0y1
vec3 origin_x0y1
The top left origin.
Definition: R2ViewRays.h:15
R2_view_rays_t
The type of view rays used to reconstruct positions during deferred rendering.
Definition: R2ViewRays.h:9
R2_view_rays_t::origin_x1y0
vec3 origin_x1y0
The bottom right origin.
Definition: R2ViewRays.h:13
R2_positionReconstructFromEyeZ
vec4 R2_positionReconstructFromEyeZ(const float eye_z, const vec2 uv, const R2_view_rays_t view_rays)
Definition: R2PositionReconstruction.h:19
R2_bilinearInterpolate3
vec3 R2_bilinearInterpolate3(const vec3 x0y0, const vec3 x1y0, const vec3 x0y1, const vec3 x1y1, const vec2 p)
Definition: R2Bilinear.h:23