Browse Source

I knew it wasn't going to work.

Mr.doob 14 years ago
parent
commit
ebaa3ae392
2 changed files with 44 additions and 30 deletions
  1. 37 20
      examples/materials_normalmap2.html
  2. 7 10
      src/core/Geometry.js

+ 37 - 20
examples/materials_normalmap2.html

@@ -105,6 +105,8 @@
 			var windowHalfX = window.innerWidth / 2;
 			var windowHalfY = window.innerHeight / 2;
 
+			var r = 0.0;
+
 			document.addEventListener( 'mousemove', onDocumentMouseMove, false );
 
 			init();
@@ -122,55 +124,65 @@
 
 				// LIGHTS
 
-				ambientLight = new THREE.AmbientLight( 0x444444 );
+				ambientLight = new THREE.AmbientLight( 0x050505 );
 				scene.addLight( ambientLight );
 
-				pointLight = new THREE.PointLight( 0xffffff );
-				pointLight.position.z = 600;
-
+				pointLight = new THREE.PointLight( 0x999999 );
+				pointLight.position.z = 10000;
 				scene.addLight( pointLight );
 
-				directionalLight = new THREE.DirectionalLight( 0xffffff );
-				directionalLight.position.x = 1;
-				directionalLight.position.y = 1;
-				directionalLight.position.z = - 1;
+				directionalLight = new THREE.DirectionalLight( 0xbbbbbb );
+				directionalLight.position.x = 0;
+				directionalLight.position.y = 0;
+				directionalLight.position.z = 1;
 				directionalLight.position.normalize();
 				scene.addLight( directionalLight );
 
-				// material parameters
+				// light representation
 
-				var ambient = 0x444444, diffuse = 0x555555, specular = 0x181820, shininess = 2;
+				var sphere = new Sphere( 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.addObject(lightMesh);
+
+				// material parameters
+				
+				var ambient = 0x020202, diffuse = 0x666666, specular = 0x444444, shininess = 2;
 
 				var fragment_shader = ShaderUtils.lib[ "normal" ].fragment_shader;
 				var vertex_shader = ShaderUtils.lib[ "normal" ].vertex_shader;
 				var uniforms = ShaderUtils.lib[ "normal" ].uniforms;
  
 				uniforms[ "tNormal" ].texture = ImageUtils.loadTexture( "obj/leeperrysmith/Infinite-Level_02_Tangent_SmoothUV.jpg" );
-				uniforms[ "uNormalScale" ].value = - 0.75;
-
 				uniforms[ "tDiffuse" ].texture = ImageUtils.loadTexture( "obj/leeperrysmith/Map-COL.jpg" );
-
+				
 				uniforms[ "enableAO" ].value = false;
 				uniforms[ "enableDiffuse" ].value = true;
-
+				
 				uniforms[ "uPointLightPos" ].value = pointLight.position;
 				uniforms[ "uPointLightColor" ].value = pointLight.color;
 
 				uniforms[ "uDirLightPos" ].value = directionalLight.position;
 				uniforms[ "uDirLightColor" ].value = directionalLight.color;
-
+				
 				uniforms[ "uAmbientLightColor" ].value = ambientLight.color;
-
+				
 				uniforms[ "uDiffuseColor" ].value.setHex( diffuse );
 				uniforms[ "uSpecularColor" ].value.setHex( specular );
 				uniforms[ "uAmbientColor" ].value.setHex( ambient );
-
+				
 				uniforms[ "uShininess" ].value = shininess;
 
+				
 				var material = new THREE.MeshShaderMaterial( { fragment_shader: fragment_shader, 
-									    vertex_shader: vertex_shader, 
-									    uniforms: uniforms
-									  } );
+															    vertex_shader: vertex_shader, 
+															    uniforms: uniforms
+															  } );
+				
+				//var material = new THREE.MeshLambertMaterial( { map: ImageUtils.loadTexture( "obj/leeperrysmith/Map-COL.jpg" ) } );
+				
+				//var material = new THREE.MeshPhongMaterial( { color: diffuse, specular: specular, ambient: ambient, shininess: shininess, map: ImageUtils.loadTexture( "obj/leeperrysmith/Map-COL.jpg" ) } );
 
 				loader = new THREE.Loader( true );
 				document.body.appendChild( loader.statusDomElement );
@@ -221,6 +233,11 @@
 
 				}
 
+				lightMesh.position.x = 500 * Math.cos( r );
+				lightMesh.position.z = 500 * Math.sin( r );
+
+				r += 0.01;
+
 				webglRenderer.render( scene, camera );
 
 				if ( statsEnabled ) stats.update();

+ 7 - 10
src/core/Geometry.js

@@ -192,15 +192,15 @@ THREE.Geometry.prototype = {
 
 		}
 
-		function handleTriangle( context, a, b, c ) {
+		function handleTriangle( context, a, b, c, ua, ub, uc ) {
 
 			vA = context.vertices[ a ].position;
 			vB = context.vertices[ b ].position;
 			vC = context.vertices[ c ].position;
 
-			uvA = uv[ 0 ];
-			uvB = uv[ 1 ];
-			uvC = uv[ 2 ];
+			uvA = uv[ ua ];
+			uvB = uv[ ub ];
+			uvC = uv[ uc ];
 
 			x1 = vB.x - vA.x;
 			x2 = vC.x - vA.x;
@@ -239,7 +239,7 @@ THREE.Geometry.prototype = {
 
 			if ( face instanceof THREE.Face3 ) {
 
-				handleTriangle( this, face.a, face.b, face.c );
+				handleTriangle( this, face.a, face.b, face.c, 0, 1, 2 );
 
 				this.vertices[ face.a ].normal.copy( face.vertexNormals[ 0 ] );
 				this.vertices[ face.b ].normal.copy( face.vertexNormals[ 1 ] );
@@ -248,11 +248,8 @@ THREE.Geometry.prototype = {
 
 			} else if ( face instanceof THREE.Face4 ) {
 
-				handleTriangle( this, face.a, face.b, face.c );
-
-				// this messes up everything
-				// quads need to be handled differently
-				//handleTriangle( this, face.a, face.c, face.d );
+				handleTriangle( this, face.a, face.b, face.c, 0, 1, 2 );
+				handleTriangle( this, face.a, face.b, face.d, 0, 1, 3 );
 
 				this.vertices[ face.a ].normal.copy( face.vertexNormals[ 0 ] );
 				this.vertices[ face.b ].normal.copy( face.vertexNormals[ 1 ] );