]> git.lizzy.rs Git - dragonblocks_alpha.git/blob - shaders/3d/fragment.glsl
Add diffuse lighting, improve skybox and add timelapse
[dragonblocks_alpha.git] / shaders / 3d / fragment.glsl
1 in vec3 fragmentNormal;
2 in float fragmentTextureIndex;
3 in vec2 fragmentTextureCoords;
4 in vec3 fragmentColor;
5
6 out vec4 outColor;
7
8 uniform float daylight;
9 uniform vec3 lightDir;
10 uniform sampler2D textures[MAX_TEXTURE_UNITS];
11
12 vec3 hsv2rgb(vec3 c)
13 {
14     vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
15     vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
16     return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
17 }
18
19 void main()
20 {
21         vec3 lightColor = vec3(1.0);
22
23         vec3 ambient = mix(0.2, 0.8, daylight) * lightColor;
24         vec3 diffuse = 0.2 * daylight * clamp(dot(normalize(fragmentNormal), normalize(lightDir)), 0.0, 1.0) * lightColor;
25
26         vec3 light = ambient + diffuse;
27
28         outColor = texture(textures[int(fragmentTextureIndex + 0.5)], fragmentTextureCoords) * vec4(hsv2rgb(vec3(fragmentColor)), 1.0) * vec4(light, 1.0);
29 }