Browse Source

Removed vertex lighting from normal mapping shader.

Normal-mapped ninja now looks slightly different from Phong ninja, but Lee looks less artificial ;)
alteredq 14 years ago
parent
commit
46041d3650
3 changed files with 22 additions and 39 deletions
  1. 0 0
      build/ThreeExtras.js
  2. 16 13
      examples/materials_normalmap2.html
  3. 6 26
      src/extras/ShaderUtils.js

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


+ 16 - 13
examples/materials_normalmap2.html

@@ -117,24 +117,24 @@
 				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( 0x222233 );
+				ambientLight = new THREE.AmbientLight( 0x050505 );
 				scene.addLight( ambientLight );
 
-				pointLight = new THREE.PointLight( 0x888877 );
+				pointLight = new THREE.PointLight( 0x999999 );
 				pointLight.position.z = 10000;
 				scene.addLight( pointLight );
 
-				directionalLight = new THREE.DirectionalLight( 0x999955 );
-				directionalLight.position.x = 1;
-				directionalLight.position.y = 1;
-				directionalLight.position.z = 0.5;
+				directionalLight = new THREE.DirectionalLight( 0xbbbbbb );
+				directionalLight.position.x = 0;
+				directionalLight.position.y = 0;
+				directionalLight.position.z = 1;
 				directionalLight.position.normalize();
 				scene.addLight( directionalLight );
 
@@ -148,12 +148,12 @@
 
 				// material parameters
 				
-				var ambient = 0x020202, diffuse = 0x666666, specular = 0x666666, shininess = 4;
+				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[ "tDiffuse" ].texture = ImageUtils.loadTexture( "obj/leeperrysmith/Map-COL.jpg" );
 				
@@ -174,12 +174,15 @@
 				
 				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.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 );
@@ -230,8 +233,8 @@
 
 				}
 
-				lightMesh.position.x = 2500 * Math.cos( r );
-				lightMesh.position.z = 2500 * Math.sin( r );
+				lightMesh.position.x = 500 * Math.cos( r );
+				lightMesh.position.z = 500 * Math.sin( r );
 
 				r += 0.01;
 

+ 6 - 26
src/extras/ShaderUtils.js

@@ -99,9 +99,9 @@ var ShaderUtils = {
 			fragment_shader: [
 
 			"uniform vec3 uDirLightPos;",
+			
+			"uniform vec3 uAmbientLightColor;",
 			"uniform vec3 uDirLightColor;",
-
-			"uniform vec3 uPointLightPos;",
 			"uniform vec3 uPointLightColor;",
 
 			"uniform vec3 uAmbientColor;",
@@ -121,7 +121,6 @@ var ShaderUtils = {
 			"varying vec3 vNormal;",
 			"varying vec2 vUv;",
 
-			"varying vec3 vLightWeighting;",
 			"varying vec3 vPointLightVector;",
 			"varying vec3 vViewPosition;",
 
@@ -184,11 +183,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"),
@@ -197,13 +196,7 @@ var ShaderUtils = {
 
 			"attribute vec4 tangent;",
 
-			"uniform vec3 uDirLightPos;",
-			"uniform vec3 uDirLightColor;",
-
 			"uniform vec3 uPointLightPos;",
-			"uniform vec3 uPointLightColor;",
-
-			"uniform vec3 uAmbientLightColor;",
 
 			"#ifdef VERTEX_TEXTURES",
 
@@ -218,7 +211,6 @@ var ShaderUtils = {
 			"varying vec3 vNormal;",
 			"varying vec2 vUv;",
 
-			"varying vec3 vLightWeighting;",
 			"varying vec3 vPointLightVector;",
 			"varying vec3 vViewPosition;",
 
@@ -239,22 +231,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