R2 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"
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
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
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
float R2_logDepthEncodePartial(const float z, const float depth_coefficient)
Definition: R2LogDepth.h:33
View ray types.
Functions for transforming normal vectors.
Viewport types and functions.
The type of viewports.
Definition: R2Viewport.h:9
Reconstructed surface data, taken from the G-Buffer.
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
The type of view rays used to reconstruct positions during deferred rendering.
Definition: R2ViewRays.h:9
Logarithmic depth functions.
Types describing calculated light contributions.
layout(location=0) out vec4 R2_out
RGBA color.
The type of light values that all deferred light shaders calculate.
Definition: R2LightOutput.h:9
vec3 diffuse
The diffuse color/intensity (8-bit unsigned)
Definition: R2LightOutput.h:11
vec3 specular
The specular color/intensity (8-bit unsigned)
Definition: R2LightOutput.h:13
Surface data reconstructed from the G-Buffer.
R2_light_output_t R2_deferredLightMain(const R2_reconstructed_surface_t surface)
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)