-
Notifications
You must be signed in to change notification settings - Fork 0
/
pointlightShadowTest.html
177 lines (145 loc) · 4.79 KB
/
pointlightShadowTest.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!DOCTYPE html>
<html lang="en">
<head>
<title>PointLight ShadowTest1 </title>
<meta charset="utf-8">
<style>
body {
font-family: Monospace;
background-color: #000;
color: #fff;
margin: 0px;
overflow: hidden;
}
</style>
<script src="js/three.min.js"></script>
<script src="js/controls/OrbitControls.js"></script>
<script src="js/Detector.js"></script>
<script src="js/libs/stats.min.js"></script>
<script src="js/ParametricGeometries.js"></script>
<script type="text/javascript" src="Basics.js"></script>
</head>
<body>
<script>
var camera, scene, renderer, stats;
var pointLight, pointLight2;
var klein, kleinMaterial, groundMaterial, ground, cubeGroup;
var t = 0;
init();
animate();
function init() {
camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.set( 0, 10, 40 );
scene = new THREE.Scene();
scene.add(new THREE.AmbientLight(0x990000));
function createLight( color ) {
var pointLight = new THREE.PointLight( color, 1, 30 );
pointLight.castShadow = true;
pointLight.shadowCameraNear = 1;
pointLight.shadowCameraFar = 30;
//pointLight.shadowCameraVisible = true;
pointLight.shadowMapWidth = 2048;
pointLight.shadowMapHeight = 1024;
pointLight.shadowBias = 0.01;
pointLight.shadowDarkness = 0.5;
var geometry = new THREE.SphereGeometry( 0.3, 32, 32 );
var material = new THREE.MeshBasicMaterial( { color: color } );
var sphere = new THREE.Mesh( geometry, material );
pointLight.add( sphere );
return pointLight;
}
pointLight = createLight( 0xFFFF99 );
scene.add( pointLight );
pointLight2 = createLight( 0xFFCC99 );
scene.add( pointLight2 );
pointLight3 = createLight( 0xffffff );
scene.add( pointLight3 );
kleinMaterial = new THREE.MeshPhongMaterial( {
color: 0x99CCFF,
shininess: 50,
specular: 0x222222
} );
var kleinGeo = new THREE.ParametricGeometry( THREE.ParametricGeometries.klein_complex, 50, 50 );
klein = new THREE.Mesh( kleinGeo, kleinMaterial );
klein.position.set( 0, 5, 0 );
klein.castShadow = true;
klein.receiveShadow = true;
scene.add( klein );
groundMaterial = new THREE.MeshPhongMaterial( {
color: 0xa0adaf,
shininess: 10,
specular: 0x111111,
shading: THREE.SmoothShading
} );
materials = [groundMaterial, new THREE.MeshBasicMaterial( { color: 0x000000, wireframe: true, transparent: true, opacity: 1, side: THREE.DoubleSide } )];
var groundGeo = new THREE.PlaneGeometry( 20, 20, 5, 5 );
ground = new THREE.Mesh( groundGeo, groundMaterial );
//ground = new THREE.SceneUtils.createMultiMaterialObject(groundGeo, materials);
// ***** multiMaterialObject can't receive shadow ***** //
ground.position.set( 0, 0, -10 );
ground.scale.multiplyScalar( 3 );
ground.receiveShadow = true;
scene.add(ground);
var cubeGeo = new THREE.CubeGeometry(1,1,8);
cubeGroup = [];
var radius = 18;
var theta = 15/180 * Math.PI;
for (var cur_theta = theta; cur_theta < 2*Math.PI; cur_theta += theta){
var cube = new THREE.Mesh( cubeGeo, groundMaterial );
var x = radius * Math.cos(cur_theta);
var y = radius * Math.sin(cur_theta);
cube.position.set(x,y,-10);
cube.castShadow = true;
cube.receiveShadow = true;
scene.add(cube);
cubeGroup.push(cube);
}
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setClearColor(0x000000);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.BasicShadowMap;
controls = new THREE.OrbitControls( camera, renderer.domElement );
controls.target.set( 0, 0, 0 );
controls.update();
stats = initStats();
document.body.appendChild( stats.domElement );
document.body.appendChild( renderer.domElement );
window.addEventListener( 'resize', onWindowResize, false );
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function animate() {
requestAnimationFrame( animate );
render();
stats.update();
}
function render() {
var time = Date.now() * 0.001;
pointLight.position.x = Math.sin( time ) * 9;
pointLight.position.y = Math.sin( time * 1.1 ) * 9;
pointLight.position.z = Math.sin( time * 1.2 ) * 9 + 4;
time += 10000;
pointLight2.position.x = Math.sin( time ) * 9;
pointLight2.position.y = Math.sin( time * 1.1 ) * 9;
pointLight2.position.z = Math.sin( time * 1.2 ) * 9 + 4;
time += 10000;
pointLight3.position.x = Math.sin( time ) * 9;
pointLight3.position.y = Math.sin( time * 1.1 ) * 9;
pointLight3.position.z = Math.sin( time * 1.2 ) * 9 + 4;
klein.rotation.y += 0.05;
t++;
for(var i = 0; i < cubeGroup.length; i++){
var height = 8 + 3 * Math.sin(Math.PI/18 * (t + i));
cubeGroup[i].geometry = new THREE.CubeGeometry(1,1,height);
cubeGroup[i].geometry.NeedsUpdate = true;
}
renderer.render( scene, camera );
}
</script>
</body>
</html>
check