R2 Shaders
R2SurfaceShaderDriverSingle.h
Go to the documentation of this file.
1 #ifndef R2_SURFACE_SHADER_DRIVER_SINGLE_H
2 #define R2_SURFACE_SHADER_DRIVER_SINGLE_H
3 
4 /// \file R2SurfaceShaderDriverSingle.h
5 /// \brief A fragment shader driver for single instance surfaces.
6 
7 #include "R2LogDepth.h"
8 #include "R2Normals.h"
9 #include "R2SurfaceTypes.h"
10 #include "R2GBufferOutput.h"
11 #include "R2View.h"
12 
13 in R2_vertex_data_t R2_vertex_data;
14 uniform R2_surface_matrices_instance_t R2_surface_matrices_instance;
15 uniform R2_surface_textures_t R2_surface_textures;
16 uniform R2_view_t R2_view;
17 
18 layout(location = 0) out vec4 R2_out_albedo;
19 layout(location = 1) out vec2 R2_out_normal;
20 layout(location = 2) out vec4 R2_out_specular;
21 
23 R2_surface_shader_main_gbuffer()
24 {
25  vec3 normal_bumped = R2_normalsBump (
26  R2_surface_textures.normal,
27  R2_surface_matrices_instance.transform_normal,
28  R2_vertex_data.normal_vertex,
29  R2_vertex_data.tangent,
30  R2_vertex_data.bitangent,
31  R2_vertex_data.uv
32  );
33 
34  float depth_log = R2_logDepthEncodePartial (
35  R2_vertex_data.positive_eye_z,
36  R2_view.depth_coefficient);
37 
38  R2_surface_derived_t derived =
39  R2_surface_derived_t (normal_bumped);
40 
42  R2_vertex_data,
43  derived,
44  R2_surface_textures,
45  R2_view,
46  R2_surface_matrices_instance
47  );
48 
49  return R2_gbuffer_output_t(
50  o.albedo,
51  o.emission,
53  o.specular,
54  o.specular_exp / 256.0,
55  depth_log,
56  o.discarded
57  );
58 }
59 
60 void
61 main (void)
62 {
63  R2_gbuffer_output_t o = R2_surface_shader_main_gbuffer();
64 
65  //
66  // Assign all outputs.
67  //
68 
69  R2_out_albedo = vec4 (o.albedo, o.emission);
70  R2_out_normal = o.normal;
71  R2_out_specular = vec4 (o.specular, o.specular_exp);
72  gl_FragDepth = o.depth;
73 
74  if (o.discarded) {
75  discard;
76  }
77 }
78 
79 #endif // R2_SURFACE_SHADER_DRIVER_SINGLE_H
float R2_logDepthEncodePartial(const float z, const float depth_coefficient)
Definition: R2LogDepth.h:33
vec2 uv
Object-space UV.
mat3x3 transform_normal
Object-space to Eye-space normal matrix.
vec3 normal_vertex
Object-space vertex normal.
Functions for transforming normal vectors.
vec3 specular
8-bit unsigned normalized RGB specular color
Types relating to the view.
Types for deferred surface shading.
R2_surface_output_t R2_deferredSurfaceMain(const R2_vertex_data_t data, const R2_surface_derived_t derived, const R2_surface_textures_t textures, const R2_view_t view, const R2_surface_matrices_instance_t matrices_instance)
vec3 albedo
8-bit unsigned normalized RGB color
The G-Buffer format.
float positive_eye_z
Positive eye-space Z position.
vec3 tangent
Tangent vector.
float emission
8-bit unsigned normalized emission level
vec3 specular
8-bit unsigned normalized RGB specular color
bool discarded
True if this particular surface fragment should be discarded
vec3 normal
Eye-space normal vector.
vec2 normal
Compressed 16-bit half-precision normals.
float depth
Logarithmic depth value.
Textures that are required by all surfaces.
Interpolated vertex data that all deferred surface shaders will receive.
float specular_exp
Specular exponent in the range [0, 256]
float emission
8-bit unsigned normalized emission level
vec3 bitangent
Bitangent vector.
sampler2D normal
RGB normal map texture.
bool discarded
True if this particular surface fragment should be discarded
The type of surface details that all deferred surface shaders are required to calculate.
Derived surface data that all deferred surface shaders will receive.
Logarithmic depth functions.
A type representing the values written to the G-Buffer.
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.
vec3 albedo
8-bit unsigned normalized RGB color
Matrices and parameters related to the view that all surface shaders will receive.
Definition: R2View.h:9
vec2 R2_normalsCompress(const vec3 n)
Definition: R2Normals.h:17
float specular_exp
8-bit unsigned normalized specular exponent
vec3 R2_normalsBump(const sampler2D t_normal, const mat3x3 m_normal, const vec3 n, const vec3 t, const vec3 b, const vec2 uv)
Definition: R2Normals.h:144