HIRO_DRAW
Computer Graphics Structures library
ShaderApi.h
1 /*
2  Copyright (C) Skeletex Research, s.r.o. - All Rights Reserved
3  Unauthorized copying of this file, via any medium is strictly prohibited
4  Proprietary and confidential
5 */
6 #ifndef HIRO_DRAW_SHADER_API_H
7 #define HIRO_DRAW_SHADER_API_H
8 #include <string>
9 
10 #include <glbinding/gl/gl.h>
11 #include <glm/glm.hpp>
12 
13 #include <Utils/GeometryStructures.h>
14 #include <COGS/Color.h>
15 #include <HIRO_DRAW/API.h>
16 
17 
18 
19 namespace hiro::shader
20 {
21  // CAUTION:
22  // anything changed in this section needs to be updated accordingly in GLSL
23 
25  const int MAX_SCENE_COUNT{ 16 };
27  const int MAX_CAMERA_COUNT{ 16 };
29  const int MAX_LIGHT_COUNT{ 16 };
31  const int MAX_LIGHT_COUNT_PER_SCENE{ 4 };
33  const int MAX_INSTANCE_COUNT{ 32 };
34 
36  const int ULOC_RENDER_PASS{ 0 };
38  const int ULOC_SHADOWING_METHOD{ 1 };
40  const int ULOC_MODEL_MATRIX{ 2 };
42  const int ULOC_SCENE_ID{ 6 };
44  const int ULOC_USE_INSTANCING{ 7 };
47 
48  const int ULOC_CUSTOM_BEGIN{ 12 };
49  const int ULOC_CUSTOM_0{ ULOC_CUSTOM_BEGIN + 0 };
50  const int ULOC_CUSTOM_1{ ULOC_CUSTOM_BEGIN + 1 };
51  const int ULOC_CUSTOM_2{ ULOC_CUSTOM_BEGIN + 2 };
52  const int ULOC_CUSTOM_3{ ULOC_CUSTOM_BEGIN + 3 };
53  const int ULOC_CUSTOM_4{ ULOC_CUSTOM_BEGIN + 4 };
54  const int ULOC_CUSTOM_5{ ULOC_CUSTOM_BEGIN + 5 };
55  const int ULOC_CUSTOM_6{ ULOC_CUSTOM_BEGIN + 6 };
56  const int ULOC_CUSTOM_7{ ULOC_CUSTOM_BEGIN + 7 };
57  const int ULOC_CUSTOM_8{ ULOC_CUSTOM_BEGIN + 8 };
58  const int ULOC_CUSTOM_9{ ULOC_CUSTOM_BEGIN + 9 };
59  const int ULOC_CUSTOM_10{ ULOC_CUSTOM_BEGIN + 10 };
60  const int ULOC_CUSTOM_11{ ULOC_CUSTOM_BEGIN + 11 };
61  const int ULOC_CUSTOM_12{ ULOC_CUSTOM_BEGIN + 12 };
62  const int ULOC_CUSTOM_13{ ULOC_CUSTOM_BEGIN + 13 };
63  const int ULOC_CUSTOM_14{ ULOC_CUSTOM_BEGIN + 14 };
64  const int ULOC_CUSTOM_15{ ULOC_CUSTOM_BEGIN + 15 };
65  const int ULOC_CUSTOM_16{ ULOC_CUSTOM_BEGIN + 16 };
66  const int ULOC_CUSTOM_17{ ULOC_CUSTOM_BEGIN + 17 };
67  const int ULOC_CUSTOM_18{ ULOC_CUSTOM_BEGIN + 18 };
68  const int ULOC_CUSTOM_19{ ULOC_CUSTOM_BEGIN + 19 };
69 
71  const int UBIND_INSTANCING_MATRICES{ 0 };
73  const int UBIND_VIEW_MATRICES{ 1 };
75  const int UBIND_SCENE_DATA{ 2 };
77  const int UBIND_LIGHTS{ 3 };
78 
79  const int UBIND_CUSTOM_0{ 4 };
80  const int UBIND_CUSTOM_1{ 5 };
81  const int UBIND_CUSTOM_2{ 6 };
82  const int UBIND_CUSTOM_3{ 7 };
83  const int UBIND_CUSTOM_4{ 8 };
84  const int UBIND_CUSTOM_5{ 9 };
85  const int UBIND_CUSTOM_6{ 10 };
86  const int UBIND_CUSTOM_7{ 11 };
87  const int UBIND_CUSTOM_8{ 12 };
88  const int UBIND_CUSTOM_9{ 13 };
89 
90 
91 
93  struct HIRO_DRAW_API Material
94  {
96  Material() = default;
98  Material(const cogs::Color3f &col);
100  cogs::Color3f color{ cogs::color::GRAY70 };
102  float specular{ 0.5f };
104  float shininess{ 60.0f };
106  bool metallic{ false };
107  uint8_t __padding0{ 0 };
108  uint16_t __padding1{ 0 };
110  bool use_lighting{ true };
111  uint8_t __padding2{ 0 };
112  uint16_t __padding3{ 0 };
113  };
114 
116  struct HIRO_DRAW_API Light
117  {
118  glm::mat4 view{ 1.0f };
120  glm::vec4 position{ 0.0f };
122  cogs::Color3f color{ cogs::color::WHITE };
124  float ambient_intensity{ 0.1f };
126  float in_camera_space{ false };
127  bool cast_shadow{ false };
128  uint8_t __padding0{ 0 };
129  uint16_t __padding1{ 0 };
130  glm::vec2 __padding2{ 0.0f };
131 
132  static hiro::shader::Light CreateLight(
133  const glm::vec4 &position,
134  const cogs::Color3f &color,
135  float ambient_intensity,
136  bool in_camera_space);
137 
138  static hiro::shader::Light CreatePointLight(
139  const glm::vec3 &position,
140  const cogs::Color3f &color,
141  float ambient_intensity);
142 
143  static hiro::shader::Light CreateDirectionalLight(
144  const glm::vec3 &direction,
145  const cogs::Color3f &color,
146  float ambient_intensity);
147 
148 
150  static hiro::shader::Light CreateHeadLight(const cogs::Color3f &color);
151 
153  static hiro::shader::Light CreateShadowSunLight(
154  const glm::vec3 &direction,
155  const cogs::Color3f &color,
156  float ambient_intensity,
157  const geom::Sphere &scene_bounds);
158 
160  static hiro::shader::Light CreateShadowSpotlight(
161  const glm::vec3 &position,
162  const glm::mat4 &view,
163  const glm::mat4 &projection,
164  const cogs::Color3f &color);
165 
167  static hiro::shader::Light CreateShadowPointLight(
168  const glm::vec3 &position,
169  const cogs::Color3f &color,
170  float ambient_intensity,
171  const geom::Sphere &scene_bounds);
172 
173  };
174 
176  struct MatAndInv
177  {
179  MatAndInv(const glm::mat4 &mat);
180  glm::mat4 matrix{ 1.0f };
181  glm::mat4 inverse{ 1.0f };
182  };
183 
185  struct SceneData
186  {
188  glm::mat4 projection;
192  int32_t camera_id;
193  glm::vec3 __padding0{ 0.0f };
195  glm::ivec4 light_ids;
197  glm::ivec2 resolution;
198  glm::vec2 __padding1{ 0.0f };
199  };
200 
202  inline void DrawFullscreen()
203  {
204  gl::glDrawArrays(gl::GLenum::GL_TRIANGLE_FAN, 0, 4);
205  }
206 
207 }
208 
209 #endif /* !HIRO_DRAW_SHADER_API_H */
const int ULOC_CUSTOM_5
Location usable for custom uniform.
Definition: ShaderApi.h:54
const int UBIND_CUSTOM_1
Uniform binding location for custom data.
Definition: ShaderApi.h:80
const int UBIND_CUSTOM_4
Uniform binding location for custom data.
Definition: ShaderApi.h:83
const int ULOC_CUSTOM_8
Location usable for custom uniform.
Definition: ShaderApi.h:57
const int ULOC_CUSTOM_15
Location usable for custom uniform.
Definition: ShaderApi.h:64
const int UBIND_CUSTOM_9
Uniform binding location for custom data.
Definition: ShaderApi.h:88
const int ULOC_CUSTOM_BEGIN
First location usable for custom uniform.
Definition: ShaderApi.h:48
const int UBIND_CUSTOM_6
Uniform binding location for custom data.
Definition: ShaderApi.h:85
const int ULOC_MODEL_MATRIX
Location of model matrix stored in hiro::draw::Style::transform.
Definition: ShaderApi.h:40
const int UBIND_SCENE_DATA
Uniform binding location for scene data structures.
Definition: ShaderApi.h:75
void DrawFullscreen()
Invokes draw for fullscreen.vert shader.
Definition: ShaderApi.h:202
const int ULOC_CUSTOM_7
Location usable for custom uniform.
Definition: ShaderApi.h:56
const int ULOC_CUSTOM_10
Location usable for custom uniform.
Definition: ShaderApi.h:59
const int ULOC_CUSTOM_17
Location usable for custom uniform.
Definition: ShaderApi.h:66
const int UBIND_LIGHTS
Uniform binding location for light structures.
Definition: ShaderApi.h:77
const int UBIND_CUSTOM_5
Uniform binding location for custom data.
Definition: ShaderApi.h:84
glm::ivec4 light_ids
Indices of lights used by this scenes.
Definition: ShaderApi.h:195
const int ULOC_RENDER_PASS
Location of integer identifier of current render system pass.
Definition: ShaderApi.h:36
const int UBIND_CUSTOM_2
Uniform binding location for custom data.
Definition: ShaderApi.h:81
Interface for writing shaders. Contains C++ definitions equivalent to GLSL definitions.
Definition: API.h:23
const int ULOC_CUSTOM_6
Location usable for custom uniform.
Definition: ShaderApi.h:55
const int ULOC_CUSTOM_18
Location usable for custom uniform.
Definition: ShaderApi.h:67
const int UBIND_CUSTOM_8
Uniform binding location for custom data.
Definition: ShaderApi.h:87
const int ULOC_CUSTOM_0
Location usable for custom uniform.
Definition: ShaderApi.h:49
const int ULOC_CUSTOM_16
Location usable for custom uniform.
Definition: ShaderApi.h:65
Definition of scene light.
Definition: ShaderApi.h:116
const int MAX_INSTANCE_COUNT
Maximal usable number of Renderer-Style pairs per scene.
Definition: ShaderApi.h:33
const int MAX_CAMERA_COUNT
Maximal usable number of cameras.
Definition: ShaderApi.h:27
int32_t camera_id
Index of a camera used by this scene.
Definition: ShaderApi.h:192
const int ULOC_CUSTOM_19
Location usable for custom uniform.
Definition: ShaderApi.h:68
const int UBIND_CUSTOM_7
Uniform binding location for custom data.
Definition: ShaderApi.h:86
const int ULOC_CUSTOM_1
Location usable for custom uniform.
Definition: ShaderApi.h:50
const int MAX_SCENE_COUNT
Maximal usable number of scenes.
Definition: ShaderApi.h:25
glm::mat4 projection
Scene projection matrix.
Definition: ShaderApi.h:188
const int ULOC_CUSTOM_4
Location usable for custom uniform.
Definition: ShaderApi.h:53
const int UBIND_CUSTOM_3
Uniform binding location for custom data.
Definition: ShaderApi.h:82
const int ULOC_CUSTOM_3
Location usable for custom uniform.
Definition: ShaderApi.h:52
const int ULOC_CUSTOM_11
Location usable for custom uniform.
Definition: ShaderApi.h:60
const int MAX_LIGHT_COUNT_PER_SCENE
Maximal usable number of lights per scene.
Definition: ShaderApi.h:31
const int UBIND_VIEW_MATRICES
Uniform binding location for camera view matrices.
Definition: ShaderApi.h:73
const int ULOC_CUSTOM_12
Location usable for custom uniform.
Definition: ShaderApi.h:61
const int ULOC_SHADOWING_METHOD
Location of integer identifier of shadowing method.
Definition: ShaderApi.h:38
Scene information wrapper.
Definition: ShaderApi.h:185
const int ULOC_CUSTOM_2
Location usable for custom uniform.
Definition: ShaderApi.h:51
const int ULOC_SCENE_ID
Location of scene index, that currently renders.
Definition: ShaderApi.h:42
glm::mat4 projection_inverse
Inverse to scene projection matrix.
Definition: ShaderApi.h:190
const int MAX_LIGHT_COUNT
Maximal usable number of lights.
Definition: ShaderApi.h:29
const int UBIND_INSTANCING_MATRICES
Uniform binding location for instance matrices.
Definition: ShaderApi.h:71
const int ULOC_CUSTOM_9
Location usable for custom uniform.
Definition: ShaderApi.h:58
Properties of a simple phong material.
Definition: ShaderApi.h:93
const int ULOC_USE_INSTANCING
Location of boolean deciding whether instanced rendering is used.
Definition: ShaderApi.h:44
Matrix and its inverse.
Definition: ShaderApi.h:176
const int ULOC_CUSTOM_13
Location usable for custom uniform.
Definition: ShaderApi.h:62
const int UBIND_CUSTOM_0
Uniform binding location for custom data.
Definition: ShaderApi.h:79
glm::ivec2 resolution
Resolution of a scene viewport.
Definition: ShaderApi.h:197
const int ULOC_CUSTOM_14
Location usable for custom uniform.
Definition: ShaderApi.h:63
const int ULOC_PRE_INSTANCING_MATRIX
Location of a pre-instance matrix.
Definition: ShaderApi.h:46