Skip to content

Commit 9bc1058

Browse files
author
Jos Dirksen
committed
Fixes while reviewing chapters
1 parent 1742aac commit 9bc1058

File tree

4 files changed

+45
-32
lines changed

4 files changed

+45
-32
lines changed

chapter-03/03-spot-light.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
renderer.setClearColor(new THREE.Color(0xEEEEEE, 1.0));
4747
renderer.setSize(window.innerWidth, window.innerHeight);
4848
renderer.shadowMapEnabled = true;
49+
renderer.shadowMapType=THREE.PCFShadowMap;
4950

5051
// create the ground plane
5152
var planeGeometry = new THREE.PlaneGeometry(60, 20, 1, 1);
@@ -102,7 +103,7 @@
102103

103104
// add spotlight for a bit of light
104105
var spotLight0 = new THREE.SpotLight(0xcccccc);
105-
spotLight0.position.set(-40, 60, -10);
106+
spotLight0.position.set(-40, 30, -10);
106107
spotLight0.lookAt(plane);
107108
scene.add(spotLight0);
108109

@@ -117,9 +118,11 @@
117118
spotLight.castShadow = true;
118119
spotLight.shadowCameraNear = 2;
119120
spotLight.shadowCameraFar = 200;
120-
spotLight.shadowCameraFov = 130;
121+
spotLight.shadowCameraFov = 30;
121122
spotLight.target = plane;
122123
spotLight.distance = 0;
124+
spotLight.angle = 0.4;
125+
123126

124127

125128
scene.add(spotLight);
@@ -244,13 +247,14 @@
244247
}
245248
sphereLightMesh.position.z = +(7 * (Math.sin(phase)));
246249
sphereLightMesh.position.x = +(14 * (Math.cos(phase)));
250+
sphereLightMesh.position.y = 10;
247251

248252
if (invert < 0) {
249253
var pivot = 14;
250254
sphereLightMesh.position.x = (invert * (sphereLightMesh.position.x - pivot)) + pivot;
251255
}
252256

253-
spotLight.position = sphereLightMesh.position;
257+
spotLight.position.copy(sphereLightMesh.position);
254258
}
255259

256260
// render using requestAnimationFrame

chapter-03/05-hemisphere-light.html

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757

5858
var planeGeometry = new THREE.PlaneGeometry(1000, 200, 20, 20);
5959
var planeMaterial = new THREE.MeshLambertMaterial({map: textureGrass});
60+
// var planeMaterial = new THREE.MeshLambertMaterial();
6061
var plane = new THREE.Mesh(planeGeometry, planeMaterial);
6162
plane.receiveShadow = true;
6263

@@ -100,6 +101,9 @@
100101
camera.position.x = -20;
101102
camera.position.y = 15;
102103
camera.position.z = 45;
104+
// camera.position.x = -120;
105+
// camera.position.y = 165;
106+
// camera.position.z = 145;
103107
camera.lookAt(new THREE.Vector3(10, 0, 0));
104108

105109

@@ -115,31 +119,29 @@
115119

116120
var hemiLight = new THREE.HemisphereLight(0x0000ff, 0x00ff00, 0.6);
117121
hemiLight.position.set(0, 500, 0);
118-
hemiLight.visible = false;
119122
scene.add(hemiLight);
120123

121124

