R2 Shaders
R2DepthShaderDriverSingle.h
Go to the documentation of this file.
1 #ifndef R2_DEPTH_SHADER_DRIVER_SINGLE_H
2 #define R2_DEPTH_SHADER_DRIVER_SINGLE_H
3 
4 /// \file R2DepthShaderDriverSingle.h
5 /// \brief A fragment shader driver for single instance depth shaders.
6 
7 #include "R2DepthTypes.h"
8 #include "R2LogDepth.h"
9 #include "R2SurfaceTypes.h"
10 #include "R2View.h"
11 
12 in R2_vertex_data_t R2_vertex_data;
13 uniform R2_surface_matrices_instance_t R2_surface_matrices_instance;
14 uniform R2_surface_textures_t R2_surface_textures;
15 uniform R2_view_t R2_view;
16 
17 layout(location = 0) out vec2 R2_out_depth_variance;
18 
20 R2_depth_shader_main_exec()
21 {
22  float depth_log = R2_logDepthEncodePartial(
23  R2_vertex_data.positive_eye_z,
24  R2_view.depth_coefficient);
25 
26  bool discarded = R2_depthShaderMain(
27  R2_vertex_data,
28  R2_view,
29  R2_surface_matrices_instance);
30 
31  return R2_depth_shader_result_t(discarded, depth_log);
32 }
33 
34 void
35 main (void)
36 {
37  R2_depth_shader_result_t o = R2_depth_shader_main_exec();
38 
39  R2_out_depth_variance = vec2 (o.depth, o.depth * o.depth);
40  gl_FragDepth = o.depth;
41 
42  if (o.discarded) {
43  discard;
44  }
45 }
46 
47 #endif // R2_DEPTH_SHADER_DRIVER_SINGLE_H
float R2_logDepthEncodePartial(const float z, const float depth_coefficient)
Definition: R2LogDepth.h:33
Types related to depth/depth-variance rendering.
Types relating to the view.
Types for deferred surface shading.
float depth
The calculated logarithmic depth of the surface.
Definition: R2DepthTypes.h:13
float positive_eye_z
Positive eye-space Z position.
bool R2_depthShaderMain(const R2_vertex_data_t data, const R2_view_t view, const R2_surface_matrices_instance_t matrices_instance)
Definition: R2DepthBasic.h:13
The type of values produced by depth shader executions.
Definition: R2DepthTypes.h:9
Textures that are required by all surfaces.
Interpolated vertex data that all deferred surface shaders will receive.
Logarithmic depth functions.
bool discarded
true iff the fragment should be discarded
Definition: R2DepthTypes.h:11
float depth_coefficient
The scene's logarithmic depth coefficient.
Definition: R2View.h:11
layout(location=0) out vec4 R2_out
RGBA color.
Matrices related to the rendered instance that all deferred surface shaders will receive.
Matrices and parameters related to the view that all surface shaders will receive.
Definition: R2View.h:9