pyrender2 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. pyrender/__init__.py +24 -0
  2. pyrender/camera.py +435 -0
  3. pyrender/constants.py +149 -0
  4. pyrender/font.py +272 -0
  5. pyrender/fonts/OpenSans-Bold.ttf +0 -0
  6. pyrender/fonts/OpenSans-BoldItalic.ttf +0 -0
  7. pyrender/fonts/OpenSans-ExtraBold.ttf +0 -0
  8. pyrender/fonts/OpenSans-ExtraBoldItalic.ttf +0 -0
  9. pyrender/fonts/OpenSans-Italic.ttf +0 -0
  10. pyrender/fonts/OpenSans-Light.ttf +0 -0
  11. pyrender/fonts/OpenSans-LightItalic.ttf +0 -0
  12. pyrender/fonts/OpenSans-Regular.ttf +0 -0
  13. pyrender/fonts/OpenSans-Semibold.ttf +0 -0
  14. pyrender/fonts/OpenSans-SemiboldItalic.ttf +0 -0
  15. pyrender/light.py +382 -0
  16. pyrender/material.py +705 -0
  17. pyrender/mesh.py +328 -0
  18. pyrender/node.py +263 -0
  19. pyrender/offscreen.py +160 -0
  20. pyrender/platforms/__init__.py +6 -0
  21. pyrender/platforms/base.py +73 -0
  22. pyrender/platforms/egl.py +219 -0
  23. pyrender/platforms/osmesa.py +59 -0
  24. pyrender/platforms/pyglet_platform.py +90 -0
  25. pyrender/primitive.py +489 -0
  26. pyrender/renderer.py +1328 -0
  27. pyrender/sampler.py +102 -0
  28. pyrender/scene.py +585 -0
  29. pyrender/shader_program.py +283 -0
  30. pyrender/shaders/debug_quad.frag +23 -0
  31. pyrender/shaders/debug_quad.vert +25 -0
  32. pyrender/shaders/flat.frag +126 -0
  33. pyrender/shaders/flat.vert +86 -0
  34. pyrender/shaders/mesh.frag +456 -0
  35. pyrender/shaders/mesh.vert +86 -0
  36. pyrender/shaders/mesh_depth.frag +8 -0
  37. pyrender/shaders/mesh_depth.vert +13 -0
  38. pyrender/shaders/segmentation.frag +13 -0
  39. pyrender/shaders/segmentation.vert +14 -0
  40. pyrender/shaders/text.frag +12 -0
  41. pyrender/shaders/text.vert +12 -0
  42. pyrender/shaders/vertex_normals.frag +10 -0
  43. pyrender/shaders/vertex_normals.geom +74 -0
  44. pyrender/shaders/vertex_normals.vert +27 -0
  45. pyrender/shaders/vertex_normals_pc.geom +29 -0
  46. pyrender/texture.py +259 -0
  47. pyrender/trackball.py +216 -0
  48. pyrender/utils.py +115 -0
  49. pyrender/version.py +1 -0
  50. pyrender/viewer.py +1160 -0
  51. pyrender2-0.2.0.dist-info/METADATA +152 -0
  52. pyrender2-0.2.0.dist-info/RECORD +55 -0
  53. pyrender2-0.2.0.dist-info/WHEEL +5 -0
  54. pyrender2-0.2.0.dist-info/licenses/LICENSE +21 -0
  55. pyrender2-0.2.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,456 @@
