summaryrefslogtreecommitdiff
path: root/shaders/terrain_fragment.glsl
blob: 8b966fd1f6c16ca90dd700b24acb96d4e5387350 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#version 120

varying vec3 normal, light_pos, pos;

uniform sampler2D tex[3];
uniform sampler2D marktex;
uniform vec3 selpos, player_pos;
uniform bool show_sel;

void main() {
	vec3 n = normalize(normal);
	float diffuse = max(dot(n, light_pos), 0.5);

	float f1 = clamp((pos.y-60.0) / 3.0, 0.0, 1.0);
	float f2 = clamp((pos.y-33) / 3.0, 0.0, 1.0);

	vec4 grass = texture2D(tex[0], gl_TexCoord[0].st);
	vec4 rock = texture2D(tex[1], gl_TexCoord[0].st);
	vec4 soil = texture2D(tex[2], gl_TexCoord[0].st);

	gl_FragColor = mix(mix(soil, grass, f2), rock, f1) * diffuse;

	/* selection marker */
	if(show_sel &&
		pos.x >= selpos.x-1 && pos.x <= selpos.x+1 &&
		pos.z >= selpos.z-1 && pos.z <= selpos.z+1) {
		vec2 st = vec2((pos.x + 1 - selpos.x) / 2, (pos.z + 1 - selpos.z) / 2);
		gl_FragColor += texture2D(marktex, st);
	}
	gl_FragColor = mix(gl_FragColor, gl_Fog.color, pow(length(player_pos - pos)/100, 5));
	if(player_pos.y < 30 - 1.7)
		gl_FragColor = mix(gl_FragColor, vec4(0, .3, .8, 0), .7);
}

/* vim: set syn=glsl: */