summaryrefslogtreecommitdiff
path: root/shaders/terrain_fragment.glsl
blob: 7197883ca3b11057ef6e49d071b87818102fcb4e (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
36
37
38
#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-15.0) / 3.0, 0.0, 1.0);
	//float f2 = clamp((pos.y-2) / 3.0, 0.0, 1.0);
	float f1 = clamp((pos.y-60.0) / 3.0, 0.0, 1.0);
	float f2 = clamp((pos.y-30) / 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;

	//gl_FragColor = mix(gl_FragColor, gl_FragColor*vec4(0, 0, 1, 0), clamp(31 - pos.y, 0.0, 1.0));
	//gl_FragColor += vec4(0, 0, 1, clamp(31 - pos.y, 0.0, 1.0));

	/* 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));
}

/* vim: set syn=glsl: */