Archived
1
0
Fork 0

first and last commit

This commit is contained in:
Sen 2025-09-02 14:43:36 +02:00
commit c9e78fd810
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
381 changed files with 37141 additions and 0 deletions

9
shaders/blit.fsh Normal file
View file

@ -0,0 +1,9 @@
out vec4 FragColor;
in vec2 tex_coord;
uniform sampler2D tex;
void main() {
FragColor = texture(tex, tex_coord);
}

8
shaders/blit.vsh Normal file
View file

@ -0,0 +1,8 @@
layout (location = 0) in vec2 coords;
out vec2 tex_coord;
void main() {
tex_coord = coords;
gl_Position = vec4(coords * 2.0 - 1.0, 0.0, 1.0);
}

38
shaders/grid.fsh Normal file
View file

@ -0,0 +1,38 @@
out vec4 FragColor;
in vec3 vertex;
in vec2 tex_coord;
uniform float time;
#define GLM_PI 3.14159265358979323846264338327950288
#define GLM_SQRT2 1.41421356237309504880168872420969808
#define vis_div 24.0
float v2rand(vec2 uv) {
return fract(sin(dot(uv, vec2(12.9898,78.233))) * 43758.5453123);
}
float avg(vec4 v) {
return ((v.r + v.g + v.b) / 3.0) * v.a;
}
float gauss(float v, float b, float c) {
return (1.0 / (c * sqrt(2.0 * GLM_PI))) * exp(-(pow(v - b, 2.0) / (2.0 * pow(c, 2.0))));
}
float dgauss(float v, float b, float c) {
return b + v * c;
}
float inside(vec2 vec, vec2 offs, float a, float b, float scale, float x1, float x2, float y1, float y2) {
vec2 cscaled = (mod(vec + offs + 1.0, 1.0)) * scale;
return (x2 < x1 ? (cscaled.x >= x1 || cscaled.x <= x2) : (cscaled.x >= x1 && cscaled.x <= x2)) || (y2 < y1 ? (cscaled.y >= y1 || cscaled.y <= y2) : (cscaled.y >= y1 && cscaled.y <= y2)) || (abs(cscaled.y - (cscaled.x - (x2 < x1 ? (x1 - x2) : (x2 - x1)) * GLM_SQRT2 * (x2 < x1 ? 0.0 : (x1 < scale / 2.0 ? x1 : (x2 - scale))))) < GLM_SQRT2) ? b : a;
}
void main() {
vec2 shift = vec2(v2rand(tex_coord + fract(time)) * 2.0 - 1.0, v2rand(tex_coord + 0.5 + fract(time)) * 2.0 - 1.0);
shift = vec2(dgauss(shift.x, 0.0, 1.0), dgauss(shift.y, 0.0, 1.0)) * 0.015;
vec3 cl = vec3(inside(tex_coord / vis_div, shift, 0.0, 1.0, 64.0, 1.0, 3.0, 1.0, 3.0), inside(tex_coord / vis_div, shift, 0.0, 1.0, 64.0, 63.0, 1.0, 63.0, 1.0), inside(tex_coord / vis_div, shift, 0.0, 1.0, 64.0, 61.0, 63.0, 61.0, 63.0));
FragColor = vec4(mix(vec3(0.0, 0.0, clamp(0.1 + 0.2 * (vertex.y + 64.0) / 128.0, 0.0, 1.0)), cl, clamp(cl.x + cl.y + cl.z, 0.0, 1.0)), 1.0);
}

16
shaders/grid.vsh Normal file
View file

@ -0,0 +1,16 @@
layout (location = 0) in vec3 pos;
layout (location = 1) in vec3 norm;
layout (location = 2) in vec2 coord;
out vec3 vertex;
out vec2 tex_coord;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main() {
vertex = vec3(model * vec4(pos, 1.0));
tex_coord = coord;
gl_Position = projection * view * vec4(vertex, 1.0);
}

8
shaders/lightmap.fsh Normal file
View file

@ -0,0 +1,8 @@
out vec4 FragColor;
uniform float fog;
uniform vec3 color;
void main() {
FragColor = vec4(color, fog);
}

7
shaders/lightmap.vsh Normal file
View file

@ -0,0 +1,7 @@
layout (location = 0) in vec2 coords;
uniform vec2 size;
void main() {
gl_Position = vec4(coords * 2.0 / size, 0.0, 1.0);
}

