A 3D game engine from scratch.
1// (c) 2020 Vlad-Stefan Harbuz <vlad@vladh.net>
2
3uniform sampler2D l_color_texture;
4uniform sampler2D bloom_texture;
5#if USE_FOG
6 uniform sampler2D l_depth_texture;
7#endif
8
9in BLOCK {
10 vec2 tex_coords;
11} fs_in;
12
13out vec4 frag_color;
14
15void main() {
16 vec3 color = texture(l_color_texture, fs_in.tex_coords).rgb;
17
18 #if USE_BLOOM
19 vec3 bloom = texture(bloom_texture, fs_in.tex_coords).rgb;
20 color += bloom / 15.0;
21 #endif
22
23 #if USE_FOG
24 float depth = texture(l_depth_texture, fs_in.tex_coords).r;
25 float linear_depth = linearize_depth(
26 depth, camera_near_clip_dist, camera_far_clip_dist
27 ) / camera_far_clip_dist;
28 float fog_term = pow(linear_depth, 3.0) * 3.0;
29 color += FOG_ALBEDO * fog_term;
30 #endif
31
32 color = add_tone_mapping(color);
33 color = correct_gamma(color);
34
35 frag_color = vec4(color, 1.0);
36}