R2 Shaders
R2DebugEyePositionReconstruction.frag
Go to the documentation of this file.
1 /// \file R2DebugEyePositionReconstruction.frag
2 /// \brief A fragment shader driver for reconstructing eye-space positions.
3 
5 #include "R2GBufferInput.h"
6 #include "R2LogDepth.h"
7 #include "R2Viewport.h"
8 #include "R2ViewRays.h"
9 
10 layout(location = 0) out vec4 R2_out_eye_position;
11 
12 uniform R2_viewport_t R2_viewport;
13 uniform R2_view_rays_t R2_view_rays;
14 uniform R2_gbuffer_input_t R2_gbuffer;
15 uniform float R2_depth_coefficient;
16 
17 void
18 main (void)
19 {
20  // Get the current screen coordinates in UV coordinate form
21  vec2 screen_uv =
22  R2_viewportFragmentPositionToUV (R2_viewport, gl_FragCoord.xy);
23 
24  // Reconstruct the eye-space Z from the depth texture
25  float log_depth =
26  texture (R2_gbuffer.depth, screen_uv).x;
27  float eye_z_positive =
28  R2_logDepthDecode (log_depth, R2_depth_coefficient);
29  float eye_z =
30  -eye_z_positive;
31 
32  // Reconstruct the full eye-space position
33  R2_out_eye_position =
34  R2_positionReconstructFromEyeZ (eye_z, screen_uv, R2_view_rays);
35 }
36 
View ray types.
Viewport types and functions.
The type of viewports.
Definition: R2Viewport.h:9
float R2_logDepthDecode(const float z, const float depth_coefficient)
Definition: R2LogDepth.h:72
The textures that make up the G-Buffer.
A type representing the set of bound textures that make up the G-Buffer.
Definition: R2GBufferInput.h:9
vec2 R2_viewportFragmentPositionToUV(const R2_viewport_t v, const vec2 f_pos)
Definition: R2Viewport.h:24
The type of view rays used to reconstruct positions during deferred rendering.
Definition: R2ViewRays.h:9
Logarithmic depth functions.
vec4 R2_positionReconstructFromEyeZ(const float eye_z, const vec2 uv, const R2_view_rays_t view_rays)
layout(location=0) out vec4 R2_out
RGBA color.
Functions for performing position reconstruction during deferred rendering.