R2 Shaders
R2DebugEyeZReconstruction.frag
Go to the documentation of this file.
1 #ifndef R2_DEBUG_EYE_Z_RECONSTRUCTION_H
2 #define R2_DEBUG_EYE_Z_RECONSTRUCTION_H
3 
4 /// \file R2DebugEyeZReconstruction.frag
5 /// \brief A fragment shader driver for reconstructing eye-space Z positions.
6 
7 #include "R2GBufferInput.h"
8 #include "R2LogDepth.h"
9 #include "R2Viewport.h"
10 
11 layout(location = 0) out float R2_out_z;
12 
13 uniform R2_viewport_t R2_viewport;
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  R2_out_z = eye_z;
33 }
34 
35 #endif // R2_DEBUG_EYE_Z_RECONSTRUCTION_H
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
Logarithmic depth functions.
layout(location=0) out vec4 R2_out
RGBA color.