add shaders, remove multi block layer
This commit is contained in:
parent
1e7ef94ceb
commit
563f235b2f
129 changed files with 1848 additions and 1486 deletions
9
client/src/main/resources/shaders/blit.fsh
Normal file
9
client/src/main/resources/shaders/blit.fsh
Normal file
|
@ -0,0 +1,9 @@
|
|||
out vec4 FragColor;
|
||||
|
||||
in vec2 tex_coord;
|
||||
|
||||
uniform sampler2D tex;
|
||||
|
||||
void main() {
|
||||
FragColor = texture(tex, tex_coord);
|
||||
}
|
8
client/src/main/resources/shaders/blit.vsh
Normal file
8
client/src/main/resources/shaders/blit.vsh
Normal 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
client/src/main/resources/shaders/grid.fsh
Normal file
38
client/src/main/resources/shaders/grid.fsh
Normal 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
client/src/main/resources/shaders/grid.vsh
Normal file
16
client/src/main/resources/shaders/grid.vsh
Normal 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
client/src/main/resources/shaders/lightmap.fsh
Normal file
8
client/src/main/resources/shaders/lightmap.fsh
Normal file
|
@ -0,0 +1,8 @@
|
|||
out vec4 FragColor;
|
||||
|
||||
uniform float fog;
|
||||
uniform vec3 color;
|
||||
|
||||
void main() {
|
||||
FragColor = vec4(color, fog);
|
||||
}
|
7
client/src/main/resources/shaders/lightmap.vsh
Normal file
7
client/src/main/resources/shaders/lightmap.vsh
Normal 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);
|
||||
}
|
7
client/src/main/resources/shaders/vis.fsh
Normal file
7
client/src/main/resources/shaders/vis.fsh
Normal 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
client/src/main/resources/shaders/vis.vsh
Normal file
15
client/src/main/resources/shaders/vis.vsh
Normal 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
client/src/main/resources/shaders/world.fsh
Normal file
87
client/src/main/resources/shaders/world.fsh
Normal 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
client/src/main/resources/shaders/world.vsh
Normal file
20
client/src/main/resources/shaders/world.vsh
Normal 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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue