3 const vec2 positions[4] = { vec2(-1, 1), vec2(1, 1), vec2(1, -1), vec2(-1, -1) };
4 const vec2 uvs[4] = { vec2(0, 1), vec2(1, 1), vec2(1, 0), vec2(0, 0) };
5 const int indices[6] = { 0, 1, 2, 0, 2, 3 };
7 layout(binding=0) uniform Game
16 int idx = indices[gl_VertexIndex];
17 vec2 pos = positions[idx];
20 gl_Position = vec4(pos, 1, 1);
25 layout(binding=0) uniform texture2D tex_tex;
26 layout(binding=1) uniform texture2D tex_shadow;
27 layout(binding=2) uniform texture2D tex_light;
28 layout(binding=0) uniform sampler smp;
35 vec4 tb = vec4(0.8,0.3,0.3,1);
36 if (mod(floor(uv.x*10), 2) != mod(floor(uv.y*10),2)) {
37 tb = vec4(0.3,0.3,0.8,1);
39 vec4 tt = texture(sampler2D(tex_tex, smp), uv);
40 vec4 ts = texture(sampler2D(tex_shadow, smp), uv);
41 vec4 tl = texture(sampler2D(tex_light, smp), uv);
43 vec3 l = tt.a * (tt.rgb * tl.rgb) + (1-tt.a) * (tl.rgb * tl.a);
44 l = ts.a * (l * ts.rgb) + (1-ts.a) * (l);
45 frag_color = vec4(l, 1);
47 vec3 a = (tb.rgb + tl.rgb) * tt.rgb * ts.rgb; // + tl.rgb * tl.a;
48 frag_color = vec4(a, 1);
51 vec3 bg = tb.rgb * tl.rgb;
52 vec3 bg_s = bg * (1-ts.a) + bg * ts.rgb * 0.5 * ts.a;
53 vec3 t = tt.rgb * tl.rgb;
54 vec3 t_s = t * (1-ts.a) + t * ts.rgb * 0.5 * ts.a;
55 vec3 bg_s_t_s = bg_s * (1-tt.a) + t_s * tt.a;
56 frag_color = vec4(bg_s_t_s, 1);
58 // frag_color = vec4(tl);
62 @program combine vs_combine fs_combine
67 const vec2 positions[4] = { vec2(0, 1), vec2(1, 1), vec2(1, 0), vec2(0, 0) };
68 const vec2 uvs[4] = { vec2(0, 0), vec2(1, 0), vec2(1, 1), vec2(0, 1) };
69 const int indices[6] = { 0, 1, 2, 0, 2, 3 };
71 layout(binding=0) uniform Game
82 int idx = indices[gl_VertexIndex];
83 vec2 pos = positions[idx];
86 vec2 inst_pos_abs = inst_pos + inst_size * pos - cam - screen / 2;
87 gl_Position = vec4(inst_pos_abs / screen * 2, 1, 1);
92 layout(binding=0) uniform texture2D tex;
93 layout(binding=0) uniform sampler smp;
99 vec4 tex_color = texture(sampler2D(tex, smp), uv);
102 frag_color = tex_color;
106 @program tex vs_tex fs_tex
111 const vec2 positions[3] = { vec2(0, 1), vec2(1, 1), vec2(0.5, 0) };
112 const vec2 uvs[3] = { vec2(0, 0), vec2(1, 0), vec2(0.5, 1) };
114 layout(binding=0) uniform Game
120 layout(binding=1) uniform Light
127 float shadow_brightness;
133 out vec3 light_color;
134 out float shadow_brightness;
136 // https://gist.github.com/yiwenl/3f804e80d0930e34a0b33359259b556c
137 vec2 rotate(vec2 v, float a) {
140 mat2 m = mat2(c, s, -s, c);
145 int idx = gl_VertexIndex;
146 vec2 pos = positions[idx];
148 light_color = light.color;
149 shadow_brightness = light.shadow_brightness;
151 if (idx == 2) { // keep pos for base
152 vec2 inst_pos_abs = inst_pos + inst_size * pos - cam - screen / 2;
153 gl_Position = vec4(inst_pos_abs / screen * 2, 1, 1);
156 vec2 anchor = vec2(0.5, 0);
157 vec2 anchor_abs = inst_pos + inst_size * anchor - cam - screen / 2;
158 vec2 light_pos_abs = light.pos - cam - screen / 2;
159 vec2 dir = anchor_abs - light_pos_abs;
161 vec2 left_right[] = {
163 rotate(dir, -1.5708),
166 float light_radius_factor = 1.5 / log(light.reach);
168 vec2 inst_pos_abs = anchor_abs + dir + left_right[idx] * light_radius_factor;
169 gl_Position = vec4(inst_pos_abs / screen * 2, 1, 1);
175 layout(binding=0) uniform texture2D tex;
176 layout(binding=0) uniform sampler smp;
180 in float shadow_brightness;
183 vec3 brighten(vec3 c, float f) {
184 vec3 d = vec3(1) - c;
188 vec4 blur(float radius, float resolution) {
189 float blur = radius/resolution;
194 vec4 sum = vec4(0.0);
196 sum += texture(sampler2D(tex, smp), vec2(uv.x - 4.0*blur*hstep, uv.y - 4.0*blur*vstep)) * 0.0162162162;
197 sum += texture(sampler2D(tex, smp), vec2(uv.x - 3.0*blur*hstep, uv.y - 3.0*blur*vstep)) * 0.0540540541;
198 sum += texture(sampler2D(tex, smp), vec2(uv.x - 2.0*blur*hstep, uv.y - 2.0*blur*vstep)) * 0.1216216216;
199 sum += texture(sampler2D(tex, smp), vec2(uv.x - 1.0*blur*hstep, uv.y - 1.0*blur*vstep)) * 0.1945945946;
201 sum += texture(sampler2D(tex, smp), vec2(uv.x, uv.y)) * 0.2270270270;
203 sum += texture(sampler2D(tex, smp), vec2(uv.x + 1.0*blur*hstep, uv.y + 1.0*blur*vstep)) * 0.1945945946;
204 sum += texture(sampler2D(tex, smp), vec2(uv.x + 2.0*blur*hstep, uv.y + 2.0*blur*vstep)) * 0.1216216216;
205 sum += texture(sampler2D(tex, smp), vec2(uv.x + 3.0*blur*hstep, uv.y + 3.0*blur*vstep)) * 0.0540540541;
206 sum += texture(sampler2D(tex, smp), vec2(uv.x + 4.0*blur*hstep, uv.y + 4.0*blur*vstep)) * 0.0162162162;
212 vec4 tex_color = blur(10, 1);
213 tex_color = texture(sampler2D(tex, smp), uv);
215 vec3 brighter = brighten(light_color, shadow_brightness);
216 frag_color = vec4(brighter * tex_color.a + vec3(1) * (1-tex_color.a), tex_color.a);
220 @program shadow vs_shadow fs_shadow
225 const vec2 positions[4] = { vec2(-0.5, 0.5), vec2(0.5, 0.5), vec2(0.5, -0.5), vec2(-0.5, -0.5) };
226 const int indices[6] = { 0, 1, 2, 0, 2, 3 };
228 layout(binding=0) uniform Game
234 layout(binding=1) uniform Light
241 float shadow_brightness;
248 out float light_intensity;
252 int idx = indices[gl_VertexIndex];
253 vec2 pos = positions[idx];
255 vec2 inst_pos_ap = light.pos + light.reach * 2 * pos;
256 vec2 inst_pos_rp = inst_pos_ap - cam - screen / 2;
257 vec2 inst_pos_rw = inst_pos_rp / screen * 2;
258 gl_Position = vec4(inst_pos_rw, 1, 1);
260 light_col = light.color;
261 light_pos = light.pos;
262 light_rea = light.reach;
263 light_glo = light.radius_glow;
264 light_intensity = light.intensity;
265 fragpos = inst_pos_ap;
270 layout(binding=0) uniform Game
280 in float light_intensity;
284 float dist(vec2 a, vec2 b) {
285 float d1 = a.x - b.x;
286 float d2 = a.y - b.y;
287 return sqrt(d1*d1 + d2*d2);
291 // vec2 frag_coord_abs = gl_FragCoord.xy * v_screen + v_cam + v_screen / 2;
292 // float factor = dist(light_pos, frag_coord_abs) / light_rad;
293 float factor_rea = 1 - (dist(light_pos, fragpos) / light_rea);
294 float factor_glo = 1 - (dist(light_pos, fragpos) / light_glo);
295 if (factor_rea > 1.0) discard;
296 frag_color = vec4(light_col.rgb * factor_rea, factor_glo * light_intensity);
297 // frag_color = vec4(vec3(mod(factor, 1.0)) * light_col, factor);
301 @program light vs_light fs_light