R2 Core Shaders

R2DepthBatched.vert
Go to the documentation of this file.
1 /// \file R2DepthBatched.vert
2 /// \brief A vertex shader for batched instances.
3
4 #include "R2LogDepth.h"
5 #include "R2Normals.h"
6 #include "R2SurfaceTypes.h"
7 #include "R2SurfaceVertexBatched.h"
8 #include "R2View.h"
9
10 out R2_vertex_data_t R2_vertex_data;
11 out R2_surface_matrices_instance_t R2_surface_matrices_instance;
12
13 uniform R2_view_t R2_view;
14
15 void
16 main (void)
17 {
18 mat4x4 m_modelview =
19 (R2_view.transform_view * R2_vertex_transform_model);
20 // Batched transforms are guaranteed to be orthogonal
21 mat3x3 m_normal =
22 mat3x3 (m_modelview);
23 mat3x3 m_uv =
24 mat3x3 (1.0); // Identity matrix
25
26 vec4 position_hom =
27 vec4 (R2_vertex_position, 1.0);
28 vec4 position_eye =
29 (m_modelview * position_hom);
30 vec4 position_clip =
31 ((R2_view.transform_projection * m_modelview) * position_hom);
32 vec4 position_clip_log =
33 vec4 (
34 position_clip.xy,
35 R2_logDepthEncodeFull (position_clip.w, R2_view.depth_coefficient),
36 position_clip.w);
37
38 float positive_eye_z = R2_logDepthPrepareEyeZ (position_eye.z);
39
40 vec2 uv = R2_vertex_uv;
41 vec4 tangent4 = R2_vertex_tangent4;
42 vec3 tangent = tangent4.xyz;
43 vec3 normal = R2_vertex_normal;
44 vec3 bitangent = R2_normalsBitangent (normal, tangent4);
45
46 R2_surface_matrices_instance = R2_surface_matrices_instance_t (
47 m_modelview,
48 m_normal,
49 m_uv
50 );
51
52 R2_vertex_data = R2_vertex_data_t (
53 position_eye,
54 position_clip,
55 positive_eye_z,
56 uv,
57 normal,
58 tangent,
59 bitangent
60 );
61
62 gl_Position = position_clip_log;
63 }
R2_logDepthEncodeFull
float R2_logDepthEncodeFull(const float z, const float depth_coefficient)
Definition: R2LogDepth.h:51
R2_view_t::transform_projection
mat4x4 transform_projection
Eye-space to Clip-space matrix.
Definition: R2View.h:15
R2_normalsBitangent
vec3 R2_normalsBitangent(const vec3 n, const vec4 t)
Definition: R2Normals.h:58
R2Normals.h
Functions for transforming normal vectors.
R2View.h
Types relating to the view.
R2SurfaceTypes.h
Types for deferred surface shading.
R2_vertex_data_t
Interpolated vertex data that all deferred surface shaders will receive.
Definition: R2SurfaceTypes.h:11
R2_logDepthPrepareEyeZ
float R2_logDepthPrepareEyeZ(const float z)
Definition: R2LogDepth.h:15
R2LogDepth.h
Logarithmic depth functions.
R2SurfaceVertexBatched.h
Data delivered via vertex attributes to batched instances in deferred rendering.
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_view_t
Matrices and parameters related to the view that all surface shaders will receive.
Definition: R2View.h:9
R2_view_t::transform_view
mat4x4 transform_view
World-space to Eye-space matrix.
Definition: R2View.h:13