R2 Core Shaders
R2SurfaceSingle.vert
Go to the documentation of this file.
1 /// \file R2SurfaceSingle.vert
2 /// \brief A vertex shader for single instances.
3 
4 #include "R2LogDepth.h"
5 #include "R2Normals.h"
6 #include "R2SurfaceTypes.h"
7 #include "R2SurfaceVertex.h"
8 #include "R2View.h"
9 #include "R2Viewport.h"
10 
11 out R2_vertex_data_t R2_vertex_data;
12 uniform R2_view_t R2_view;
13 uniform R2_surface_matrices_instance_t R2_surface_matrices_instance;
14 
15 void
16 main (void)
17 {
18  vec4 position_hom =
19  vec4 (R2_vertex_position, 1.0);
20  vec4 position_eye =
21  (R2_surface_matrices_instance.transform_modelview * position_hom);
22  vec4 position_clip =
23  ((R2_view.transform_projection * R2_surface_matrices_instance.transform_modelview) * position_hom);
24  vec4 position_clip_log =
25  vec4 (
26  position_clip.xy,
27  R2_logDepthEncodeFull (position_clip.w, R2_view.depth_coefficient),
28  position_clip.w);
29 
30  float positive_eye_z = R2_logDepthPrepareEyeZ (position_eye.z);
31 
32  vec2 uv = (R2_surface_matrices_instance.transform_uv * vec3 (R2_vertex_uv, 1.0)).xy;
33  vec4 tangent4 = R2_vertex_tangent4;
34  vec3 tangent = tangent4.xyz;
35  vec3 normal = R2_vertex_normal;
36  vec3 bitangent = R2_normalsBitangent (normal, tangent4);
37 
38  R2_vertex_data = R2_vertex_data_t (
39  position_eye,
40  position_clip,
41  positive_eye_z,
42  uv,
43  normal,
44  tangent,
45  bitangent
46  );
47 
48  gl_Position = position_clip_log;
49 }
Data required by each vertex in deferred rendering, provided as vertex attributes.
float R2_logDepthEncodeFull(const float z, const float depth_coefficient)
Definition: R2LogDepth.h:51
mat4x4 transform_projection
Eye-space to Clip-space matrix.
Definition: R2View.h:15
vec3 R2_normalsBitangent(const vec3 n, const vec4 t)
Definition: R2Normals.h:58
Functions for transforming normal vectors.
Viewport types and functions.
Types relating to the view.
Types for deferred surface shading.
mat4x4 transform_modelview
Object-space to Eye-space matrix.
mat3x3 transform_uv
UV matrix.
Interpolated vertex data that all deferred surface shaders will receive.
float R2_logDepthPrepareEyeZ(const float z)
Definition: R2LogDepth.h:15
Logarithmic depth functions.
float depth_coefficient
The scene's logarithmic depth coefficient.
Definition: R2View.h:11
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