implement lighmap shading
This commit is contained in:
parent
cf0239c76e
commit
64396b28b9
6 changed files with 20 additions and 10 deletions
|
@ -41,6 +41,11 @@ public enum Shader {
|
|||
context.vec("max_vert_dist", Client.CLIENT.lightDistVert);
|
||||
context.vec("max_cam_dist", Client.CLIENT.lightDistCam);
|
||||
context.integer("n_lights", 0);
|
||||
|
||||
context.color3("specular", 0xffffff);
|
||||
context.vec("shine", 1.0f);
|
||||
// context.vec("density", density);
|
||||
|
||||
GlState.setActiveTexture(GL46.GL_TEXTURE0);
|
||||
// glBindBufferBase(GL_UNIFORM_BUFFER, 0, world->light_buf);
|
||||
}, "MAX_LIGHTS", (Supplier<Integer>)() -> Client.CLIENT.lightMaximum),
|
||||
|
|
|
@ -31,8 +31,9 @@ float inside(vec2 vec, vec2 offs, float a, float b, float scale, float x1, float
|
|||
}
|
||||
|
||||
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);
|
||||
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(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));
|
||||
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,6 +1,7 @@
|
|||
layout (location = 0) in vec3 pos;
|
||||
layout (location = 1) in vec3 norm;
|
||||
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;
|
||||
|
@ -8,9 +9,10 @@ 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(vertex, 1.0);
|
||||
gl_Position = projection * view * vec4(offset + vertex, 1.0);
|
||||
}
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
layout (location = 0) in vec3 pos;
|
||||
layout (location = 1) in vec3 norm;
|
||||
layout (location = 1) in vec4 color;
|
||||
layout (location = 2) in vec2 coord;
|
||||
layout (location = 3) in vec2 light;
|
||||
|
||||
out float ypos;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
uniform vec3 offset;
|
||||
|
||||
void main() {
|
||||
vec3 vertex = vec3(model * vec4(pos, 1.0));
|
||||
vec3 vertex = offset + vec3(model * vec4(pos, 1.0));
|
||||
ypos = vertex.y;
|
||||
gl_Position = projection * view * vec4(vertex, 1.0);
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ void main() {
|
|||
vec3 norm = normalize(normal);
|
||||
vec3 dir = normalize(cam_pos - vertex);
|
||||
vec4 texel = texture(tex, tex_coord) * brightness;
|
||||
vec3 light_v = texture(lightmap, vec2(0.03125 + lm_coord.x * 256, 0.03125 + lm_coord.y * 256)).rgb;
|
||||
texel *= texture(lightmap, 0.03125 + lm_coord * 256.0);
|
||||
vec3 rgb = texel.rgb;
|
||||
vec3 result = calc_dir_light(norm, dir, rgb);
|
||||
// int l = 0;
|
||||
|
@ -87,5 +87,5 @@ void main() {
|
|||
// l++;
|
||||
// }
|
||||
}
|
||||
FragColor = texel * vec4(light_v, 1.0); // vec4(result, texel.a);
|
||||
FragColor = texel; // vec4(result, texel.a);
|
||||
}
|
||||
|
|
|
@ -18,10 +18,10 @@ uniform vec3 offset;
|
|||
|
||||
void main() {
|
||||
vec3 norm = vec3(0.0, 1.0, 0.0);
|
||||
vertex = vec3(model * vec4(pos, 1.0));
|
||||
vertex = offset + vec3(model * vec4(pos, 1.0));
|
||||
normal = mat3(transpose(inverse(model))) * norm;
|
||||
brightness = color;
|
||||
tex_coord = coord;
|
||||
lm_coord = light;
|
||||
gl_Position = projection * view * vec4(offset + vertex, 1.0);
|
||||
gl_Position = projection * view * vec4(vertex, 1.0);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue