-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
104 lines (93 loc) · 3.35 KB
/
index.html
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!doctype html>
<html lang="en">
<head>
<title>Terrain Generator</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="css/index.css">
<script src="js/main.js"></script>
<script src="js/terrain.js"></script>
<script src="js/libs/three.js"></script>
<script src="js/libs/simplex-noise.js"></script>
<script src="js/libs/dat.gui.js"></script>
<script type="shader-vertex" id="terrain-vertexShader">
uniform float terrainScale;
varying vec3 vNormal;
varying vec3 vWorldPosition;
varying float distFromCenter;
varying float correctedHeight;
void main()
{
distFromCenter = length(position.y);
correctedHeight = position.y / terrainScale;
vNormal = vec3(normal);
vec4 worldPosition = modelMatrix * vec4(position, 1.0);
vWorldPosition = worldPosition.xyz;
gl_Position = projectionMatrix * viewMatrix * worldPosition;
}
</script>
<script type="shader-fragment" id="terrain-fragmentShader">
precision mediump float;
uniform vec3 lightPosition;
uniform vec4 seaSandColor;
uniform vec4 beachSandColor;
uniform vec4 grassColor;
uniform vec4 forestColor;
uniform vec4 rockColor;
uniform vec4 snowColor;
uniform float seaSandHeight;
uniform float beachSandHeight;
uniform float grassHeight;
uniform float forestHeight;
uniform float rockHeight;
uniform float snowHeight;
varying vec3 vNormal;
varying vec3 vWorldPosition;
varying float distFromCenter;
varying float correctedHeight;
void main()
{
if(correctedHeight>0.0)
{
if(correctedHeight < beachSandHeight)
{
gl_FragColor = beachSandColor;
}
else if(correctedHeight < grassHeight)
{
gl_FragColor = mix(beachSandColor,grassColor,(correctedHeight-beachSandHeight)/(grassHeight-beachSandHeight));
}
else if(correctedHeight < forestHeight)
{
gl_FragColor = mix(grassColor,forestColor,(correctedHeight-grassHeight)/(forestHeight-grassHeight));
}
else if(correctedHeight < rockHeight)
{
gl_FragColor = mix(forestColor,rockColor,(correctedHeight-forestHeight)/(rockHeight-forestHeight));
}
else if(correctedHeight < snowHeight)
{
gl_FragColor = rockColor;
}
else
{
gl_FragColor = snowColor;
}
}
else if(correctedHeight > seaSandHeight)
{
gl_FragColor = mix(beachSandColor,seaSandColor,correctedHeight/seaSandHeight);
}
else
{
gl_FragColor = seaSandColor;
}
vec3 lightDirection = normalize(lightPosition - vWorldPosition);
float c = 0.25 + dot(vNormal, lightDirection) * 1.0;
gl_FragColor *= vec4(c,c,c,1);
}
</script>
</head>
<body>
</body>
</html>