1
0
Fork 0

implement basic shader

This commit is contained in:
Sen 2025-08-28 17:41:29 +02:00
parent 563f235b2f
commit cf0239c76e
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
6 changed files with 114 additions and 104 deletions

View file

@ -10,10 +10,13 @@ struct light_t {
in vec3 vertex;
in vec3 normal;
in vec4 brightness;
in vec2 tex_coord;
in vec2 lm_coord;
uniform vec3 cam_pos;
uniform sampler2D tex;
uniform sampler2D lightmap;
uniform vec3 specular;
uniform float shine;
uniform float max_vert_dist;
@ -72,8 +75,9 @@ 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);
vec3 rgb = texel.rgb * texel.a;
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;
vec3 rgb = texel.rgb;
vec3 result = calc_dir_light(norm, dir, rgb);
// int l = 0;
for(int z = 0; z < n_lights; z++) {
@ -83,5 +87,5 @@ void main() {
// l++;
// }
}
FragColor = vec4(result, 1.0);
FragColor = texel * vec4(light_v, 1.0); // vec4(result, texel.a);
}

View file

@ -1,20 +1,27 @@
layout (location = 0) in vec3 pos;
layout (location = 1) in vec3 norm;
// 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 vec3 normal;
out vec4 brightness;
out vec2 tex_coord;
out vec2 lm_coord;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
uniform sampler2D tex;
uniform float density;
uniform vec3 offset;
void main() {
vec3 norm = vec3(0.0, 1.0, 0.0);
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);
normal = mat3(transpose(inverse(model))) * norm;
brightness = color;
tex_coord = coord;
lm_coord = light;
gl_Position = projection * view * vec4(offset + vertex, 1.0);
}