20
shaders/rect.fsh Normal file
View file

@ -0,0 +1,20 @@
out vec4 FragColor;
in vec2 tex_coord;
uniform vec2 size;
uniform sampler2D tex;
uniform bool use_tex;
uniform float border;
uniform vec4 fill_t;
uniform vec4 fill_b;
uniform vec4 border_t;
uniform vec4 border_b;
void main() {
vec2 tex_pos = tex_coord * size;
if(tex_pos.x < border || tex_pos.x > (size.x - border) || tex_pos.y < border || tex_pos.y > (size.y - border))
FragColor = mix(border_t, border_b, tex_coord.y);
else
FragColor = (use_tex ? texture(tex, (tex_coord - (border / size)) * (size / (size - (border * 2.0)))) : vec4(1.0)) * mix(fill_t, fill_b, tex_coord.y);
}

12
shaders/rect.vsh Normal file
View file

@ -0,0 +1,12 @@
layout (location = 0) in vec2 coords;
out vec2 tex_coord;
uniform vec2 screen;
uniform vec2 offset;
uniform vec2 size;
void main() {
tex_coord = coords;
gl_Position = vec4((vec2(offset.x, screen.y - offset.y) + (coords * vec2(size.x, -size.y))) / screen * 2.0 - 1.0, 0.0, 1.0);
}

35
shaders/text.fsh Normal file
View file

@ -0,0 +1,35 @@
out vec4 FragColor;
in vec2 tex_coord;
uniform vec2 font_size;
uniform vec4 pad;
uniform vec4 glyph;
uniform vec4 color;
uniform vec4 back;
uniform sampler2D tex;
uniform int flags;
uniform int ch_index;
uniform float time;
#define FLAG_UL 0x01
#define FLAG_CL 0x02
#define FLAG_BL 0x04
#define FLAG_FD 0x08
void main() {
vec2 tex_pos = glyph.st - pad.st + tex_coord * ((glyph.pq + pad.pq) - (glyph.st - pad.st));
if((flags & FLAG_CL) != 0 && tex_pos.y >= floor(font_size.y / 2.0) && tex_pos.y < (floor(font_size.y / 2.0) + 1.0))
FragColor = vec4(0.25, 0.25, 0.25, color.a);
else if((flags & FLAG_UL) != 0 && tex_pos.y >= (font_size.y - 2.0) && tex_pos.y < (font_size.y - 1.0))
FragColor = vec4(0.95, 0.1, 0.1, color.a);
else if(tex_pos.x < glyph.s || tex_pos.x > glyph.p || tex_pos.y < glyph.t || tex_pos.y > glyph.q)
FragColor = vec4(0.0);
else
FragColor = texture(tex, (vec2(float(ch_index & 15), float((ch_index >> 4) & 15)) + (tex_pos / font_size)) / 16.0) * color;
if((flags & FLAG_BL) != 0 && fract(time) >= 0.5)
FragColor = vec4(0.0, 1.0, 0.0, FragColor.a);
if((flags & FLAG_FD) != 0)
FragColor = mix(FragColor, vec4(1.0, 1.0, 1.0, FragColor.a), sin(radians(fract(time + tex_coord.y) * 360.0)) * 0.5 + 0.5);
FragColor = mix(back, FragColor, FragColor.a);
}

12
shaders/text.vsh Normal file
View file

@ -0,0 +1,12 @@
layout (location = 0) in vec2 coords;
out vec2 tex_coord;
uniform vec2 screen;
uniform vec2 offset;
uniform vec2 size;
void main() {
tex_coord = coords;
gl_Position = vec4((vec2(offset.x, screen.y - offset.y) + (coords * vec2(size.x, -size.y))) / screen * 2.0 - 1.0, 0.0, 1.0);
}

7
shaders/vis.fsh Normal file
View file

@ -0,0 +1,7 @@
out vec4 FragColor;
in float ypos;
void main() {
FragColor = vec4(clamp(-0.3 + 1.8 * (ypos + 64.0) / 128.0, 0.0, 1.0), clamp(-0.7 + 2.2 * (ypos + 64.0) / 128.0, 0.0, 1.0), clamp(0.1 + 2.0 * (ypos + 64.0) / 128.0, 0.0, 1.0), 1.0);
}

15
shaders/vis.vsh Normal file
View file