1
+ #version 330 core
2
+ ///////////////////////////////////////////////////////////////////////////////
3
+ // Structs
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+
6
+ struct SpotLight {
7
+ vec3 color;
8
+ float intensity;
9
+ float range;
10
+ vec3 position;
11
+ vec3 direction;
12
+ float light_angle_scale;
13
+ float light_angle_offset;
14
+
15
+ #ifdef SPOT_LIGHT_SHADOWS
16
+ sampler2D shadow_map;
17
+ mat4 light_matrix;
18
+ #endif
19
+ };
20
+
21
+ struct DirectionalLight {
22
+ vec3 color;
23
+ float intensity;
24
+ vec3 direction;
25
+
26
+ #ifdef DIRECTIONAL_LIGHT_SHADOWS
27
+ sampler2D shadow_map;
28
+ mat4 light_matrix;
29
+ #endif
30
+ };
31
+
32
+ struct PointLight {
33
+ vec3 color;
34
+ float intensity;
35
+ float range;
36
+ vec3 position;
37
+
38
+ #ifdef POINT_LIGHT_SHADOWS
39
+ samplerCube shadow_map;
40
+ #endif
41
+ };
42
+
43
+ struct Material {
44
+ vec3 emissive_factor;
45
+
46
+ #ifdef USE_METALLIC_MATERIAL
47
+ vec4 base_color_factor;
48
+ float metallic_factor;
49
+ float roughness_factor;
50
+ #endif
51
+
52
+ #ifdef USE_GLOSSY_MATERIAL
53
+ vec4 diffuse_factor;
54
+ vec3 specular_factor;
55
+ float glossiness_factor;
56
+ #endif
57
+
58
+ #ifdef HAS_NORMAL_TEX
59
+ sampler2D normal_texture;
60
+ #endif
61
+ #ifdef HAS_OCCLUSION_TEX
62
+ sampler2D occlusion_texture;
63
+ #endif
64
+ #ifdef HAS_EMISSIVE_TEX
65
+ sampler2D emissive_texture;
66
+ #endif
67
+ #ifdef HAS_BASE_COLOR_TEX
68
+ sampler2D base_color_texture;
69
+ #endif
70
+ #ifdef HAS_METALLIC_ROUGHNESS_TEX
71
+ sampler2D metallic_roughness_texture;
72
+ #endif
73
+ #ifdef HAS_DIFFUSE_TEX
74
+ sampler2D diffuse_texture;
75
+ #endif
76
+ #ifdef HAS_SPECULAR_GLOSSINESS_TEX
77
+ sampler2D specular_glossiness;
78
+ #endif
79
+ };
80
+
81
+ struct PBRInfo {
82
+ float nl;
83
+ float nv;
84
+ float nh;
85
+ float lh;
86
+ float vh;
87
+ float roughness;
88
+ float metallic;
89
+ vec3 f0;
90
+ vec3 c_diff;
91
+ };
92
+
93
+ ///////////////////////////////////////////////////////////////////////////////
94
+ // Uniforms
95
+ ///////////////////////////////////////////////////////////////////////////////
96
+ uniform Material material;
97
+ uniform PointLight point_lights[MAX_POINT_LIGHTS];
98
+ uniform int n_point_lights;
99
+ uniform DirectionalLight directional_lights[MAX_DIRECTIONAL_LIGHTS];
100
+ uniform int n_directional_lights;
101
+ uniform SpotLight spot_lights[MAX_SPOT_LIGHTS];
102
+ uniform int n_spot_lights;
103
+ uniform vec3 cam_pos;
104
+ uniform vec3 ambient_light;
105
+
106
+ #ifdef USE_IBL
107
+ uniform samplerCube diffuse_env;
108
+ uniform samplerCube specular_env;
109
+ #endif
110
+
111
+ ///////////////////////////////////////////////////////////////////////////////
112
+ // Inputs
113
+ ///////////////////////////////////////////////////////////////////////////////
114
+
115
+ in vec3 frag_position;
116
+ #ifdef NORMAL_LOC
117
+ in vec3 frag_normal;
118
+ #endif
119
+ #ifdef HAS_NORMAL_TEX
120
+ #ifdef TANGENT_LOC
121
+ #ifdef NORMAL_LOC
122
+ in mat3 tbn;
123
+ #endif
124
+ #endif
125
+ #endif
126
+ #ifdef TEXCOORD_0_LOC
127
+ in vec2 uv_0;
128
+ #endif
129
+ #ifdef TEXCOORD_1_LOC
130
+ in vec2 uv_1;
131
+ #endif
132
+ #ifdef COLOR_0_LOC
133
+ in vec4 color_multiplier;
134
+ #endif
135
+
136
+ ///////////////////////////////////////////////////////////////////////////////
137
+ // OUTPUTS
138
+ ///////////////////////////////////////////////////////////////////////////////
139
+
140
+ out vec4 frag_color;
141
+
142
+ ///////////////////////////////////////////////////////////////////////////////
143
+ // Constants
144
+ ///////////////////////////////////////////////////////////////////////////////
145
+ const float PI = 3.141592653589793;
146
+ const float min_roughness = 0.04;
147
+
148
+ ///////////////////////////////////////////////////////////////////////////////
149
+ // Utility Functions
150
+ ///////////////////////////////////////////////////////////////////////////////
151
+ vec4 srgb_to_linear(vec4 srgb)
152
+ {
153
+ #ifndef SRGB_CORRECTED
154
+ // Fast Approximation
155
+ //vec3 linOut = pow(srgbIn.xyz,vec3(2.2));
156
+ //
157
+ vec3 b_less = step(vec3(0.04045),srgb.xyz);
158
+ vec3 lin_out = mix( srgb.xyz/vec3(12.92), pow((srgb.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), b_less );
159
+ return vec4(lin_out, srgb.w);
160
+ #else
161
+ return srgb;
162
+ #endif
163
+ }
164
+
165
+ // Normal computation
166
+ vec3 get_normal()
167
+ {
168
+ #ifdef HAS_NORMAL_TEX
169
+
170
+ #ifndef HAS_TANGENTS
171
+ vec3 pos_dx = dFdx(frag_position);
172
+ vec3 pos_dy = dFdy(frag_position);
173
+ vec3 tex_dx = dFdx(vec3(uv_0, 0.0));
174
+ vec3 tex_dy = dFdy(vec3(uv_0, 0.0));
175
+ vec3 t = (tex_dy.t * pos_dx - tex_dx.t * pos_dy) / (tex_dx.s * tex_dy.t - tex_dy.s * tex_dx.t);
176
+
177
+ #ifdef NORMAL_LOC
178
+ vec3 ng = normalize(frag_normal);
179
+ #else
180
+ vec3 = cross(pos_dx, pos_dy);
181
+ #endif
182
+
183
+ t = normalize(t - ng * dot(ng, t));
184
+ vec3 b = normalize(cross(ng, t));
185
+ mat3 tbn_n = mat3(t, b, ng);
186
+
187
+ #else
188
+
189
+ mat3 tbn_n = tbn;
190
+
191
+ #endif
192
+
193
+ vec3 n = texture(material.normal_texture, uv_0).rgb;
194
+ n = normalize(tbn_n * ((2.0 * n - 1.0) * vec3(1.0, 1.0, 1.0)));
195
+ return n; // TODO NORMAL MAPPING
196
+
197
+ #else
198
+
199
+ #ifdef NORMAL_LOC
200
+ return frag_normal;
201
+ #else
202
+ return normalize(cam_pos - frag_position);
203
+ #endif
204
+
205
+ #endif
206
+ }
207
+
208
+ // Fresnel
209
+ vec3 specular_reflection(PBRInfo info)
210
+ {
211
+ vec3 res = info.f0 + (1.0 - info.f0) * pow(clamp(1.0 - info.vh, 0.0, 1.0), 5.0);
212
+ return res;
213
+ }
214
+
215
+ // Smith
216
+ float geometric_occlusion(PBRInfo info)
217
+ {
218
+ float r = info.roughness + 1.0;
219
+ float k = r * r / 8.0;
220
+ float g1 = info.nv / (info.nv * (1.0 - k) + k);
221
+ float g2 = info.nl / (info.nl * (1.0 - k) + k);
222
+ //float k = info.roughness * sqrt(2.0 / PI);
223
+ //float g1 = info.lh / (info.lh * (1.0 - k) + k);
224
+ //float g2 = info.nh / (info.nh * (1.0 - k) + k);
225
+ return g1 * g2;
226
+ }
227
+
228
+ float microfacet_distribution(PBRInfo info)
229
+ {
230
+ float a = info.roughness * info.roughness;
231
+ float a2 = a * a;
232
+ float nh2 = info.nh * info.nh;
233
+
234
+ float denom = (nh2 * (a2 - 1.0) + 1.0);
235
+ return a2 / (PI * denom * denom);
236
+ }
237
+
238
+ vec3 compute_brdf(vec3 n, vec3 v, vec3 l,
239
+ float roughness, float metalness,
240
+ vec3 f0, vec3 c_diff, vec3 albedo,
241
+ vec3 radiance)
242
+ {
243
+ vec3 h = normalize(l+v);
244
+ float nl = clamp(dot(n, l), 0.001, 1.0);
245
+ float nv = clamp(abs(dot(n, v)), 0.001, 1.0);
246
+ float nh = clamp(dot(n, h), 0.0, 1.0);
247
+ float lh = clamp(dot(l, h), 0.0, 1.0);
248
+ float vh = clamp(dot(v, h), 0.0, 1.0);
249
+
250
+ PBRInfo info = PBRInfo(nl, nv, nh, lh, vh, roughness, metalness, f0, c_diff);
251
+
252
+ // Compute PBR terms
253
+ vec3 F = specular_reflection(info);
254
+ float G = geometric_occlusion(info);
255
+ float D = microfacet_distribution(info);
256
+
257
+ // Compute BRDF
258
+ vec3 diffuse_contrib = (1.0 - F) * c_diff / PI;
259
+ vec3 spec_contrib = F * G * D / (4.0 * nl * nv + 0.001);
260
+
261
+ vec3 color = nl * radiance * (diffuse_contrib + spec_contrib);
262
+ return color;
263
+ }
264
+
265
+ float texture2DCompare(sampler2D depths, vec2 uv, float compare) {
266
+ return compare > texture(depths, uv.xy).r ? 1.0 : 0.0;
267
+ }
268
+
269
+ float texture2DShadowLerp(sampler2D depths, vec2 size, vec2 uv, float compare) {
270
+ vec2 texelSize = vec2(1.0)/size;
271
+ vec2 f = fract(uv*size+0.5);
272
+ vec2 centroidUV = floor(uv*size+0.5)/size;
273
+
274
+ float lb = texture2DCompare(depths, centroidUV+texelSize*vec2(0.0, 0.0), compare);
275
+ float lt = texture2DCompare(depths, centroidUV+texelSize*vec2(0.0, 1.0), compare);
276
+ float rb = texture2DCompare(depths, centroidUV+texelSize*vec2(1.0, 0.0), compare);
277
+ float rt = texture2DCompare(depths, centroidUV+texelSize*vec2(1.0, 1.0), compare);
278
+ float a = mix(lb, lt, f.y);
279
+ float b = mix(rb, rt, f.y);
280
+ float c = mix(a, b, f.x);
281
+ return c;
282
+ }
283
+
284
+ float PCF(sampler2D depths, vec2 size, vec2 uv, float compare){
285
+ float result = 0.0;
286
+ for(int x=-1; x<=1; x++){
287
+ for(int y=-1; y<=1; y++){
288
+ vec2 off = vec2(x,y)/size;
289
+ result += texture2DShadowLerp(depths, size, uv+off, compare);
290
+ }
291
+ }
292
+ return result/9.0;
293
+ }
294
+
295
+ float shadow_calc(mat4 light_matrix, sampler2D shadow_map, float nl)
296
+ {
297
+ // Compute light texture UV coords
298
+ vec4 proj_coords = vec4(light_matrix * vec4(frag_position.xyz, 1.0));
299
+ vec3 light_coords = proj_coords.xyz / proj_coords.w;
300
+ light_coords = light_coords * 0.5 + 0.5;
301
+ float current_depth = light_coords.z;
302
+ float bias = max(0.001 * (1.0 - nl), 0.0001) / proj_coords.w;
303
+ float compare = (current_depth - bias);
304
+ float shadow = PCF(shadow_map, textureSize(shadow_map, 0), light_coords.xy, compare);
305
+ if (light_coords.z > 1.0) {
306
+ shadow = 0.0;
307
+ }
308
+ return shadow;
309
+ }
310
+
311
+ ///////////////////////////////////////////////////////////////////////////////
312
+ // MAIN
313
+ ///////////////////////////////////////////////////////////////////////////////
314
+ void main()
315
+ {
316
+
317
+ vec4 color = vec4(vec3(0.0), 1.0);
318
+ ///////////////////////////////////////////////////////////////////////////////
319
+ // Handle Metallic Materials
320
+ ///////////////////////////////////////////////////////////////////////////////
321
+ #ifdef USE_METALLIC_MATERIAL
322
+
323
+ // Compute metallic/roughness factors
324
+ float roughness = material.roughness_factor;
325
+ float metallic = material.metallic_factor;
326
+ #ifdef HAS_METALLIC_ROUGHNESS_TEX
327
+ vec2 mr = texture(material.metallic_roughness_texture, uv_0).rg;
328
+ roughness = roughness * mr.r;
329
+ metallic = metallic * mr.g;
330
+ #endif
331
+ roughness = clamp(roughness, min_roughness, 1.0);
332
+ metallic = clamp(metallic, 0.0, 1.0);
333
+ // In convention, material roughness is perceputal roughness ^ 2
334
+ float alpha_roughness = roughness * roughness;
335
+
336
+ // Compute albedo
337
+ vec4 base_color = material.base_color_factor;
338
+ #ifdef HAS_BASE_COLOR_TEX
339
+ base_color = base_color * srgb_to_linear(texture(material.base_color_texture, uv_0));
340
+ #endif
341
+
342
+ // Compute specular and diffuse colors
343
+ vec3 dialectric_spec = vec3(min_roughness);
344
+ vec3 c_diff = mix(vec3(0.0), base_color.rgb * (1 - min_roughness), 1.0 - metallic);
345
+ vec3 f0 = mix(dialectric_spec, base_color.rgb, metallic);
346
+
347
+ // Compute normal
348
+ vec3 n = normalize(get_normal());
349
+
350
+ // Loop over lights
351
+ for (int i = 0; i < n_directional_lights; i++) {
352
+ vec3 direction = directional_lights[i].direction;
353
+ vec3 v = normalize(cam_pos - frag_position); // Vector towards camera
354
+ vec3 l = normalize(-1.0 * direction); // Vector towards light
355
+
356
+ // Compute attenuation and radiance
357
+ float attenuation = directional_lights[i].intensity;
358
+ vec3 radiance = attenuation * directional_lights[i].color;
359
+
360
+ // Compute outbound color
361
+ vec3 res = compute_brdf(n, v, l, roughness, metallic,
362
+ f0, c_diff, base_color.rgb, radiance);
363
+
364
+ // Compute shadow
365
+ #ifdef DIRECTIONAL_LIGHT_SHADOWS
366
+ float nl = clamp(dot(n,l), 0.0, 1.0);
367
+ float shadow = shadow_calc(
368
+ directional_lights[i].light_matrix,
369
+ directional_lights[i].shadow_map,
370
+ nl
371
+ );
372
+ res = res * (1.0 - shadow);
373
+ #endif
374
+ color.xyz += res;
375
+ }
376
+
377
+ for (int i = 0; i < n_point_lights; i++) {
378
+ vec3 position = point_lights[i].position;
379
+ vec3 v = normalize(cam_pos - frag_position); // Vector towards camera
380
+ vec3 l = normalize(position - frag_position); // Vector towards light
381
+
382
+ // Compute attenuation and radiance
383
+ float dist = length(position - frag_position);
384
+ float attenuation = point_lights[i].intensity / (dist * dist);
385
+ vec3 radiance = attenuation * point_lights[i].color;
386
+
387
+ // Compute outbound color
388
+ vec3 res = compute_brdf(n, v, l, roughness, metallic,
389
+ f0, c_diff, base_color.rgb, radiance);
390
+ color.xyz += res;
391
+ }
392
+ for (int i = 0; i < n_spot_lights; i++) {
393
+ vec3 position = spot_lights[i].position;
394
+ vec3 v = normalize(cam_pos - frag_position); // Vector towards camera
395
+ vec3 l = normalize(position - frag_position); // Vector towards light
396
+
397
+ // Compute attenuation and radiance
398
+ vec3 direction = spot_lights[i].direction;
399
+ float las = spot_lights[i].light_angle_scale;
400
+ float lao = spot_lights[i].light_angle_offset;
401
+ float dist = length(position - frag_position);
402
+ float cd = clamp(dot(direction, -l), 0.0, 1.0);
403
+ float attenuation = clamp(cd * las + lao, 0.0, 1.0);
404
+ attenuation = attenuation * attenuation * spot_lights[i].intensity;
405
+ attenuation = attenuation / (dist * dist);
406
+ vec3 radiance = attenuation * spot_lights[i].color;
407
+
408
+ // Compute outbound color
409
+ vec3 res = compute_brdf(n, v, l, roughness, metallic,
410
+ f0, c_diff, base_color.rgb, radiance);
411
+ #ifdef SPOT_LIGHT_SHADOWS
412
+ float nl = clamp(dot(n,l), 0.0, 1.0);
413
+ float shadow = shadow_calc(
414
+ spot_lights[i].light_matrix,
415
+ spot_lights[i].shadow_map,
416
+ nl
417
+ );
418
+ res = res * (1.0 - shadow);
419
+ #endif
420
+ color.xyz += res;
421
+ }
422
+ color.xyz += base_color.xyz * ambient_light;
423
+
424
+ // Calculate lighting from environment
425
+ #ifdef USE_IBL
426
+ // TODO
427
+ #endif
428
+
429
+ // Apply occlusion
430
+ #ifdef HAS_OCCLUSION_TEX
431
+ float ao = texture(material.occlusion_texture, uv_0).r;
432
+ color.xyz *= ao;
433
+ #endif
434
+
435
+ // Apply emissive map
436
+ vec3 emissive = material.emissive_factor;
437
+ #ifdef HAS_EMISSIVE_TEX
438
+ emissive *= srgb_to_linear(texture(material.emissive_texture, uv_0)).rgb;
439
+ #endif
440
+ color.xyz += emissive * material.emissive_factor;
441
+
442
+ #ifdef COLOR_0_LOC
443
+ color *= color_multiplier;
444
+ #endif
445
+
446
+ frag_color = clamp(vec4(pow(color.xyz, vec3(1.0/2.2)), color.a * base_color.a), 0.0, 1.0);
447
+
448
+ #else
449
+ // TODO GLOSSY MATERIAL BRDF
450
+ #endif
451
+
452
+ ///////////////////////////////////////////////////////////////////////////////
453
+ // Handle Glossy Materials
454
+ ///////////////////////////////////////////////////////////////////////////////
455
+
456
+ }
@@ -0,0 +1,86 @@
1
+ #version 330 core
2
+
3
+ // Vertex Attributes
4
+ layout(location = 0) in vec3 position;
5
+ #ifdef NORMAL_LOC
6
+ layout(location = NORMAL_LOC) in vec3 normal;
7
+ #endif
8
+ #ifdef TANGENT_LOC
9
+ layout(location = TANGENT_LOC) in vec4 tangent;
10
+ #endif
11
+ #ifdef TEXCOORD_0_LOC
12
+ layout(location = TEXCOORD_0_LOC) in vec2 texcoord_0;
13
+ #endif
14
+ #ifdef TEXCOORD_1_LOC
15
+ layout(location = TEXCOORD_1_LOC) in vec2 texcoord_1;
16
+ #endif
17
+ #ifdef COLOR_0_LOC
18
+ layout(location = COLOR_0_LOC) in vec4 color_0;
19
+ #endif
20
+ #ifdef JOINTS_0_LOC
21
+ layout(location = JOINTS_0_LOC) in vec4 joints_0;
22
+ #endif
23
+ #ifdef WEIGHTS_0_LOC
24
+ layout(location = WEIGHTS_0_LOC) in vec4 weights_0;
25
+ #endif
26
+ layout(location = INST_M_LOC) in mat4 inst_m;
27
+
28
+ // Uniforms
29
+ uniform mat4 M;
30
+ uniform mat4 V;
31
+ uniform mat4 P;
32
+
33
+ // Outputs
34
+ out vec3 frag_position;
35
+ #ifdef NORMAL_LOC
36
+ out vec3 frag_normal;
37
+ #endif
38
+ #ifdef HAS_NORMAL_TEX
39
+ #ifdef TANGENT_LOC
40
+ #ifdef NORMAL_LOC
41
+ out mat3 tbn;
42
+ #endif
43
+ #endif
44
+ #endif
45
+ #ifdef TEXCOORD_0_LOC
46
+ out vec2 uv_0;
47
+ #endif
48
+ #ifdef TEXCOORD_1_LOC
49
+ out vec2 uv_1;
50
+ #endif
51
+ #ifdef COLOR_0_LOC
52
+ out vec4 color_multiplier;
53
+ #endif
54
+
55
+
56
+ void main()
57
+ {
58
+ gl_Position = P * V * M * inst_m * vec4(position, 1);
59
+ frag_position = vec3(M * inst_m * vec4(position, 1.0));
60
+
61
+ mat4 N = transpose(inverse(M * inst_m));
62
+
63
+ #ifdef NORMAL_LOC
64
+ frag_normal = normalize(vec3(N * vec4(normal, 0.0)));
65
+ #endif
66
+
67
+ #ifdef HAS_NORMAL_TEX
68
+ #ifdef TANGENT_LOC
69
+ #ifdef NORMAL_LOC
70
+ vec3 normal_w = normalize(vec3(N * vec4(normal, 0.0)));
71
+ vec3 tangent_w = normalize(vec3(N * vec4(tangent.xyz, 0.0)));
72
+ vec3 bitangent_w = cross(normal_w, tangent_w) * tangent.w;
73
+ tbn = mat3(tangent_w, bitangent_w, normal_w);
74
+ #endif
75
+ #endif
76
+ #endif
77
+ #ifdef TEXCOORD_0_LOC
78
+ uv_0 = texcoord_0;
79
+ #endif
80
+ #ifdef TEXCOORD_1_LOC
81
+ uv_1 = texcoord_1;
82
+ #endif
83
+ #ifdef COLOR_0_LOC
84
+ color_multiplier = color_0;
85
+ #endif
86
+ }
@@ -0,0 +1,8 @@
1
+ #version 330 core
2
+
3
+ out vec4 frag_color;
4
+
5
+ void main()
6
+ {
7
+ frag_color = vec4(1.0);
8
+ }
@@ -0,0 +1,13 @@
1
+ #version 330 core
2
+ layout(location = 0) in vec3 position;
3
+ layout(location = INST_M_LOC) in mat4 inst_m;
4
+
5
+ uniform mat4 P;
6
+ uniform mat4 V;
7
+ uniform mat4 M;
8
+
9
+ void main()
10
+ {
11
+ mat4 light_matrix = P * V;
12
+ gl_Position = light_matrix * M * inst_m * vec4(position, 1.0);
13
+ }
@@ -0,0 +1,13 @@
1
+ #version 330 core
2
+
3
+ uniform vec3 color;
4
+ out vec4 frag_color;
5
+
6
+ ///////////////////////////////////////////////////////////////////////////////
7
+ // MAIN
8
+ ///////////////////////////////////////////////////////////////////////////////
9
+ void main()
10
+ {
11
+ frag_color = vec4(color, 1.0);
12
+ //frag_color = vec4(1.0, 0.5, 0.5, 1.0);
13
+ }
@@ -0,0 +1,14 @@
1
+ #version 330 core
2
+ layout(location = 0) in vec3 position;
3
+ layout(location = INST_M_LOC) in mat4 inst_m;
4
+
5
+ uniform mat4 P;
6
+ uniform mat4 V;
7
+ uniform mat4 M;
8
+
9
+ void main()
10
+ {
11
+ mat4 light_matrix = P * V;
12
+ gl_Position = light_matrix * M * inst_m * vec4(position, 1.0);
13
+ }
14
+
@@ -0,0 +1,12 @@
1
+ #version 330 core
2
+ in vec2 uv;
3
+ out vec4 color;
4
+
5
+ uniform sampler2D text;
6
+ uniform vec4 text_color;
7
+
8
+ void main()
9
+ {
10
+ vec4 sampled = vec4(1.0, 1.0, 1.0, texture(text, uv).r);
11
+ color = text_color * sampled;
12
+ }
@@ -0,0 +1,12 @@
1
+ #version 330 core
2
+ layout (location = 0) in vec4 vertex;
3
+
4
+ out vec2 uv;
5
+
6
+ uniform mat4 projection;
7
+
8
+ void main()
9
+ {
10
+ gl_Position = projection * vec4(vertex.xy, 0.0, 1.0);
11
+ uv = vertex.zw;
12
+ }
@@ -0,0 +1,10 @@
1
+ #version 330 core
2
+
3
+ out vec4 frag_color;
4
+
5
+ uniform vec4 normal_color;
6
+
7
+ void main()
8
+ {
9
+ frag_color = normal_color;
10
+ }