~vladh/peony

peony/src_shaders/standard_depth.geom -rw-r--r-- 1.1 KiB
7fc9922bVlad-Stefan Harbuz changes shaders namespace into class a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
  Peony Game Engine
  Copyright (C) 2020 Vlad-Stefan Harbuz <vlad@vladh.net>
  All rights reserved.
*/

layout (triangles) in;
layout (triangle_strip, max_vertices=18) out;

out BLOCK {
  vec4 world_position;
} gs_out;

void main() {
  int n_faces_for_this_light;
  if (current_shadow_light_type == LIGHT_POINT) {
    n_faces_for_this_light = 6;
  } else if (current_shadow_light_type == LIGHT_DIRECTIONAL) {
    n_faces_for_this_light = 1;
  }

  for (int face = 0; face < n_faces_for_this_light; face++) {
    int layer_face = (current_shadow_light_idx * n_faces_for_this_light) + face;
    gl_Layer = layer_face;

    for (int idx = 0; idx < 3; idx++) {
      gs_out.world_position = gl_in[idx].gl_Position;

      mat4 shadow_transform;
      if (current_shadow_light_type == LIGHT_POINT) {
        shadow_transform = shadowmap_3d_transforms[layer_face];
      } else if (current_shadow_light_type == LIGHT_DIRECTIONAL) {
        shadow_transform = shadowmap_2d_transforms[layer_face];
      }

      gl_Position = shadow_transform * gs_out.world_position;
      EmitVertex();
    }

    EndPrimitive();
  }
}