~vladh/peony

peony/src_shaders/postprocessing.frag -rw-r--r-- 895 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
  Peony Game Engine
  Copyright (C) 2020 Vlad-Stefan Harbuz <vlad@vladh.net>
  All rights reserved.
*/

uniform sampler2D l_color_texture;
uniform sampler2D bloom_texture;
#if USE_FOG
  uniform sampler2D l_depth_texture;
#endif

in BLOCK {
  vec2 tex_coords;
} fs_in;

out vec4 frag_color;

void main() {
  vec3 color = texture(l_color_texture, fs_in.tex_coords).rgb;

  #if USE_BLOOM
    vec3 bloom = texture(bloom_texture, fs_in.tex_coords).rgb;
    color += bloom / 15.0;
  #endif

  #if USE_FOG
    float depth = texture(l_depth_texture, fs_in.tex_coords).r;
    float linear_depth = linearize_depth(
      depth, camera_near_clip_dist, camera_far_clip_dist
    ) / camera_far_clip_dist;
    float fog_term = pow(linear_depth, 3.0) * 3.0;
    color += FOG_ALBEDO * fog_term;
  #endif

  color = add_tone_mapping(color);
  color = correct_gamma(color);

  frag_color = vec4(color, 1.0);
}