mirror of
https://github.com/wahyd4/three.js.git
synced 2026-08-15 07:56:00 +10:00
This commit has handful of things going on:
- had to sacrifice one light to please ANGLE, making it again up to 4 instead of up to 5 total lights :(
- Basic / Lambert / Phong materials now have new parameters:
"combine": THREE.Mix | THREE.Multiply [default]
- tells how to combine environment map with the original material:
- "Multiply" creates chrome-like metallic look (it's what was already there),
color of the underlying material is multiplied with the environment map,
this creates different colored metals
- "Mix" creates shiny plastic look
color of the underlying material is lerped with the environment map,
amount of the contribution from the environment map is controlled
by another new parameter "reflectivity"
"reflectivity": <float> [from <0.0, 1.0>]
- controls mixing of underlying material and environment map for "Mix" combine mode
0: pure underlying material, zero contribution from environment map (Basic/Lambert/Phong)
1: pure environment map, zero contribution from underlying material (uncolored chrome look)
"refraction_ratio": <float>
- controls refractive mapping, ratio of the index of refraction in the medium containing the incident ray
to that of the medium being entered
- sensible values seem to be from ~0.6 - 1.0
(in theory, e.g. air/glass should be 0.75, but this looks weird, values between 0.9 - 1.0 give the most interesting results,
though maybe there is bug somewhere in my code)
- for use refraction mapping, just add parameter to TextureCube like this (default is reflection mapping)
"new THREE.TextureCube( images, THREE.RefractionMap )"
179 lines
5.0 KiB
HTML
179 lines
5.0 KiB
HTML
<!DOCTYPE HTML>
|
|
<html lang="en">
|
|
<head>
|
|
<title>three.js - point light WebGL</title>
|
|
<meta charset="utf-8">
|
|
<style type="text/css">
|
|
body {
|
|
background-color: #000;
|
|
margin: 0px;
|
|
overflow: hidden;
|
|
}
|
|
|
|
#info {
|
|
position: absolute;
|
|
top: 0px; width: 100%;
|
|
color: #ffffff;
|
|
padding: 5px;
|
|
font-family: Monospace;
|
|
font-size: 13px;
|
|
text-align: center;
|
|
}
|
|
|
|
a {
|
|
color: #ff0080;
|
|
text-decoration: none;
|
|
}
|
|
|
|
a:hover {
|
|
color: #0080ff;
|
|
}
|
|
|
|
#log { color:#fff; position:absolute; top:50px; text-align:left; display:block; z-index:100; pointer-events:none; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<pre id="log"></pre>
|
|
|
|
<div id="container"></div>
|
|
<div id="info">
|
|
<a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - point lights WebGL demo.<br />
|
|
Walt Disney head by <a href="http://www.davidoreilly.com/2009/01/walt-disneys-head-on-a-plate" target="_blank">David OReilly</a>
|
|
</div>
|
|
|
|
<script type="text/javascript" src="../build/Three.js"></script>
|
|
|
|
<script type="text/javascript" src="../src/extras/io/Loader.js"></script>
|
|
<script type="text/javascript" src="../src/extras/primitives/Sphere.js"></script>
|
|
|
|
<script type="text/javascript" src="js/Stats.js"></script>
|
|
|
|
<script type="text/javascript">
|
|
|
|
var camera, scene, renderer,
|
|
particle1, particle2, particle2,
|
|
light1, light2, light3,
|
|
object;
|
|
|
|
init();
|
|
setInterval( loop, 1000 / 60 );
|
|
|
|
function init() {
|
|
|
|
var container = document.getElementById( 'container' );
|
|
|
|
camera = new THREE.Camera( 65, window.innerWidth / window.innerHeight, 1, 1000 );
|
|
camera.position.z = 100;
|
|
|
|
scene = new THREE.Scene();
|
|
|
|
var loader = new THREE.Loader();
|
|
|
|
loader.loadAscii( "obj/walt/WaltHead_slim.js", function( geometry ) {
|
|
|
|
//object = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial( { ambient: 0x555555, color: 0x555555, specular: 0xffffff, shininess: 50, shading: THREE.FlatShading } ) );
|
|
object = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial( { ambient: 0x555555, color: 0x555555, specular: 0xffffff, shininess: 50, shading: THREE.SmoothShading } ) );
|
|
object.scale.x = object.scale.y = object.scale.z = 0.80;
|
|
object.overdraw = true;
|
|
scene.addObject( object );
|
|
|
|
});
|
|
|
|
|
|
/*
|
|
loader.loadBinary( "obj/walt/WaltHead_bin.js", function( geometry ) {
|
|
|
|
object = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial( 0x555555, 0x555555, 0xffffff, 50, 1.0 ) );
|
|
object.scale.x = object.scale.y = object.scale.z = 0.80;
|
|
object.overdraw = true;
|
|
scene.addObject( object );
|
|
|
|
}, "obj/walt");
|
|
*/
|
|
|
|
/*
|
|
var directionalLight = new THREE.DirectionalLight( 0x111111, 0.9 );
|
|
directionalLight.position.x = 1;
|
|
directionalLight.position.y = 1;
|
|
directionalLight.position.z = 2;
|
|
directionalLight.position.normalize();
|
|
scene.addLight( directionalLight );
|
|
*/
|
|
|
|
scene.addLight( new THREE.AmbientLight( 0x00020 ) );
|
|
scene.addLight( new THREE.AmbientLight( 0x00000 ) );
|
|
|
|
light1 = new THREE.PointLight( 0xff0040 );
|
|
scene.addLight( light1 );
|
|
|
|
light2 = new THREE.PointLight( 0x0040ff );
|
|
scene.addLight( light2 );
|
|
|
|
light3 = new THREE.PointLight( 0x80ff80 );
|
|
scene.addLight( light3 );
|
|
|
|
var sphere = new Sphere( 0.5, 16, 8, 1 );
|
|
|
|
var l1 = new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: 0xff0040 } ) );
|
|
l1.position = light1.position;
|
|
scene.addObject( l1 );
|
|
|
|
var l2 = new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: 0x0040ff } ) );
|
|
l2.position = light2.position;
|
|
scene.addObject( l2 );
|
|
|
|
var l3 = new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: 0x80ff80 } ) );
|
|
l3.position = light3.position;
|
|
scene.addObject( l3 );
|
|
|
|
//renderer = new THREE.CanvasRenderer();
|
|
renderer = new THREE.WebGLRenderer( scene );
|
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
|
container.appendChild( renderer.domElement );
|
|
|
|
/*
|
|
stats = new Stats();
|
|
stats.domElement.style.position = 'absolute';
|
|
stats.domElement.style.top = '0px';
|
|
stats.domElement.style.zIndex = 100;
|
|
container.appendChild( stats.domElement );
|
|
*/
|
|
|
|
}
|
|
|
|
function loop() {
|
|
|
|
var time = new Date().getTime() * 0.0005;
|
|
|
|
if( object ) object.rotation.y -= 0.01;
|
|
|
|
light1.position.x = Math.sin( time * 0.7 ) * 30;
|
|
light1.position.y = Math.cos( time * 0.5 ) * 40;
|
|
light1.position.z = Math.cos( time * 0.3 ) * 30;
|
|
|
|
light2.position.x = Math.cos( time * 0.3 ) * 30;
|
|
light2.position.y = Math.sin( time * 0.5 ) * 40;
|
|
light2.position.z = Math.sin( time * 0.7 ) * 30;
|
|
|
|
light3.position.x = Math.sin( time * 0.7 ) * 30;
|
|
light3.position.y = Math.cos( time * 0.3 ) * 40;
|
|
light3.position.z = Math.sin( time * 0.5 ) * 30;
|
|
|
|
renderer.render(scene, camera);
|
|
|
|
//stats.update();
|
|
|
|
}
|
|
|
|
function log( text ) {
|
|
|
|
var e = document.getElementById("log");
|
|
e.innerHTML = text + "<br/>" + e.innerHTML;
|
|
|
|
}
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|