R2 Core 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
4 #include "R2PositionReconstruction.h"
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
R2ViewRays.h
View ray types.
layout
layout(location=0) in vec3 R2_vertex_world_position
World-space position.
R2Viewport.h
Viewport types and functions.
R2_viewport_t
The type of viewports.
Definition: R2Viewport.h:9
R2_logDepthDecode
float R2_logDepthDecode(const float z, const float depth_coefficient)
Definition: R2LogDepth.h:72
R2GBufferInput.h
The textures that make up the G-Buffer.
R2_gbuffer_input_t
A type representing the set of bound textures that make up the G-Buffer.
Definition: R2GBufferInput.h:9
R2_viewportFragmentPositionToUV
vec2 R2_viewportFragmentPositionToUV(const R2_viewport_t v, const vec2 f_pos)
Definition: R2Viewport.h:24
R2_view_rays_t
The type of view rays used to reconstruct positions during deferred rendering.
Definition: R2ViewRays.h:9
R2LogDepth.h
Logarithmic depth functions.
R2_positionReconstructFromEyeZ
vec4 R2_positionReconstructFromEyeZ(const float eye_z, const vec2 uv, const R2_view_rays_t view_rays)
Definition: R2PositionReconstruction.h:19
R2PositionReconstruction.h
Functions for performing position reconstruction during deferred rendering.