]> git.lizzy.rs Git - dragonblocks_alpha.git/blobdiff - shaders/3d/fragment.glsl
Add diffuse lighting, improve skybox and add timelapse
[dragonblocks_alpha.git] / shaders / 3d / fragment.glsl
index a3c9a9f509af5b3a0e60ccbef287c6cff540deb7..be0eb58fd0c0aa846025892ae606c34cddd3c8f5 100755 (executable)
@@ -1,9 +1,12 @@
+in vec3 fragmentNormal;
 in float fragmentTextureIndex;
 in vec2 fragmentTextureCoords;
 in vec3 fragmentColor;
 
 out vec4 outColor;
 
+uniform float daylight;
+uniform vec3 lightDir;
 uniform sampler2D textures[MAX_TEXTURE_UNITS];
 
 vec3 hsv2rgb(vec3 c)
@@ -15,5 +18,12 @@ vec3 hsv2rgb(vec3 c)
 
 void main()
 {
-       outColor = texture(textures[int(fragmentTextureIndex + 0.5)], fragmentTextureCoords) * vec4(hsv2rgb(vec3(fragmentColor)), 1.0);
+       vec3 lightColor = vec3(1.0);
+
+       vec3 ambient = mix(0.2, 0.8, daylight) * lightColor;
+       vec3 diffuse = 0.2 * daylight * clamp(dot(normalize(fragmentNormal), normalize(lightDir)), 0.0, 1.0) * lightColor;
+
+       vec3 light = ambient + diffuse;
+
+       outColor = texture(textures[int(fragmentTextureIndex + 0.5)], fragmentTextureCoords) * vec4(hsv2rgb(vec3(fragmentColor)), 1.0) * vec4(light, 1.0);
 }