2021-01-04 23:37:44 +01:00
|
|
|
#version 440 core
|
2021-01-07 11:06:40 +01:00
|
|
|
|
|
|
|
in vec3 Normal;
|
2021-01-04 23:37:44 +01:00
|
|
|
in vec2 TexCoords;
|
|
|
|
in vec2 Light;
|
|
|
|
|
|
|
|
out vec4 fragColor;
|
|
|
|
|
|
|
|
layout(binding=0) uniform sampler2D BlockAtlas;
|
|
|
|
layout(binding=1) uniform sampler2D LightMap;
|
|
|
|
|
|
|
|
float blendDarken(float base, float blend) {
|
|
|
|
return min(blend,base);
|
|
|
|
}
|
|
|
|
|
|
|
|
vec3 blendDarken(vec3 base, vec3 blend) {
|
|
|
|
return vec3(blendDarken(base.r,blend.r),blendDarken(base.g,blend.g),blendDarken(base.b,blend.b));
|
|
|
|
}
|
|
|
|
|
|
|
|
vec3 blendDarken(vec3 base, vec3 blend, float opacity) {
|
|
|
|
return (blendDarken(base, blend) * opacity + base * (1.0 - opacity));
|
|
|
|
}
|
|
|
|
|
2021-01-07 11:06:40 +01:00
|
|
|
float diffuse() {
|
|
|
|
float x = Normal.x;
|
|
|
|
float y = Normal.y;
|
|
|
|
float z = Normal.z;
|
|
|
|
return min(x * x * 0.6f + y * y * ((3f + y) / 4f) + z * z * 0.8f, 1f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void main() {
|
2021-01-04 23:37:44 +01:00
|
|
|
vec4 tex = texture2D(BlockAtlas, TexCoords);
|
|
|
|
|
|
|
|
vec4 light = texture2D(LightMap, Light);
|
|
|
|
|
2021-01-07 11:06:40 +01:00
|
|
|
fragColor = vec4(blendDarken(tex.rgb, light.rgb, light.a) * diffuse(), tex.a);
|
2021-01-04 23:37:44 +01:00
|
|
|
}
|