improve shader
This commit is contained in:
parent
64396b28b9
commit
01ceef058c
7 changed files with 127 additions and 106 deletions
|
@ -10,9 +10,9 @@ struct light_t {
|
|||
|
||||
in vec3 vertex;
|
||||
in vec3 normal;
|
||||
in vec4 brightness;
|
||||
in vec2 tex_coord;
|
||||
in vec2 lm_coord;
|
||||
in float brightness;
|
||||
|
||||
uniform vec3 cam_pos;
|
||||
uniform sampler2D tex;
|
||||
|
@ -24,9 +24,9 @@ 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 vec3 block_ambient;
|
||||
uniform int n_lights;
|
||||
uniform bool sky_light;
|
||||
uniform light_block {
|
||||
light_t lights[MAX_LIGHTS];
|
||||
};
|
||||
|
@ -50,8 +50,8 @@ vec3 calc_dir_light(vec3 norm, vec3 dir, vec3 rgb) {
|
|||
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;
|
||||
vec3 diffuse = dir_ambient * 0.125 * diff * rgb;
|
||||
vec3 specular = dir_ambient * 1.25 * spec * specular * rgb;
|
||||
return (ambient + diffuse + specular);
|
||||
}
|
||||
|
||||
|
@ -75,10 +75,12 @@ vec3 calc_point_light(light_t light, vec3 norm, vec3 dir, vec3 rgb) {
|
|||
void main() {
|
||||
vec3 norm = normalize(normal);
|
||||
vec3 dir = normalize(cam_pos - vertex);
|
||||
vec4 texel = texture(tex, tex_coord) * brightness;
|
||||
texel *= texture(lightmap, 0.03125 + lm_coord * 256.0);
|
||||
vec3 rgb = texel.rgb;
|
||||
vec3 result = calc_dir_light(norm, dir, rgb);
|
||||
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;
|
||||
float block = clamp(0.03125 + lm_coord.x * 256.0, 0.0, 1.0);
|
||||
vec3 lm = block * block_ambient;
|
||||
vec3 rgb = texel.rgb; // * brightness;
|
||||
vec3 result = rgb * lm + calc_dir_light(norm, dir, rgb * sky * (1.0 - block));
|
||||
// int l = 0;
|
||||
for(int z = 0; z < n_lights; z++) {
|
||||
// if(lights[z].enabled) {
|
||||
|
@ -87,5 +89,5 @@ void main() {
|
|||
// l++;
|
||||
// }
|
||||
}
|
||||
FragColor = texel; // vec4(result, texel.a);
|
||||
FragColor = vec4(result, texel.a);
|
||||
}
|
||||
|
|
|
@ -1,27 +1,29 @@
|
|||
layout (location = 0) in vec3 pos;
|
||||
// layout (location = 1) in vec3 norm;
|
||||
layout (location = 1) in vec4 color;
|
||||
layout (location = 1) in vec4 norm;
|
||||
layout (location = 2) in vec2 coord;
|
||||
layout (location = 3) in vec2 light;
|
||||
|
||||
out vec3 vertex;
|
||||
out vec3 normal;
|
||||
out vec4 brightness;
|
||||
out vec2 tex_coord;
|
||||
out vec2 lm_coord;
|
||||
out float brightness;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
uniform sampler2D tex;
|
||||
uniform vec3 offset;
|
||||
uniform int chunk_x;
|
||||
uniform int chunk_y;
|
||||
uniform int chunk_z;
|
||||
|
||||
void main() {
|
||||
vec3 norm = vec3(0.0, 1.0, 0.0);
|
||||
vertex = offset + vec3(model * vec4(pos, 1.0));
|
||||
normal = mat3(transpose(inverse(model))) * norm;
|
||||
brightness = color;
|
||||
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);
|
||||
normal = mat3(transpose(inverse(model))) * norm.rgb;
|
||||
brightness = norm.a;
|
||||
tex_coord = coord;
|
||||
lm_coord = light;
|
||||
gl_Position = projection * view * vec4(vertex, 1.0);
|
||||
gl_Position = projection * view * vec4(offset + nvertex, 1.0);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue