~vladh/peony

peony/src_shaders/normal_visualizer.geom -rw-r--r-- 2.9 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
  Peony Game Engine
  Copyright (C) 2020 Vlad-Stefan Harbuz <vlad@vladh.net>
  All rights reserved.
*/

layout (triangles) in;
layout (line_strip, max_vertices=32) out;

in BLOCK {
  vec3 world_position;
  vec2 screen_position;
  vec3 normal;
  vec3 bitangent;
  vec3 tangent;
  vec2 tex_coords;
} gs_in[3];

out BLOCK {
  vec3 world_position;
  vec2 screen_position;
  vec3 normal;
  vec3 bitangent;
  vec3 tangent;
  vec2 tex_coords;
} gs_out;

void main() {
  float normal_length = 0.1;

  for (int idx = 0; idx < 3; idx++) {
    vec3 P = gs_in[idx].world_position.xyz;
    vec3 N = gs_in[idx].normal.xyz;

    gl_Position = projection * view * vec4(P, 1.0);
    gs_out.world_position = gs_in[idx].world_position;
    gs_out.screen_position = gs_in[idx].screen_position;
    gs_out.normal = gs_in[idx].normal;
    gs_out.bitangent = gs_in[idx].bitangent;
    gs_out.tangent = gs_in[idx].tangent;
    gs_out.tex_coords = gs_in[idx].tex_coords;
    EmitVertex();

    gl_Position = projection * view * vec4(P + N * normal_length, 1.0);
    gs_out.normal = vec3(0.0, 0.0, 0.0);
    EmitVertex();

    EndPrimitive();
  }

  for (int idx = 0; idx < 3; idx++) {
    vec3 P = gs_in[idx].world_position.xyz;
    vec3 N = gs_in[idx].tangent.xyz;

    gl_Position = projection * view * vec4(P, 1.0);
    gs_out.world_position = gs_in[idx].world_position;
    gs_out.screen_position = gs_in[idx].screen_position;
    gs_out.normal = gs_in[idx].normal;
    gs_out.bitangent = gs_in[idx].bitangent;
    gs_out.tangent = gs_in[idx].tangent;
    gs_out.tex_coords = gs_in[idx].tex_coords;
    EmitVertex();

    gl_Position = projection * view * vec4(P + N * normal_length, 1.0);
    gs_out.normal = vec3(0.0, 0.0, 0.0);
    EmitVertex();

    EndPrimitive();
  }

  for (int idx = 0; idx < 3; idx++) {
    vec3 P = gs_in[idx].world_position.xyz;
    vec3 N = gs_in[idx].bitangent.xyz;

    gl_Position = projection * view * vec4(P, 1.0);
    gs_out.world_position = gs_in[idx].world_position;
    gs_out.screen_position = gs_in[idx].screen_position;
    gs_out.normal = gs_in[idx].normal;
    gs_out.bitangent = gs_in[idx].bitangent;
    gs_out.tangent = gs_in[idx].tangent;
    gs_out.tex_coords = gs_in[idx].tex_coords;
    EmitVertex();

    gl_Position = projection * view * vec4(P + N * normal_length, 1.0);
    gs_out.normal = vec3(0.0, 0.0, 0.0);
    EmitVertex();

    EndPrimitive();
  }

  for (int idx = 0; idx < 4; idx++) {
    vec3 P = gs_in[idx % 3].world_position.xyz;
    vec3 N = gs_in[idx % 3].normal.xyz;

    gl_Position = projection * view * vec4(P, 1.0);
    gs_out.world_position = gs_in[idx % 3].world_position;
    gs_out.screen_position = gs_in[idx % 3].screen_position;
    gs_out.normal = gs_in[idx % 3].normal;
    gs_out.bitangent = gs_in[idx % 3].bitangent;
    gs_out.tangent = gs_in[idx % 3].tangent;
    gs_out.tex_coords = gs_in[idx % 3].tex_coords;
    EmitVertex();
  }
  EndPrimitive();
}