1 /* quad vertex shader */
3 const vec2 positions[4] = { vec2(0, 1), vec2(1, 1), vec2(1, 0), vec2(0, 0) };
4 const vec2 uvs[4] = { vec2(0, 0), vec2(1, 0), vec2(1, 1), vec2(0, 1) };
5 const int indices[6] = { 0, 1, 2, 0, 2, 3 };
7 layout(binding=0) uniform Game
18 int idx = indices[gl_VertexIndex];
19 vec2 pos = positions[idx];
22 vec2 inst_pos_abs = inst_pos + inst_size * pos - cam - screen / 2;
23 gl_Position = vec4(inst_pos_abs / screen * 2, 1, 1);
27 /* quad fragment shader */
29 layout(binding=0) uniform texture2D tex;
30 layout(binding=0) uniform sampler smp;
36 vec4 tex_color = texture(sampler2D(tex, smp), uv);
39 frag_color = tex_color;
43 /* quad shader program */
51 const vec2 positions[4] = { vec2(0, 1), vec2(1, 1), vec2(1, 0), vec2(0, 0) };
52 const vec2 uvs[4] = { vec2(0, 0), vec2(1, 0), vec2(1, 1), vec2(0, 1) };
53 const int indices[6] = { 0, 1, 2, 0, 2, 3 };
55 layout(binding=0) uniform Game
61 layout(binding=1) uniform Light
70 vec2 rotate(vec2 v, float a) {
73 mat2 m = mat2(c, s, -s, c);
78 int idx = indices[gl_VertexIndex];
79 vec2 pos = positions[idx];
82 if (idx == 2 || idx == 3) { // keep pos for lower vertices (base)
83 vec2 inst_pos_abs = inst_pos + inst_size * pos - cam - screen / 2;
84 gl_Position = vec4(inst_pos_abs / screen * 2, 1, 1);
87 vec2 anchor = vec2(0.5, 0);
88 vec2 anchor_abs = inst_pos + inst_size * anchor - cam - screen / 2;
89 vec2 light_pos_abs = light_pos - cam - screen / 2;
90 vec2 dir = anchor_abs - light_pos_abs;
97 vec2 inst_pos_abs = anchor_abs + dir + left_right[idx] / 2;
98 gl_Position = vec4(inst_pos_abs / screen * 2, 1, 1);
104 layout(binding=0) uniform texture2D tex;
105 layout(binding=0) uniform sampler smp;
111 vec4 tex_color = texture(sampler2D(tex, smp), uv);
112 // if (tex_color.a < 1)
114 frag_color = vec4(0, 0, 0, 1);
118 @program shadow vs_shadow fs_shadow
123 const vec2 positions[4] = { vec2(-0.5, 0.5), vec2(0.5, 0.5), vec2(0.5, -0.5), vec2(-0.5, -0.5) };
124 const int indices[6] = { 0, 1, 2, 0, 2, 3 };
126 layout(binding=0) uniform Game
135 int idx = indices[gl_VertexIndex];
136 vec2 pos = positions[idx];
138 vec2 light_size = vec2(10, 10);
140 vec2 inst_pos_abs = light_pos + light_size * pos - cam - screen / 2;
141 gl_Position = vec4(inst_pos_abs / screen * 2, 1, 1);
149 frag_color = vec4(1, 0, 0, 1);
153 @program light vs_light fs_light