R2 Core 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
22 R2_gbuffer_output_t
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
41 R2_surface_output_t o = R2_deferredSurfaceMain(
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,
52 R2_normalsCompress (o.normal),
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
R2_logDepthEncodePartial
float R2_logDepthEncodePartial(const float z, const float depth_coefficient)
Definition: R2LogDepth.h:33
R2_vertex_data_t::uv
vec2 uv
Object-space UV.
Definition: R2SurfaceTypes.h:19
R2_surface_matrices_instance_t::transform_normal
mat3x3 transform_normal
Object-space to Eye-space normal matrix.
Definition: R2SurfaceTypes.h:48
R2_vertex_data_t::normal_vertex
vec3 normal_vertex
Object-space vertex normal.
Definition: R2SurfaceTypes.h:21
layout
layout(location=0) in vec3 R2_vertex_world_position
World-space position.
R2Normals.h
Functions for transforming normal vectors.
R2_surface_output_t::specular
vec3 specular
8-bit unsigned normalized RGB specular color
Definition: R2SurfaceOutput.h:17
R2View.h
Types relating to the view.
R2SurfaceTypes.h
Types for deferred surface shading.
R2_deferredSurfaceMain
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)
Definition: R2SurfaceBasic.h:14
R2_gbuffer_output_t::albedo
vec3 albedo
8-bit unsigned normalized RGB color
Definition: R2GBufferOutput.h:11
R2GBufferOutput.h
The G-Buffer format.
R2_vertex_data_t::positive_eye_z
float positive_eye_z
Positive eye-space Z position.
Definition: R2SurfaceTypes.h:17
R2_vertex_data_t::tangent
vec3 tangent
Tangent vector.
Definition: R2SurfaceTypes.h:23
R2_surface_output_t::emission
float emission
8-bit unsigned normalized emission level
Definition: R2SurfaceOutput.h:13
R2_gbuffer_output_t::specular
vec3 specular
8-bit unsigned normalized RGB specular color
Definition: R2GBufferOutput.h:17
R2_surface_output_t::discarded
bool discarded
True if this particular surface fragment should be discarded
Definition: R2SurfaceOutput.h:21
R2_surface_output_t::normal
vec3 normal
Eye-space normal vector.
Definition: R2SurfaceOutput.h:15
R2_gbuffer_output_t::normal
vec2 normal
Compressed 16-bit half-precision normals.
Definition: R2GBufferOutput.h:15
R2_gbuffer_output_t::depth
float depth
Logarithmic depth value.
Definition: R2GBufferOutput.h:21
R2_surface_textures_t
Textures that are required by all surfaces.
Definition: R2SurfaceTypes.h:37
R2_vertex_data_t
Interpolated vertex data that all deferred surface shaders will receive.
Definition: R2SurfaceTypes.h:11
R2_surface_output_t::specular_exp
float specular_exp
Specular exponent in the range [0, 256]
Definition: R2SurfaceOutput.h:19
R2_gbuffer_output_t::emission
float emission
8-bit unsigned normalized emission level
Definition: R2GBufferOutput.h:13
R2_vertex_data_t::bitangent
vec3 bitangent
Bitangent vector.
Definition: R2SurfaceTypes.h:25
R2_surface_textures_t::normal
sampler2D normal
RGB normal map texture.
Definition: R2SurfaceTypes.h:39
R2_gbuffer_output_t::discarded
bool discarded
True if this particular surface fragment should be discarded
Definition: R2GBufferOutput.h:23
R2_surface_output_t
The type of surface details that all deferred surface shaders are required to calculate.
Definition: R2SurfaceOutput.h:9
R2_surface_derived_t
Derived surface data that all deferred surface shaders will receive.
Definition: R2SurfaceTypes.h:30
R2LogDepth.h
Logarithmic depth functions.
R2_gbuffer_output_t
A type representing the values written to the G-Buffer.
Definition: R2GBufferOutput.h:9
R2_view_t::depth_coefficient
float depth_coefficient
The scene&#39;s logarithmic depth coefficient.
Definition: R2View.h:11
R2_surface_matrices_instance_t
Matrices related to the rendered instance that all deferred surface shaders will receive.
Definition: R2SurfaceTypes.h:44
R2_surface_output_t::albedo
vec3 albedo
8-bit unsigned normalized RGB color
Definition: R2SurfaceOutput.h:11
R2_view_t
Matrices and parameters related to the view that all surface shaders will receive.
Definition: R2View.h:9
R2_normalsCompress
vec2 R2_normalsCompress(const vec3 n)
Definition: R2Normals.h:17
R2_gbuffer_output_t::specular_exp
float specular_exp
8-bit unsigned normalized specular exponent
Definition: R2GBufferOutput.h:19
R2_normalsBump
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