~vladh/peony

peony/src_shaders/renderdebug.frag -rw-r--r-- 2.5 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
  Peony Game Engine
  Copyright (C) 2020 Vlad-Stefan Harbuz <vlad@vladh.net>
  All rights reserved.
*/

uniform sampler2D g_position_texture;
uniform sampler2D g_normal_texture;
uniform sampler2D g_albedo_texture;
uniform sampler2D g_pbr_texture;

uniform sampler2D l_color_texture;
uniform sampler2D l_bright_color_texture;
uniform sampler2D l_depth_texture;

uniform sampler2D blur1_texture;
uniform sampler2D blur2_texture;

in BLOCK {
  vec2 tex_coords;
} fs_in;

out vec4 frag_color;

void main() {
  if (renderdebug_displayed_texture_type == TEXTURETYPE_NONE) {
    discard;
  }

  float preview_screen_proportion = 1.0;
  float aspect_ratio = window_width / window_height;
  vec2 preview_size = vec2(
    preview_screen_proportion,
    preview_screen_proportion / aspect_ratio
  );

  if (
    fs_in.tex_coords.x < preview_size.x &&
    fs_in.tex_coords.y < preview_size.y
  ) {
    vec2 preview_tex_coords = fs_in.tex_coords / preview_size;
    vec2 sample_p = preview_tex_coords;

    vec3 color;
    if (renderdebug_displayed_texture_type == TEXTURETYPE_G_POSITION) {
      color = vec3(texture(g_position_texture, sample_p));
    } else if (renderdebug_displayed_texture_type == TEXTURETYPE_G_NORMAL) {
      color = vec3(texture(g_normal_texture, sample_p));
    } else if (renderdebug_displayed_texture_type == TEXTURETYPE_G_ALBEDO) {
      color = vec3(texture(g_albedo_texture, sample_p));
    } else if (renderdebug_displayed_texture_type == TEXTURETYPE_G_PBR) {
      color = vec3(texture(g_pbr_texture, sample_p));
    } else if (renderdebug_displayed_texture_type == TEXTURETYPE_L_COLOR) {
      color = vec3(texture(l_color_texture, sample_p));
    } else if (renderdebug_displayed_texture_type == TEXTURETYPE_L_BRIGHT_COLOR) {
      color = vec3(texture(l_bright_color_texture, sample_p));
    } else if (renderdebug_displayed_texture_type == TEXTURETYPE_L_DEPTH) {
      color = vec3(texture(l_depth_texture, sample_p));
    } else if (renderdebug_displayed_texture_type == TEXTURETYPE_BLUR1) {
      color = vec3(texture(blur1_texture, sample_p));
    } else if (renderdebug_displayed_texture_type == TEXTURETYPE_BLUR2) {
      color = vec3(texture(blur2_texture, sample_p));
    } else if (renderdebug_displayed_texture_type == TEXTURETYPE_SHADOWMAPS_3D) {
      color = texture(shadowmaps_3d, vec4(sample_p, 0.0, 0.0)).rrr;
    } else if (renderdebug_displayed_texture_type == TEXTURETYPE_SHADOWMAPS_2D) {
      color = texture(shadowmaps_2d, vec3(sample_p, 0.0)).rrr;
    }

    frag_color = vec4(color, 1.0);
  } else {
    discard;
  }
}