Browse Source

Merged with alteredq's normal shader improvements.
Tweaked normalmap2 demo parameters.

Mr.doob 14 years ago
parent
commit
897a2938c5
3 changed files with 21 additions and 59 deletions
  1. 0 0
      build/ThreeExtras.js
  2. 15 33
      examples/materials_normalmap2.html
  3. 6 26
      src/extras/ShaderUtils.js

File diff suppressed because it is too large
+ 0 - 0
build/ThreeExtras.js


+ 15 - 33
examples/materials_normalmap2.html

@@ -105,8 +105,6 @@
 			var windowHalfX = window.innerWidth / 2;
 			var windowHalfY = window.innerHeight / 2;
 
-			var r = 0.0;
-
 			document.addEventListener( 'mousemove', onDocumentMouseMove, false );
 
 			init();
@@ -117,45 +115,38 @@
 				container = document.createElement('div');
 				document.body.appendChild(container);
 
-				camera = new THREE.Camera( 60, window.innerWidth / window.innerHeight, 1, 10000 );
-				camera.position.z = 800;
+				camera = new THREE.Camera( 50, window.innerWidth / window.innerHeight, 1, 10000 );
+				camera.position.z = 900;
 
 				scene = new THREE.Scene();
 
 				// LIGHTS
 
-				ambientLight = new THREE.AmbientLight( 0x555566 );
+				ambientLight = new THREE.AmbientLight( 0x444444 );
 				scene.addLight( ambientLight );
 
-				pointLight = new THREE.PointLight( 0x888877 );
-				pointLight.position.z = 400;
+				pointLight = new THREE.PointLight( 0xffffff );
+				pointLight.position.z = 600;
+
 				scene.addLight( pointLight );
 
-				directionalLight = new THREE.DirectionalLight( 0x999955 );
+				directionalLight = new THREE.DirectionalLight( 0xffffff );
 				directionalLight.position.x = 1;
 				directionalLight.position.y = 1;
-				directionalLight.position.z = 0.5;
+				directionalLight.position.z = - 1;
 				directionalLight.position.normalize();
 				scene.addLight( directionalLight );
 
-				// light representation
-
-				var sphere = new Sphere( 50, 16, 8 );
-				lightMesh = new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color:0xffffff, opacity: 0.5 } ) );
-				lightMesh.position = pointLight.position;
-				lightMesh.scale.x = lightMesh.scale.y = lightMesh.scale.z = 0.05;
-				scene.addObject(lightMesh);
-
 				// material parameters
 
-				var ambient = 0x666677, diffuse = 0x666666, specular = 0x111111, shininess = 2;
+				var ambient = 0x444444, diffuse = 0x555555, specular = 0x181820, 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 = - 1.5;
+				uniforms[ "uNormalScale" ].value = - 0.75;
 
 				uniforms[ "tDiffuse" ].texture = ImageUtils.loadTexture( "obj/leeperrysmith/Map-COL.jpg" );
 
@@ -176,12 +167,10 @@
 
 				uniforms[ "uShininess" ].value = shininess;
 
-				var material = new THREE.MeshShaderMaterial( { fragment_shader: fragment_shader,
-															    vertex_shader: vertex_shader,
-															    uniforms: uniforms
-															  } );
-
-				//var material = new THREE.MeshLambertMaterial( { map: ImageUtils.loadTexture( "obj/leeperrysmith/Map-COL.jpg" ) } );
+				var material = new THREE.MeshShaderMaterial( { fragment_shader: fragment_shader, 
+									    vertex_shader: vertex_shader, 
+									    uniforms: uniforms
+									  } );
 
 				loader = new THREE.Loader( true );
 				document.body.appendChild( loader.statusDomElement );
@@ -232,13 +221,6 @@
 
 				}
 
-				/*
-				lightMesh.position.x = 2500 * Math.cos( r );
-				lightMesh.position.z = 2500 * Math.sin( r );
-
-				r += 0.01;
-				*/
-
 				webglRenderer.render( scene, camera );
 
 				if ( statsEnabled ) stats.update();

+ 6 - 26
src/extras/ShaderUtils.js

@@ -101,9 +101,9 @@ var ShaderUtils = {
 			fragment_shader: [
 
 			"uniform vec3 uDirLightPos;",
+			
+			"uniform vec3 uAmbientLightColor;",
 			"uniform vec3 uDirLightColor;",
-
-			"uniform vec3 uPointLightPos;",
 			"uniform vec3 uPointLightColor;",
 
 			"uniform vec3 uAmbientColor;",
@@ -125,7 +125,6 @@ var ShaderUtils = {
 			"varying vec3 vNormal;",
 			"varying vec2 vUv;",
 
-			"varying vec3 vLightWeighting;",
 			"varying vec3 vPointLightVector;",
 			"varying vec3 vViewPosition;",
 
@@ -190,11 +189,11 @@ var ShaderUtils = {
 
 				// all lights contribution summation
 
-				"vec4 totalLight = vec4( uAmbientColor, 1.0 );",
-				"totalLight += dirDiffuse + dirSpecular;",
-				"totalLight += pointDiffuse + pointSpecular;",
+				"vec4 totalLight = vec4( uAmbientLightColor * uAmbientColor, 1.0 );",
+				"totalLight += vec4( uDirLightColor, 1.0 ) * ( dirDiffuse + dirSpecular );",
+				"totalLight += vec4( uPointLightColor, 1.0 ) * ( pointDiffuse + pointSpecular );",
 
-				"gl_FragColor = vec4( totalLight.xyz * vLightWeighting * aoTex * diffuseTex, 1.0 );",
+				"gl_FragColor = vec4( totalLight.xyz * aoTex * diffuseTex, 1.0 );",
 
 			"}"
 			].join("\n"),
@@ -203,13 +202,7 @@ var ShaderUtils = {
 
 			"attribute vec4 tangent;",
 
-			"uniform vec3 uDirLightPos;",
-			"uniform vec3 uDirLightColor;",
-
 			"uniform vec3 uPointLightPos;",
-			"uniform vec3 uPointLightColor;",
-
-			"uniform vec3 uAmbientLightColor;",
 
 			"#ifdef VERTEX_TEXTURES",
 
@@ -224,7 +217,6 @@ var ShaderUtils = {
 			"varying vec3 vNormal;",
 			"varying vec2 vUv;",
 
-			"varying vec3 vLightWeighting;",
 			"varying vec3 vPointLightVector;",
 			"varying vec3 vViewPosition;",
 
@@ -245,22 +237,10 @@ var ShaderUtils = {
 
 				"vUv = uv;",
 
-				// ambient light
-
-				"vLightWeighting = uAmbientLightColor;",
-
 				// point light
 
 				"vec4 lPosition = viewMatrix * vec4( uPointLightPos, 1.0 );",
 				"vPointLightVector = normalize( lPosition.xyz - mvPosition.xyz );",
-				"float pointLightWeighting = max( dot( vNormal, vPointLightVector ), 0.0 );",
-				"vLightWeighting += uPointLightColor * pointLightWeighting;",
-
-				// directional light
-
-				"vec4 lDirection = viewMatrix * vec4( uDirLightPos, 0.0 );",
-				"float directionalLightWeighting = max( dot( vNormal, normalize( lDirection.xyz ) ), 0.0 );",
-				"vLightWeighting += uDirLightColor * directionalLightWeighting;",
 
 				// displacement mapping
 

Some files were not shown because too many files changed in this diff