add visuals
This commit is contained in:
parent
1bf4578ad8
commit
220a8432ef
13 changed files with 81 additions and 93 deletions
|
@ -1,39 +0,0 @@
|
|||
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 coord = vec2(vertex.x, vertex.z) * 16.0f;
|
||||
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);
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
layout (location = 0) in vec3 pos;
|
||||
layout (location = 1) in vec4 color;
|
||||
layout (location = 2) in vec2 coord;
|
||||
layout (location = 3) in vec2 light;
|
||||
|
||||
out vec3 vertex;
|
||||
out vec2 tex_coord;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
uniform vec3 offset;
|
||||
|
||||
void main() {
|
||||
vertex = vec3(model * vec4(pos, 1.0));
|
||||
tex_coord = coord;
|
||||
gl_Position = projection * view * vec4(offset + vertex, 1.0);
|
||||
}
|
|
@ -1,3 +1,7 @@
|
|||
#define GLM_PI 3.14159265358979323846264338327950288
|
||||
#define GLM_SQRT2 1.41421356237309504880168872420969808
|
||||
#define vis_div 24.0
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
struct light_t {
|
||||
|
@ -27,10 +31,32 @@ 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);
|
||||
|
@ -73,12 +99,21 @@ vec3 calc_point_light(light_t light, vec3 norm, vec3 dir, vec3 rgb) {
|
|||
}
|
||||
|
||||
void main() {
|
||||
if(shine <= 0.0) {
|
||||
vec2 coord = fract(tex_coord * 2.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;
|
||||
vec3 direct = rgb * sky * (1.0 - light_color.a * 0.5);
|
||||
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue