Files
three.js/examples/webgl_materials_normalmap2.html
T
alteredq 942a6c89c9 Updated Clock to be more compatible with Timer (now uses seconds and getDelta API).
Lots of code got cleaner with seconds, seems we used them before all around.

Also changed examples that didn't need deltas to simple Date.now() plus some more examples cleaning, trying to get rid of obsolescence warnings.
2011-10-15 00:57:50 +02:00

207 lines
5.1 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<title>three.js webgl - materials - normal map [Lee Perry-Smith]</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 {
background:#000;
color:#fff;
padding:0;
margin:0;
font-weight: bold;
overflow:hidden;
}
a { color: #ffffff; }
#info {
position: absolute;
top: 0px; width: 100%;
color: #ffffff;
padding: 5px;
font-family:Monospace;
font-size:13px;
text-align:center;
z-index:1000;
}
#oldie {
background:rgb(200,100,0) !important;
color:#fff;
}
#vt { display:none }
#vt, #vt a { color:orange; }
.code { }
</style>
</head>
<body>
<div id="info">
<a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - webgl normalmap demo.
<a href="http://www.ir-ltd.net/infinite-3d-head-scan-released/" target="_blank">Lee Perry-Smith</a> head.
<div id="vt">displacement mapping needs vertex textures (GPU with Shader Model 3.0)<br/>
on Windows use <span class="code">Chrome --use-gl=desktop</span> or Firefox 4<br/>
please star this <a href="http://code.google.com/p/chromium/issues/detail?id=52497">Chrome issue</a> to get ANGLE support
</div>
</div>
<script src="../build/Three.js"></script>
<script src="js/Detector.js"></script>
<script src="js/RequestAnimationFrame.js"></script>
<script src="js/Stats.js"></script>
<script>
if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
var statsEnabled = true;
var container, stats, loader;
var camera, scene, renderer;
var mesh, zmesh, lightMesh, geometry;
var mesh1;
var directionalLight, pointLight, ambientLight;
var mouseX = 0;
var mouseY = 0;
var windowHalfX = window.innerWidth / 2;
var windowHalfY = window.innerHeight / 2;
init();
animate();
function init() {
container = document.createElement( 'div' );
document.body.appendChild( container );
camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 10000 );
camera.position.z = 900;
scene = new THREE.Scene();
// LIGHTS
ambientLight = new THREE.AmbientLight( 0x444444 );
scene.add( ambientLight );
pointLight = new THREE.PointLight( 0xffffff );
pointLight.position.z = 600;
scene.add( pointLight );
directionalLight = new THREE.DirectionalLight( 0xffffff );
directionalLight.position.set( 1, 1, -1 ).normalize();
scene.add( directionalLight );
// material parameters
var ambient = 0x111111, diffuse = 0xaaaaaa, specular = 0x080810, shininess = 2;
var shader = THREE.ShaderUtils.lib[ "normal" ];
var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
uniforms[ "tNormal" ].texture = THREE.ImageUtils.loadTexture( "obj/leeperrysmith/Infinite-Level_02_Tangent_SmoothUV.jpg" );
uniforms[ "uNormalScale" ].value = - 0.75;
uniforms[ "tDiffuse" ].texture = THREE.ImageUtils.loadTexture( "obj/leeperrysmith/Map-COL.jpg" );
uniforms[ "enableAO" ].value = false;
uniforms[ "enableDiffuse" ].value = true;
uniforms[ "enableSpecular" ].value = false;
uniforms[ "uDiffuseColor" ].value.setHex( diffuse );
uniforms[ "uSpecularColor" ].value.setHex( specular );
uniforms[ "uAmbientColor" ].value.setHex( ambient );
uniforms[ "uShininess" ].value = shininess;
var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights: true };
var material = new THREE.ShaderMaterial( parameters );
loader = new THREE.JSONLoader( true );
document.body.appendChild( loader.statusDomElement );
loader.load( "obj/leeperrysmith/LeePerrySmith.js", function( geometry ) { createScene( geometry, 100, material ) } );
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
if ( statsEnabled ) {
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
stats.domElement.style.zIndex = 100;
container.appendChild( stats.domElement );
}
document.addEventListener( 'mousemove', onDocumentMouseMove, false );
}
function createScene( geometry, scale, material ) {
geometry.computeTangents();
mesh1 = new THREE.Mesh( geometry, material );
mesh1.position.y = - 50;
mesh1.scale.x = mesh1.scale.y = mesh1.scale.z = scale;
scene.add( mesh1 );
loader.statusDomElement.style.display = "none";
}
function onDocumentMouseMove(event) {
mouseX = ( event.clientX - windowHalfX ) * 10;
mouseY = ( event.clientY - windowHalfY ) * 10;
}
//
function animate() {
requestAnimationFrame( animate );
render();
if ( statsEnabled ) stats.update();
}
function render() {
var ry = mouseX * 0.0003, rx = mouseY * 0.0003;
if( mesh1 ) {
mesh1.rotation.y = ry;
mesh1.rotation.x = rx;
}
renderer.render( scene, camera );
}
</script>
</body>
</html>