forked from xeolabs/scenejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
geometry_heightmap_normalMap.html
157 lines (131 loc) · 6.99 KB
/
geometry_heightmap_normalMap.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<!DOCTYPE html>
<html lang="en">
<head>
<title>SceneJS Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
margin: 0;
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
}
</style>
<script src="../api/latest/scenejs.min.js"></script>
<link href="css/styles.css" rel="stylesheet"/>
<body>
<div id="infoLight">
<a href="http://scenejs.org">SceneJS</a> - <a href="../api/latest/plugins/node/geometry/heightmap.js"
target="_other">heightmap</a> geometry
<br>
with a normal map to enhance detail
<br>
<br>
click somewhere on the terrain
</div>
<script>
// Demo of the "geometry/heightmap" node type in conjunction with a normal map
// Point SceneJS to the bundled plugins
SceneJS.setConfigs({
pluginPath: "../api/latest/plugins"
});
// Create a scene
SceneJS.createScene({
nodes: [
// Mouse-controlled camera that orbits a ray-picked point
// implemented by plugin at http://scenejs.org/api/latest/plugins/node/cameras/orbitPick.js
{
type: "cameras/pickFlyOrbit",
yaw: 80,
pitch: -40,
maxPitch: -10,
minPitch: -80,
zoom: 1800,
eye: { x: 0, y: 550, z: -1500 },
look: { x: 0, y: 150, z: 0 },
zoomSensitivity: 20.0,
showCursor: true,
cursorSize: 4.0,
nodes: [
// Depth-of-field blur effect, implemented by plugin at:
// http://scenejs.org/api/latest/plugins/node/postprocess/dof.js
{
type: "postprocess/dof",
texelSize: 0.00022, // Size of one texel (1 / width, 1 / height)
blurCoeff: 0.0084, // Calculated from the blur equation, b = ( f * ms / N )
ppm: 10000, // Pixels per millimetre
autofocus: true, // Automatically synch focusDist to "cameras/pickFlyOrbit"
nodes: [
// Override default lights with a single positional light source in World-space.
// Since our light is in World-space, it will move relative to our changing viewpoint, as if it
// were a fixture in the scene.
{
type: "lights",
id: "myLights",
lights: [
{
mode: "ambient",
color: {r: 0.4, g: 0.4, b: 0.6 }
},
{
mode: "dir",
color: {r: 1.0, g: 1.0, b: 1.0 },
diffuse: true,
specular: true,
dir: {x: 0.7, y: -0.5, z: -0.5 },
space: "world"
}
],
nodes: [
// Blue color
{
type: "material",
color: { r: 0.6, g: 0.6, b: 0.7 },
specularColor: { r: 1.0, g: 1.0, b: 1.0 },
specular: 0.7,
shine: 100,
nodes: [
// Normal map
{
type: "texture",
applyTo: "normals",
src: 'textures/terrainNormalMap.png',
// scale: { x: -1, z: 1 },
// rotate: -270,
nodes: [
// Heightmap, implemented by plugin at
// http://scenejs.org/api/latest/plugins/node/geometry/heightmap.js
{
type: "geometry/heightmap",
// Generate normals all at [0,1,0]
// so that the normal map can perturb them
emptyNormals: true,
// Texture image
src: 'textures/terrainHeightMap.png',
// Wireframe or solid - default is false
wire: false,
// Dimensions
xSize: 2000,
zSize: 2000,
ySize: 800,
// Segments on X and Z axis
xSegments: 30,
zSegments: 30
}
]
}
]
}
]
}
]
}
]
}
]
}
);
</script>
</body>
</html>