Skip to content

Commit

Permalink
Added spotlight.
Browse files Browse the repository at this point in the history
Lightmap shader now supports realtime lights. Scene/Transform.contains method added. Bunker demo has a headlight now. Light.direction removed, now uses the forward vector of it's transform.
  • Loading branch information
drojdjou committed Dec 30, 2011
1 parent 6aafa72 commit 5b82683
Show file tree
Hide file tree
Showing 22 changed files with 286 additions and 197 deletions.
70 changes: 35 additions & 35 deletions build/j3d.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion demo/000_HelloCube.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
light = new J3D.Transform();
light.light = new J3D.Light(J3D.DIRECT);
light.light.color = new J3D.Color(0.5, 0.5, 0.5, 1);
light.light.direction = new v3(1, 0, 1).norm();
light.rotation = new v3(-Math.PI, 0, Math.PI);

cube = new J3D.Transform();
cube.geometry = J3D.Primitive.Cube(1, 1, 1);
Expand Down
1 change: 0 additions & 1 deletion demo/001_Lights.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
light1 = new J3D.Transform();
light1.light = new J3D.Light(J3D.SPHERICAL_HARMONICS);
light1.light.color = new J3D.Color(0.33, 0.33, 0, 1);
light1.light.direction = new v3(0, -1, 0).norm();
light1.light.intensity = 2.5;

sun = new J3D.Transform();
Expand Down
11 changes: 2 additions & 9 deletions demo/002_Scene.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
rings[6] = engine.scene.find("root/ring/ring/ring/ring/ring/ring/ring");

for(var i = 0; i < 7; i++) {
rings[i].collider = J3D.Collider.Mesh(rings[i].geometry);
rings[i].originalRenderer = rings[i].renderer;
}

Expand Down Expand Up @@ -66,14 +65,8 @@
for(var i = 0; i < 7; i++) {
var h = J3D.Intersection.rayTest(r, rings[i]);
rings[i].renderer = (h) ? whiteMat : rings[i].originalRenderer;

if(i == 0) {
rings[i].rotation.y = sx;
rings[i].rotation.x = sy;
} else {
rings[i].rotation.y = sx + (sx * i * 0.02);
rings[i].rotation.x = sy + (sy * i * 0.02);
}
rings[i].rotation.y = sx + (sx * i * 0.02);
rings[i].rotation.x = sy + (sy * i * 0.02);
}

root.rotation.y = sx;
Expand Down
28 changes: 25 additions & 3 deletions demo/008_Lightmap.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

<script>
var mx = 0, my = 0;
var fps, eye, walls;
var fps, eye, walls, headlight;
var lightmaps, nolightmaps;
var showmaps = true;
var moveLeft = 0, moveForward = 0;
Expand All @@ -70,14 +70,35 @@
fps = engine.scene.find("fps");
eye = engine.scene.find("fps/eye");
walls = engine.scene.find("bunker/walls");

var hl = new J3D.Light(J3D.SPOTLIGHT);
hl.direction = v3.FORWARD();
hl.angle = Math.PI / 16;
hl.angleFalloff = Math.PI / 32;
hl.intensity = 0.5;

headlight = new J3D.Transform();
headlight.light = hl;

eye.add(headlight);

draw();
})
});

document.onmousemove = onMouseMove;
document.onmousedown = onMouseDown;
document.onkeydown = onKeyDown;
document.onkeyup = onKeyUp;
}

function onMouseDown(e) {
if(eye.contains(headlight)) {
eye.remove(headlight);
} else {
eye.add(headlight);
}
}

function onKeyDown(e) {
switch(e.keyCode) {
Expand Down Expand Up @@ -158,8 +179,9 @@

fps.position = fps.position.add(m);

if(document.getElementById("dizzy").checked) post.render();
else engine.render();
//if(document.getElementById("dizzy").checked) post.render();
//else
engine.render();

requestAnimationFrame(draw);
}
Expand Down
3 changes: 2 additions & 1 deletion demo/010_ToonShading.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
sun = new J3D.Transform();
sun.light = new J3D.Light(J3D.DIRECT);
sun.light.color = new J3D.Color(1.0); // Toon shader uses only one channel for light calculations: r
sun.light.direction = new v3(-1, 0, -1).norm();
//sun.rotation.x = Math.PI;
sun.rotation.z = Math.PI;

elephant = new J3D.Transform();
elephant.rotation = new v3(0, Math.PI, 0);
Expand Down
2 changes: 1 addition & 1 deletion demo/015_Persistence.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
light = new J3D.Transform();
light.light = new J3D.Light(J3D.DIRECT);
light.light.color = new J3D.Color(0.8, 0.8, 0.8, 1);
light.light.direction = new v3(1, 0, 1).norm();
light.rotation = new v3(-Math.PI, 0, Math.PI);

cube = new J3D.Transform();
cube.geometry = J3D.Primitive.Cube(1, 1, 1);
Expand Down
6 changes: 3 additions & 3 deletions demo/017_SceneManagement.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@
sun = new J3D.Transform();
sun.light = new J3D.Light(J3D.DIRECT);
sun.light.color = new J3D.Color(0.75, 0.75, 0.75, 1);
sun.light.direction = new v3(0, -1, 0).norm();
sun.rotation.y = Math.PI / 2;

camera = new J3D.Transform();
camera.camera = new J3D.Camera({ fov:30 });
camera.position.z = 12;
engine.camera = camera;

camroot = new J3D.Transform();
camroot.add(camera);
camroot.add(camera, sun);

post = new J3D.Persistence(engine);
post.blendFilter = new J3D.ShaderUtil.parseGLSL(document.getElementById("blendFilter").firstChild.nodeValue);
Expand Down Expand Up @@ -118,7 +118,7 @@
}

