version 120 varying mediump vec2 texture_coordinate uniform sampler2D

 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#version 120
varying mediump vec2 texture_coordinate;
uniform sampler2D heightTexture;
uniform sampler2D TerrainTexture1;
uniform sampler2D TerrainTexture2;
uniform sampler2D TerrainTexture3;
uniform sampler2D TerrainTexture4;
uniform sampler2D TerrainTexture5;
uniform float time;
void main (void)
{
mediump float height = ((texture2D(heightTexture, texture_coordinate).r-0.5)*255.0);
mediump float snow=0, rock=0, grass=0, dirt=0;
mediump float x = height;
dirt = -0.0008*(x-16)*(x-16)+1.0;
grass = -0.0011*(x-48)*(x-48)+1.0;
rock = -0.0011*(x-100)*(x-100)+1.0;
snow = -0.0021*(x-120)*(x-120)+1.0;
if(dirt<0) dirt = 0;
if(grass<0) grass = 0;
if(rock<0) rock = 0;
if(snow<0) snow = 0;
if(x>130) snow=1.0;
mediump vec2 texCoords = texture_coordinate + vec2(time, time) ;
if(texCoords.s >1 ) texCoords.s = texCoords.s-int(texCoords.s);
if(texCoords.t >1 ) texCoords.t = texCoords.t-int(texCoords.t);
//texCoords=normalize(texCoords);
gl_FragColor = dirt * texture2D(TerrainTexture1, texture_coordinate);
gl_FragColor += grass* texture2D(TerrainTexture2, texture_coordinate);
gl_FragColor += rock * texture2D(TerrainTexture3, texture_coordinate);
gl_FragColor += snow * texture2D(TerrainTexture4, texture_coordinate);
//gl_FragColor = normalize(gl_FragColor);
gl_FragColor.a = 1.0;
if( height < 0 ) {
gl_FragColor = texture2D(TerrainTexture5, texCoords );
}
}