@ -0,0 +1,15 @@
layout (location = 0) in vec3 pos;
layout (location = 1) in vec3 norm;
layout (location = 2) in vec2 coord;
out float ypos;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main() {
vec3 vertex = vec3(model * vec4(pos, 1.0));
ypos = vertex.y;
gl_Position = projection * view * vec4(vertex, 1.0);
}

87
shaders/world.fsh Normal file
View file

@ -0,0 +1,87 @@
out vec4 FragColor;
struct light_t {
vec4 position;
vec4 ambient; // constant
vec4 diffuse; // linear
vec4 specular; // quadratic
vec4 range;
};
in vec3 vertex;
in vec3 normal;
in vec2 tex_coord;
uniform vec3 cam_pos;
uniform sampler2D tex;
uniform vec3 specular;
uniform float shine;
uniform float max_vert_dist;
uniform float max_cam_dist;
uniform float light_factor;
uniform vec3 dir_direction;
uniform vec3 dir_ambient;
uniform vec3 dir_diffuse;
uniform vec3 dir_specular;
uniform int n_lights;
uniform light_block {
light_t lights[MAX_LIGHTS];
};
/*
vec4 pcf_sample(sampler2D stex, vec2 pos) {
vec4 avg = vec4(0.0);
vec2 texel = 1.0 / textureSize(stex, 0);
for(int x = -1; x <= 1; x++) {
for(int y = -1; y <= 1; y++) {
avg += texture(stex, pos + vec2(x, y) * texel);
}
}
return avg /= 9.0;
}
*/
vec3 calc_dir_light(vec3 norm, vec3 dir, vec3 rgb) {
vec3 ldir = normalize(-dir_direction);
float diff = max(dot(norm, ldir), 0.0);
vec3 rdir = reflect(-ldir, norm);
float spec = pow(max(dot(dir, rdir), 0.0), shine);
vec3 ambient = dir_ambient * rgb + clamp(vec3(0.0), 0.0, 1.0);
vec3 diffuse = dir_diffuse * diff * rgb;
vec3 specular = dir_specular * spec * specular * rgb;
return (ambient + diffuse + specular);
}
vec3 calc_point_light(light_t light, vec3 norm, vec3 dir, vec3 rgb) {
rgb = clamp(rgb + light_factor, 0.0, 1.0);
vec3 ldir = normalize(light.position.xyz - vertex);
float diff = max(dot(norm, ldir), 0.0);
vec3 rdir = reflect(-ldir, norm);
float spec = pow(max(dot(dir, rdir), 0.0), shine);
float distance = length((light.position.xyz - vertex) / light.range.xyz);
float attenuation = 1.0 / (light.ambient.w + light.diffuse.w * distance + light.specular.w * (distance * distance));
vec3 ambient = light.ambient.xyz * rgb;
vec3 diffuse = light.diffuse.xyz * diff * rgb;
vec3 specular = light.specular.xyz * spec * specular * rgb;
ambient *= attenuation;
diffuse *= attenuation;
specular *= attenuation;
return (ambient + diffuse + specular);
}
void main() {
vec3 norm = normalize(normal);
vec3 dir = normalize(cam_pos - vertex);
vec4 texel = texture(tex, tex_coord);
vec3 rgb = texel.rgb * texel.a;
vec3 result = calc_dir_light(norm, dir, rgb);
// int l = 0;
for(int z = 0; z < n_lights; z++) {
// if(lights[z].enabled) {
if(distance(vertex, lights[z].position.xyz) <= max_vert_dist && distance(cam_pos, lights[z].position.xyz) <= max_cam_dist)
result += calc_point_light(lights[z], norm, dir, rgb);
// l++;
// }
}
FragColor = vec4(result, 1.0);
}

20
shaders/world.vsh Normal file
View file

@ -0,0 +1,20 @@
layout (location = 0) in vec3 pos;
layout (location = 1) in vec3 norm;
layout (location = 2) in vec2 coord;
out vec3 vertex;
out vec3 normal;
out vec2 tex_coord;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
uniform sampler2D tex;
uniform float density;
void main() {
vertex = vec3(model * vec4(pos, 1.0));
normal = mat3(transpose(inverse(model))) * norm;
tex_coord = coord * density / textureSize(tex, 0);
gl_Position = projection * view * vec4(vertex, 1.0);
}