1
0
Fork 0

revert some improved rendering

This commit is contained in:
Sen 2025-08-31 11:23:30 +02:00
parent 0e003971bc
commit 9d31588d8d
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
88 changed files with 735 additions and 608 deletions

View file

@ -0,0 +1,40 @@
#define GLM_PI 3.14159265358979323846264338327950288
#define GLM_SQRT2 1.41421356237309504880168872420969808
#define vis_div 24.0
out vec4 FragColor;
in vec3 vertex;
in vec2 tex_coord;
uniform vec2 tex_mul;
uniform float time;
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 coord = fract(tex_coord * tex_mul) * vis_div;
vec2 shift = vec2(v2rand(coord + fract(time)) * 2.0 - 1.0, v2rand(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(coord / vis_div, shift, 0.0, 1.0, 64.0, 1.0, 3.0, 1.0, 3.0), inside(coord / vis_div, shift, 0.0, 1.0, 64.0, 63.0, 1.0, 63.0, 1.0), inside(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);
}

View file

@ -1,14 +1,10 @@
layout (location = 0) in vec3 pos;
layout (location = 1) in vec4 norm;
layout (location = 1) in vec4 color;
layout (location = 2) in vec2 coord;
layout (location = 3) in vec4 light;
out vec3 vertex;
out vec3 normal;
out vec2 tex_coord;
out vec4 light_color;
out float shine;
out float shading;
uniform mat4 model;
uniform mat4 view;
@ -17,15 +13,10 @@ uniform vec3 offset;
uniform int chunk_x;
uniform int chunk_y;
uniform int chunk_z;
uniform bool shade;
void main() {
vec3 nvertex = vec3(model * vec4(pos, 1.0));
vertex = vec3(float(chunk_x) + pos.x, float(chunk_y) + pos.y, float(chunk_z) + pos.z);
shading = shade ? (norm.x != 0.0 ? 0.6 : (norm.z != 0.0 ? 0.8 : (norm.y < 0.0 ? 0.5 : 1.0))) : 1.0;
normal = mat3(transpose(inverse(model))) * norm.xyz;
shine = norm.a * 32.0;
tex_coord = coord;
light_color = light;
gl_Position = projection * view * vec4(offset + nvertex, 1.0);
}

View file

@ -1,128 +0,0 @@
#define GLM_PI 3.14159265358979323846264338327950288
#define GLM_SQRT2 1.41421356237309504880168872420969808
#define vis_div 24.0
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;
in vec4 light_color;
in float shine;
in float shading;
uniform vec3 cam_pos;
uniform sampler2D tex;
uniform vec3 specular;
uniform float max_vert_dist;
uniform float max_cam_dist;
uniform float light_factor;
uniform vec3 sun_direction;
uniform vec3 sun_ambient;
uniform vec3 moon_direction;
uniform vec3 moon_ambient;
uniform int n_lights;
uniform bool sky_light;
uniform bool moon_light;
uniform float time;
uniform light_block {
light_t lights[MAX_LIGHTS];
};
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;
}
/*
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 direction, vec3 color) {
if(shine <= -2.0)
return color * rgb;
vec3 ldir = normalize(-direction);
float diff = max(dot(norm, ldir), 0.0);
vec3 rdir = reflect(-ldir, norm);
float spec = shine <= 0.0 ? 0.0 : pow(max(dot(dir, rdir), 0.0), shine) * (shine < 1.0 ? shine : 1.0);
vec3 ambient = color * rgb; // + clamp(vec3(0.0), 0.0, 1.0);
vec3 diffuse = color * 0.125 * diff * rgb;
vec3 speculars = color * 1.25 * spec * specular * rgb;
return (ambient + diffuse + speculars);
}
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 = shine <= -3.0 ? 0.0 : max(dot(norm, ldir), 0.0);
vec3 rdir = reflect(-ldir, norm);
float spec = shine <= -1.0 ? 0.0 : pow(max(dot(dir, rdir), 0.0), shine) * (shine < 1.0 ? shine : 1.0);
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 speculars = light.specular.xyz * spec * specular * rgb;
ambient *= attenuation;
diffuse *= attenuation;
speculars *= attenuation;
return (ambient + diffuse + speculars);
}
void main() {
if(shine <= -16.0) {
vec2 coord = fract(tex_coord * textureSize(tex, 0) / 256.0) * vis_div; // vertex.xz + vec2(0.25, 0.5)) * 24.0 / 2.0;
vec2 shift = vec2(v2rand(coord + fract(time)) * 2.0 - 1.0, v2rand(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(coord / vis_div, shift, 0.0, 1.0, 64.0, 1.0, 3.0, 1.0, 3.0), inside(coord / vis_div, shift, 0.0, 1.0, 64.0, 63.0, 1.0, 63.0, 1.0), inside(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);
return;
}
vec3 norm = normalize(normal);
vec3 dir = normalize(cam_pos - vertex);
vec4 texel = texture(tex, tex_coord);
float sky = sky_light ? vertex.y < 0.0 ? 0.0 : (vertex.y < 64.0 ? vertex.y / 64.0 : 1.0) : 1.0;
vec3 rgb = texel.rgb * shading;
vec3 direct = rgb * sky * (1.0 - light_color.a * light_factor);
vec3 result = rgb * light_color.rgb + calc_dir_light(norm, dir, direct, sun_direction, sun_ambient);
if(moon_light)
result += calc_dir_light(norm, dir, direct, moon_direction, moon_ambient);
for(int z = 0; z < n_lights; z++) {
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);
}
FragColor = vec4(result, texel.a);
}