|
@@ -40,14 +40,14 @@
|
|
|
<body>
|
|
|
|
|
|
<div id="info">
|
|
|
- <a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - webgl (<span id="description">normal + ao + displacement</span>) map demo.
|
|
|
+ <a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - webgl (<span id="description">normal + ao + displacement + environment + shadow</span>) map demo.
|
|
|
ninja head from <a href="http://developer.amd.com/archive/gpu/MeshMapper/pages/default.aspx" target="_blank">AMD GPU MeshMapper</a>
|
|
|
|
|
|
<div id="vt">displacement mapping needs vertex textures (GPU with Shader Model 3.0)</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>
|
|
@@ -86,7 +86,7 @@
|
|
|
document.body.appendChild( container );
|
|
|
|
|
|
camera = new THREE.OrthographicCamera( window.innerWidth / - 2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / - 2, -10000, 10000 );
|
|
|
- camera.position.z = 6200;
|
|
|
+ camera.position.z = 1500;
|
|
|
|
|
|
scene = new THREE.Scene();
|
|
|
|
|
@@ -95,25 +95,57 @@
|
|
|
ambientLight = new THREE.AmbientLight( 0x111111 );
|
|
|
scene.add( ambientLight );
|
|
|
|
|
|
- pointLight = new THREE.PointLight( 0xffff55 );
|
|
|
+ pointLight = new THREE.PointLight( 0xff0000 );
|
|
|
pointLight.position.z = 10000;
|
|
|
+ pointLight.distance = 4000;
|
|
|
scene.add( pointLight );
|
|
|
|
|
|
- directionalLight = new THREE.DirectionalLight( 0xaaaa88 );
|
|
|
- directionalLight.position.set( 1, 1, 0.5 ).normalize();
|
|
|
+ pointLight2 = new THREE.PointLight( 0xff5500 );
|
|
|
+ pointLight2.position.z = 1000;
|
|
|
+ pointLight2.distance = 2000;
|
|
|
+ scene.add( pointLight2 );
|
|
|
+
|
|
|
+ pointLight3 = new THREE.PointLight( 0x0000ff );
|
|
|
+ pointLight3.position.x = -1000;
|
|
|
+ pointLight3.position.z = 1000;
|
|
|
+ pointLight3.distance = 2000;
|
|
|
+ scene.add( pointLight3 );
|
|
|
+
|
|
|
+ directionalLight = new THREE.SpotLight( 0xaaaaaa );
|
|
|
+ directionalLight.position.set( 1000, 500, 1000 );
|
|
|
+ directionalLight.castShadow = true;
|
|
|
scene.add( directionalLight );
|
|
|
|
|
|
+ directionalLight2 = new THREE.DirectionalLight( 0xaaff33, 0 );
|
|
|
+ directionalLight2.position.set( -1, 1, 0.5 ).normalize();
|
|
|
+ //scene.add( directionalLight2 );
|
|
|
+
|
|
|
+ directionalLight3 = new THREE.DirectionalLight( 0xaaff33 );
|
|
|
+ directionalLight3.position.set( -1, 1, 0.5 ).normalize();
|
|
|
+ //scene.add( directionalLight3 );
|
|
|
+
|
|
|
+
|
|
|
// light representation
|
|
|
|
|
|
var sphere = new THREE.SphereGeometry( 100, 16, 8 );
|
|
|
lightMesh = new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: 0xffaa00 } ) );
|
|
|
lightMesh.position = pointLight.position;
|
|
|
lightMesh.scale.x = lightMesh.scale.y = lightMesh.scale.z = 0.05;
|
|
|
- scene.add( lightMesh );
|
|
|
+ //scene.add( lightMesh );
|
|
|
+
|
|
|
+ var path = "textures/cube/SwedishRoyalCastle/";
|
|
|
+ var format = '.jpg';
|
|
|
+ var urls = [
|
|
|
+ path + 'px' + format, path + 'nx' + format,
|
|
|
+ path + 'py' + format, path + 'ny' + format,
|
|
|
+ path + 'pz' + format, path + 'nz' + format
|
|
|
+ ];
|
|
|
+
|
|
|
+ var reflectionCube = THREE.ImageUtils.loadTextureCube( urls );
|
|
|
|
|
|
// common material parameters
|
|
|
|
|
|
- var ambient = 0x050505, diffuse = 0x555555, specular = 0xaa6600, shininess = 10, scale = 23;
|
|
|
+ var ambient = 0x050505, diffuse = 0x331100, specular = 0xffffff, shininess = 10, scale = 23;
|
|
|
|
|
|
// normal map shader
|
|
|
|
|
@@ -123,6 +155,7 @@
|
|
|
uniforms[ "enableAO" ].value = true;
|
|
|
uniforms[ "enableDiffuse" ].value = false;
|
|
|
uniforms[ "enableSpecular" ].value = false;
|
|
|
+ uniforms[ "enableReflection" ].value = true;
|
|
|
|
|
|
uniforms[ "tNormal" ].texture = THREE.ImageUtils.loadTexture( "textures/normal/ninja/normal.jpg" );
|
|
|
uniforms[ "tAO" ].texture = THREE.ImageUtils.loadTexture( "textures/normal/ninja/ao.jpg" );
|
|
@@ -137,10 +170,13 @@
|
|
|
|
|
|
uniforms[ "uShininess" ].value = shininess;
|
|
|
|
|
|
- var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights: true };
|
|
|
+ uniforms[ "tCube" ].texture = reflectionCube;
|
|
|
+ uniforms[ "uReflectivity" ].value = 0.1;
|
|
|
+
|
|
|
+ var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights: true, fog: false };
|
|
|
var material1 = new THREE.ShaderMaterial( parameters );
|
|
|
|
|
|
- var material2 = new THREE.MeshPhongMaterial( { color: diffuse, specular: specular, ambient: ambient, shininess: shininess } );
|
|
|
+ var material2 = new THREE.MeshPhongMaterial( { color: diffuse, specular: specular, ambient: ambient, shininess: shininess, envMap: reflectionCube, combine: THREE.MixOperation, reflectivity: 0.1 } );
|
|
|
|
|
|
//
|
|
|
|
|
@@ -151,13 +187,22 @@
|
|
|
|
|
|
//
|
|
|
|
|
|
- renderer = new THREE.WebGLRenderer();
|
|
|
+ renderer = new THREE.WebGLRenderer( { maxLights: 8 } );
|
|
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
container.appendChild( renderer.domElement );
|
|
|
|
|
|
//
|
|
|
|
|
|
- var description = "normal + ao" + ( renderer.supportsVertexTextures() ? " + displacement" : " + <strike>displacement</strike>" );
|
|
|
+ renderer.shadowCameraFov = 70;
|
|
|
+ renderer.shadowMapBias = 0.0039;
|
|
|
+
|
|
|
+ renderer.shadowMapEnabled = true;
|
|
|
+ renderer.shadowMapSoft = true;
|
|
|
+
|
|
|
+
|
|
|
+ //
|
|
|
+
|
|
|
+ var description = "normal + ao" + ( renderer.supportsVertexTextures() ? " + displacement + environment + shadow" : " + <strike>displacement</strike>" );
|
|
|
document.getElementById( "description" ).innerHTML = description;
|
|
|
document.getElementById( "vt" ).style.display = renderer.supportsVertexTextures() ? "none" : "block";
|
|
|
|
|
@@ -180,11 +225,15 @@
|
|
|
mesh1 = new THREE.Mesh( geometry, material1 );
|
|
|
mesh1.position.x = - scale * 12;
|
|
|
mesh1.scale.set( scale, scale, scale );
|
|
|
+ mesh1.castShadow = true;
|
|
|
+ mesh1.receiveShadow = true;
|
|
|
scene.add( mesh1 );
|
|
|
|
|
|
mesh2 = new THREE.Mesh( geometry, material2 );
|
|
|
mesh2.position.x = scale * 12;
|
|
|
mesh2.scale.set( scale, scale, scale );
|
|
|
+ mesh2.castShadow = true;
|
|
|
+ mesh2.receiveShadow = true;
|
|
|
scene.add( mesh2 );
|
|
|
|
|
|
loader.statusDomElement.style.display = "none";
|