]> git.lizzy.rs Git - dragonblocks_alpha.git/blob - assets/shaders/3d/terrain/fragment.glsl
Make texture batching optional (for OpenGL 3.3 compat)
[dragonblocks_alpha.git] / assets / shaders / 3d / terrain / fragment.glsl
1 in vec3 fragmentPosition;
2 in vec2 fragmentTextureCoordinates;
3 in float fragmentTextureIndex;
4 in vec3 fragmentColor;
5
6 out vec4 outColor;
7
8 uniform vec3 fogColor;
9 uniform vec3 cameraPos;
10
11 #if TEXURE_BATCH_UNITS > 1
12 uniform sampler2D textures[8];
13 #else
14 uniform sampler2D texture0;
15 #endif
16
17 void main()
18 {
19 #if TEXURE_BATCH_UNITS > 1
20         vec4 texel = texture(textures[int(fragmentTextureIndex + 0.5)], fragmentTextureCoordinates);
21 #else
22         vec4 texel = texture(texture0, fragmentTextureCoordinates);
23 #endif
24
25         outColor = texel * vec4(fragmentColor, 1.0);
26         outColor.rgb = mix(outColor.rgb, fogColor, clamp(length(fragmentPosition - cameraPos) / VIEW_DISTANCE, 0.0, 1.0));
27
28         if (outColor.a == 0.0)
29                 discard;
30 }