function populateScene() {
engine.scene.add(camroot, sun, ambient);
engine.scene.add(camroot, ambient);
addCube(null, 0, 0);
}

Expand Down
83 changes: 27 additions & 56 deletions demo/models/008/bunkerScene.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,17 @@
"red": {
"type": "Lightmap",
"color": { "r":0.6567164, "g":0, "b":0, "a":1 },
"specularIntensity": 0,
"shininess": 0,
"specularIntensity": 0.999,
"shininess": 0.7227132,
"textureTile": [ ],
"textureOffset": [ ]
},

"base": {
"type": "Lightmap",
"color": { "r":1, "g":1, "b":1, "a":1 },
"specularIntensity": 0,
"shininess": 0,
"specularIntensity": 0.999,
"shininess": 1,
"textureTile": [ 1,1 ],
"textureOffset": [ 0,0 ],
"colorTexture": "base"
Expand Down Expand Up @@ -206,8 +206,8 @@
"cabinet_front": {
"type": "Lightmap",
"color": { "r":1, "g":1, "b":1, "a":1 },
"specularIntensity": 0,
"shininess": 0,
"specularIntensity": 0.6933358,
"shininess": 0.5807685,
"textureTile": [ 1,1 ],
"textureOffset": [ 0,0 ],
"colorTexture": "cabinetfront"
Expand All @@ -216,17 +216,6 @@
},

"lights": {

"light": {
"type": 2,
"color": { "r":1, "g":1, "b":1, "a":1 }
},

"lamplight": {
"type": 2,
"color": { "r":0.9621125, "g":1, "b":0.7537314, "a":1 }
}

},

"cameras": {
Expand Down Expand Up @@ -919,15 +908,6 @@

{
"uid": 59,
"name": "light",
"parent": 55,
"position": [ -0.02425194,-0.3356099,-0.0005105734 ],
"rotation": [ 0,0,0 ],
"light": "light"
},

{
"uid": 60,
"name": "top",
"parent": 55,
"position": [ 0.45,1.027377,0 ],
Expand All @@ -939,7 +919,7 @@
},

{
"uid": 61,
"uid": 60,
"name": "largepipes",
"parent": 1,
"position": [ 0.02321442,2.337654,-1.935869 ],
Expand All @@ -955,7 +935,7 @@
},

{
"uid": 62,
"uid": 61,
"name": "pipe",
"parent": 1,
"position": [ -3.801011,1.400015,1.891272 ],
Expand All @@ -971,7 +951,7 @@
},

{
"uid": 63,
"uid": 62,
"name": "pipeending",
"parent": 1,
"position": [ -0.005020904,2.336824,-1.936106 ],
Expand All @@ -987,7 +967,7 @@
},

{
"uid": 64,
"uid": 63,
"name": "pipeholder",
"parent": 1,
"position": [ 0.05540344,2.497553,-1.936754 ],
Expand All @@ -1003,25 +983,25 @@
},

{
"uid": 65,
"uid": 64,
"name": "desk",
"parent": 1,
"position": [ -2.262847,-0.0016675,1.185786 ],
"rotation": [ 0,-0.3045448,0 ]
},

{
"uid": 66,
"uid": 65,
"name": "lamp",
"parent": 65,
"parent": 64,
"position": [ -0.4605259,0.8137751,0.2702942 ],
"rotation": [ 0,0.9535775,0 ]
},

{
"uid": 67,
"uid": 66,
"name": "base",
"parent": 66,
"parent": 65,
"position": [ 0,-0.0002431488,0 ],
"rotation": [ 0,0,0 ],
"renderer": "red",
Expand All @@ -1031,18 +1011,9 @@
},

{
"uid": 68,
"name": "lamplight",
"parent": 66,
"position": [ 0.01885286,0.2885832,0.1991458 ],
"rotation": [ -0.7753192,-1.795006,-1.664385 ],
"light": "lamplight"
},

{
"uid": 69,
"uid": 67,
"name": "stem",
"parent": 66,
"parent": 65,
"position": [ -0.009898948,0.01331375,-0.0006131363 ],
"rotation": [ 0,0,0 ],
"renderer": "darkgrey",
Expand All @@ -1052,9 +1023,9 @@
},

{
"uid": 70,
"uid": 68,
"name": "topinterior",
"parent": 66,
"parent": 65,
"position": [ -0.0006007031,0.399937,0.1621105 ],
"rotation": [ -0.2734099,-0.3037378,0.1247429 ],
"renderer": "white",
Expand All @@ -1064,9 +1035,9 @@
},

{
"uid": 71,
"uid": 69,
"name": "topexterior",
"parent": 66,
"parent": 65,
"position": [ -0.0006007031,0.399937,0.1621105 ],
"rotation": [ -0.2734099,-0.3037376,0.1247429 ],
"renderer": "red",
Expand All @@ -1076,9 +1047,9 @@
},

{
"uid": 72,
"uid": 70,
"name": "table",
"parent": 65,
"parent": 64,
"position": [ 0,0,0 ],
"rotation": [ 0,0,0 ],
"renderer": "wood",
Expand All @@ -1088,7 +1059,7 @@
},

{
"uid": 73,
"uid": 71,
"name": "walls",
"parent": 1,
"position": [ 0.4991992,-5.299922,0.09999999 ],
Expand All @@ -1104,16 +1075,16 @@
},

{
"uid": 74,
"uid": 72,
"name": "fps",
"position": [ 0,0,0 ],
"rotation": [ 0,0,0 ]
},

{
"uid": 75,
"uid": 73,
"name": "eye",
"parent": 74,
"parent": 72,
"position": [ 0,1.177749,0 ],
"rotation": [ 0,0,0 ],
"camera": "eye"
Expand Down
Loading

0 comments on commit 5b82683

Please sign in to comment.