R2 Core Shaders

R2LightShaderDriverSingle.h
Go to the documentation of this file.
1 #ifndef R2_LIGHT_SHADER_DRIVER_SINGLE_H
2 #define R2_LIGHT_SHADER_DRIVER_SINGLE_H
3
4 /// \file R2LightShaderDriverSingle.h
5 /// \brief A fragment shader driver for single instance lights.
6
7 #include "R2LightOutput.h"
8 #include "R2ReconstructedSurface.h"
9 #include "R2GBufferInput.h"
10 #include "R2LogDepth.h"
11 #include "R2Normals.h"
12 #include "R2Viewport.h"
13 #include "R2ViewRays.h"
14
15 layout(location = 0) out vec4 R2_out_diffuse;
16 layout(location = 1) out vec4 R2_out_specular;
17
18 uniform R2_viewport_t R2_light_viewport;
19 uniform R2_gbuffer_input_t R2_light_gbuffer;
20 uniform float R2_light_depth_coefficient;
21 uniform R2_view_rays_t R2_light_view_rays;
22
23 in float R2_light_volume_positive_eye_z;
24
25 void
26 main (void)
27 {
28 // Rendering of light volumes is expected to occur with depth
29 // writes disabled. However, it's necessary to calculate the
30 // correct logarithmic depth value for each fragment of the light
31 // volume in order to get correct depth testing with respect to the
32 // contents of the G-Buffer.
33
34 float depth_log = R2_logDepthEncodePartial (
35 R2_light_volume_positive_eye_z,
36 R2_light_depth_coefficient);
37
38 // Reconstruct the surface
39 R2_reconstructed_surface_t surface =
40 R2_deferredSurfaceReconstruct(
41 R2_light_gbuffer,
42 R2_light_viewport,
43 R2_light_view_rays,
44 R2_light_depth_coefficient,
45 gl_FragCoord.xy);
46
47 // Evaluate light
48 R2_light_output_t o = R2_deferredLightMain (surface);
49 R2_out_diffuse = vec4 (o.diffuse, 1.0);
50 R2_out_specular = vec4 (o.specular, 1.0);
51 gl_FragDepth = depth_log;
52 }
53
54 #endif // R2_LIGHT_SHADER_DRIVER_SINGLE_H
R2_logDepthEncodePartial
float R2_logDepthEncodePartial(const float z, const float depth_coefficient)
Definition: R2LogDepth.h:33
R2ViewRays.h
View ray types.
layout
layout(location=0) in vec3 R2_vertex_world_position
World-space position.
R2Normals.h
Functions for transforming normal vectors.
R2Viewport.h
Viewport types and functions.
R2_viewport_t
The type of viewports.
Definition: R2Viewport.h:9
R2_reconstructed_surface_t
Reconstructed surface data, taken from the G-Buffer.
Definition: R2ReconstructedSurface.h:16
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_view_rays_t
The type of view rays used to reconstruct positions during deferred rendering.
Definition: R2ViewRays.h:9
R2LogDepth.h
Logarithmic depth functions.
R2LightOutput.h
Types describing calculated light contributions.
R2_light_output_t
The type of light values that all deferred light shaders calculate.
Definition: R2LightOutput.h:9
R2_light_output_t::diffuse
vec3 diffuse
The diffuse color/intensity (8-bit unsigned)
Definition: R2LightOutput.h:11
R2_light_output_t::specular
vec3 specular
The specular color/intensity (8-bit unsigned)
Definition: R2LightOutput.h:13
R2ReconstructedSurface.h
Surface data reconstructed from the G-Buffer.
R2_deferredLightMain
R2_light_output_t R2_deferredLightMain(const R2_reconstructed_surface_t surface)
Definition: R2LightAmbientWithOcclusion.h:13
R2_deferredSurfaceReconstruct
R2_reconstructed_surface_t R2_deferredSurfaceReconstruct(const R2_gbuffer_input_t gbuffer, const R2_viewport_t viewport, const R2_view_rays_t view_rays, const float depth_coefficient, const vec2 screen_position)
Definition: R2ReconstructedSurface.h:60