47 lines
1.5 KiB
GLSL
47 lines
1.5 KiB
GLSL
#version 330
|
|
|
|
in vec2 fragTexCoord;
|
|
in vec4 fragColor;
|
|
in vec3 fragPosition;
|
|
in vec3 fragNormal;
|
|
|
|
uniform sampler2D texture0;
|
|
uniform vec4 sunlightColor;
|
|
uniform vec4 skyColor;
|
|
|
|
uniform vec3 lightDir;
|
|
|
|
out vec4 finalColor;
|
|
|
|
void main()
|
|
{
|
|
vec4 texelColor = texture(texture0, fragTexCoord);
|
|
|
|
vec3 N = normalize(fragNormal);
|
|
vec3 L = normalize(lightDir);
|
|
|
|
float ndotl = max(dot(N, L), 0.0);
|
|
float ambient = 0.1;
|
|
float sunfactor = ambient + (1.0 - ambient) * ndotl;
|
|
|
|
sunfactor *= 1+min(0, L.y);
|
|
vec3 Lmoon = normalize(-lightDir);
|
|
float ndotlMoon = max(dot(N, Lmoon), 0.0);
|
|
float moonfactor = (ambient + (1.0 - ambient) * ndotlMoon) * 8;
|
|
moonfactor *= max(0, -L.y);
|
|
|
|
// In fragColor, 'r' is blocklight R, 'g' is blocklight G, 'b' is blocklight B and 'a' is sunlight
|
|
float sunlight = fragColor.a;
|
|
texelColor.r *= sunlight * sunlightColor.r * (sunfactor+moonfactor) + fragColor.r;
|
|
texelColor.g *= sunlight * sunlightColor.g * (sunfactor+moonfactor) + fragColor.g;
|
|
texelColor.b *= sunlight * sunlightColor.b * (sunfactor+moonfactor) + fragColor.b;
|
|
float highlight = texelColor.a;
|
|
if(highlight < 0.25) highlight = 0;
|
|
float highlight_final = abs(N.y)*highlight * 4;
|
|
vec3 highlightColor = sunlightColor.rgb*highlight_final*sunlight;
|
|
highlightColor.r += fragColor.r*highlight_final;
|
|
highlightColor.g += fragColor.g*highlight_final;
|
|
highlightColor.b += fragColor.b*highlight_final;
|
|
finalColor = texelColor + vec4(highlightColor, min(1.0, highlight_final));
|
|
}
|