ProjectZombie/src/resources/shader/environmentRenderer.fsh

47 lines
1.3 KiB
GLSL

#version 330
in vec3 pPos;
in vec3 pTexture;
in vec3 pLightMapPos;
out vec4 FragColor;
uniform sampler3D atlas;
uniform sampler2D lightmap;
uniform vec3 lighting_day_low;
uniform vec3 lighting_day_high;
uniform vec2 lightmap_offset;
uniform vec2 lightmap_size;
uniform vec2 tex_cut;
uniform vec4 color;
float map(float x, float in_min, float in_max, float out_min, float out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
vec3 mapVec(float x, float in_min, float in_max, vec3 out_min, vec3 out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
vec3 biggest(vec3 a, vec3 b) {
return vec3(a.x > b.x ? a.x : b.x,
a.y > b.y ? a.y : b.y,
a.z > b.z ? a.z : b.z);
}
void main()
{
vec4 light = texture(lightmap, vec2(
map(pLightMapPos.x, lightmap_offset.x, lightmap_offset.x + lightmap_size.x, 0, 1),
map(pLightMapPos.z, lightmap_offset.y, lightmap_offset.y + lightmap_size.y, 0, 1)));
vec3 light_day = mapVec(light.r, 0, 1, lighting_day_low, lighting_day_high);
vec3 light_src = vec3(1, 1, 1) * (light.g - abs(pLightMapPos.y) * 0.1);
FragColor = texture(atlas, pTexture) * color * vec4(biggest(light_day, light_src), 1);
discard(FragColor.a == 0 || (pPos.x > tex_cut.y && tex_cut.x > 0.5));
}