~vladh/peony

peony/src_shaders/standard_depth.frag -rw-r--r-- 632 bytes
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
/*
  Peony Game Engine
  Copyright (C) 2020 Vlad-Stefan Harbuz <vlad@vladh.net>
  All rights reserved.
*/

in BLOCK {
  vec4 world_position;
} fs_in;

void main() {
  vec4 current_light_position;

  if (current_shadow_light_type == LIGHT_POINT) {
    current_light_position = point_light_position[current_shadow_light_idx];
  } else if (current_shadow_light_type == LIGHT_DIRECTIONAL) {
    current_light_position = directional_light_position[current_shadow_light_idx];
  }

  float light_distance = length(
    fs_in.world_position.xyz - vec3(current_light_position)
  ) / shadow_far_clip_dist;

  gl_FragDepth = light_distance;
}