122125
var pointColor = "#ffffff";
123-
// var spotLight = new THREE.SpotLight( pointColor);
124-
var spotLight = new THREE.DirectionalLight(pointColor);
125-
spotLight.position.set(30, 10, -50);
126-
spotLight.castShadow = true;
127-
spotLight.shadowCameraNear = 0.1;
128-
spotLight.shadowCameraFar = 100;
129-
spotLight.shadowCameraFov = 50;
130-
spotLight.target = plane;
131-
spotLight.distance = 0;
132-
spotLight.shadowCameraNear = 2;
133-
spotLight.shadowCameraFar = 200;
134-
spotLight.shadowCameraLeft = -100;
135-
spotLight.shadowCameraRight = 100;
136-
spotLight.shadowCameraTop = 100;
137-
spotLight.shadowCameraBottom = -100;
138-
spotLight.shadowMapWidth = 2048;
139-
spotLight.shadowMapHeight = 2048;
140-
141-
142-
scene.add(spotLight);
126+
// var dirLight = new THREE.SpotLight( pointColor);
127+
var dirLight = new THREE.DirectionalLight(pointColor);
128+
dirLight.position.set(30, 10, -50);
129+
dirLight.castShadow = true;
130+
// dirLight.shadowCameraNear = 0.1;
131+
// dirLight.shadowCameraFar = 100;
132+
// dirLight.shadowCameraFov = 50;
133+
dirLight.target = plane;
134+
dirLight.shadowCameraNear = 0.1;
135+
dirLight.shadowCameraFar = 200;
136+
dirLight.shadowCameraLeft = -50;
137+
dirLight.shadowCameraRight = 50;
138+
dirLight.shadowCameraTop = 50;
139+
dirLight.shadowCameraBottom = -50;
140+
dirLight.shadowMapWidth = 2048;
141+
dirLight.shadowMapHeight = 2048;
142+
143+
144+
scene.add(dirLight);
143145

144146

145147
// add the output of the renderer to the html element
@@ -156,8 +158,8 @@
156158
this.rotationSpeed = 0.03;
157159
this.bouncingSpeed = 0.03;
158160

159-
this.hemisphere = false;
160-
this.groundColor = 0x00ff00;
161+
this.hemisphere = true;
162+
this.color = 0x00ff00;
161163
this.skyColor = 0x0000ff;
162164
this.intensity = 0.6;
163165

@@ -166,9 +168,14 @@
166168
var gui = new dat.GUI();
167169

168170
gui.add(controls, 'hemisphere').onChange(function (e) {
169-
hemiLight.visible = e;
171+
172+
if (!e) {
173+
hemiLight.intensity = 0;
174+
} else {
175+
hemiLight.intensity = controls.intensity;
176+
}
170177
});
171-
gui.addColor(controls, 'groundColor').onChange(function (e) {
178+
gui.addColor(controls, 'color').onChange(function (e) {
172179
hemiLight.groundColor = new THREE.Color(e);
173180
});
174181
gui.addColor(controls, 'skyColor').onChange(function (e) {

chapter-03/06-area-light.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
planeGeometry1Mat.color = new THREE.Color(e);
157157
scene.remove(plane1);
158158
plane1 = new THREE.Mesh(planeGeometry1, planeGeometry1Mat);
159-
plane1.position = areaLight1.position;
159+
plane1.position.copy(areaLight1.position);
160160
scene.add(plane1);
161161

162162
});
@@ -168,7 +168,7 @@
168168
planeGeometry2Mat.color = new THREE.Color(e);
169169
scene.remove(plane2);
170170
plane2 = new THREE.Mesh(planeGeometry2, planeGeometry2Mat);
171-
plane2.position = areaLight2.position;
171+
plane2.position.copy(areaLight2.position);
172172
scene.add(plane2);
173173
});
174174
gui.add(controls, 'intensity2', 0, 5).onChange(function (e) {
@@ -179,7 +179,7 @@
179179
planeGeometry3Mat.color = new THREE.Color(e);
180180
scene.remove(plane3);
181181
plane3 = new THREE.Mesh(planeGeometry1, planeGeometry3Mat);
182-
plane3.position = areaLight3.position;
182+
plane3.position.copy(areaLight3.position);
183183
scene.add(plane3);
184184
});
185185
gui.add(controls, 'intensity3', 0, 5).onChange(function (e) {

chapter-07/04-program-based-sprites.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
<script type="text/javascript" src="../libs/jquery-1.9.0.js"></script>
99
<script type="text/javascript" src="../libs/stats.js"></script>
1010
<script type="text/javascript" src="../libs/dat.gui.js"></script>
11+
<script type="text/javascript" src="../libs/CanvasRenderer.js"></script>
12+
<script type="text/javascript" src="../libs/Projector.js"></script>
1113
<style>
1214
body {
1315
/* set margin to 0 and overflow to hidden, to go fullscreen */
@@ -108,7 +110,7 @@
108110

109111
function createSprites() {
110112
var material = new THREE.SpriteCanvasMaterial({
111-
program: draw,
113+
program: getTexture,
112114
color: 0xffffff}
113115
);
114116

0 commit comments

Comments
 (0)