Browse Source

Some cleanup and normalization fixes in shaders.

alteredq 13 years ago
parent
commit
71fafdf25d

File diff suppressed because it is too large
+ 2 - 2
build/Three.js


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


File diff suppressed because it is too large
+ 2 - 2
build/custom/ThreeWebGL.js


+ 1 - 3
examples/js/ShaderTerrain.js

@@ -157,11 +157,9 @@ THREE.ShaderTerrain = {
 					"for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {",
 
 						"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );",
-
 						"vec3 lVector = lPosition.xyz + vViewPosition.xyz;",
 
 						"float lDistance = 1.0;",
-
 						"if ( pointLightDistance[ i ] > 0.0 )",
 							"lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );",
 
@@ -194,7 +192,7 @@ THREE.ShaderTerrain = {
 						"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );",
 
 						"vec3 dirVector = normalize( lDirection.xyz );",
-						"vec3 dirHalfVector = normalize( lDirection.xyz + viewPosition );",
+						"vec3 dirHalfVector = normalize( dirVector + viewPosition );",
 
 						"float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );",
 						"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );",

+ 2 - 4
src/extras/ShaderUtils.js

@@ -275,7 +275,7 @@ THREE.ShaderUtils = {
 
 							// specular
 
-							"vec3 pointHalfVector = normalize( vPointLight[ i ].xyz + viewPosition );",
+							"vec3 pointHalfVector = normalize( pointVector + viewPosition );",
 							"float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );",
 							"float pointSpecularWeight = specularTex.r * max( pow( pointDotNormalHalf, uShininess ), 0.0 );",
 
@@ -316,7 +316,7 @@ THREE.ShaderUtils = {
 
 							// specular
 
-							"vec3 dirHalfVector = normalize( lDirection.xyz + viewPosition );",
+							"vec3 dirHalfVector = normalize( dirVector + viewPosition );",
 							"float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );",
 							"float dirSpecularWeight = specularTex.r * max( pow( dirDotNormalHalf, uShininess ), 0.0 );",
 
@@ -426,11 +426,9 @@ THREE.ShaderUtils = {
 						"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {",
 
 							"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );",
-
 							"vec3 lVector = lPosition.xyz - mvPosition.xyz;",
 
 							"float lDistance = 1.0;",
-
 							"if ( pointLightDistance[ i ] > 0.0 )",
 								"lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );",
 

+ 2 - 2
src/renderers/WebGLRenderer.js

@@ -5239,7 +5239,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 		var i, l, id;
 
-		for( i = 0, l = identifiers.length; i < l; i++ ) {
+		for( i = 0, l = identifiers.length; i < l; i ++ ) {
 
 			id = identifiers[ i ];
 			program.uniforms[ id ] = _gl.getUniformLocation( program, id );
@@ -5252,7 +5252,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 		var i, l, id;
 
-		for( i = 0, l = identifiers.length; i < l; i++ ) {
+		for( i = 0, l = identifiers.length; i < l; i ++ ) {
 
 			id = identifiers[ i ];
 			program.attributes[ id ] = _gl.getAttribLocation( program, id );

+ 6 - 12
src/renderers/WebGLShaders.js

@@ -292,17 +292,18 @@ THREE.ShaderChunk = {
 		"for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {",
 
 			"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );",
+			"vec3 dirVector = normalize( lDirection.xyz );",
 
 			"#ifdef WRAP_AROUND",
 
-				"float directionalLightWeightingFull = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );",
-				"float directionalLightWeightingHalf = max( 0.5 * dot( transformedNormal, normalize( lDirection.xyz ) ) + 0.5, 0.0 );",
+				"float directionalLightWeightingFull = max( dot( transformedNormal, dirVector ), 0.0 );",
+				"float directionalLightWeightingHalf = max( 0.5 * dot( transformedNormal, dirVector ) + 0.5, 0.0 );",
 
 				"vec3 directionalLightWeighting = mix( vec3( directionalLightWeightingFull ), vec3( directionalLightWeightingHalf ), wrapRGB );",
 
 			"#else",
 
-				"float directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );",
+				"float directionalLightWeighting = max( dot( transformedNormal, dirVector ), 0.0 );",
 
 			"#endif",
 
@@ -317,11 +318,9 @@ THREE.ShaderChunk = {
 			"for( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {",
 
 				"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );",
-
 				"vec3 lVector = lPosition.xyz - mvPosition.xyz;",
 
 				"float lDistance = 1.0;",
-
 				"if ( pointLightDistance[ i ] > 0.0 )",
 					"lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );",
 
@@ -340,7 +339,6 @@ THREE.ShaderChunk = {
 
 				"#endif",
 
-
 				"vLightWeighting += pointLightColor[ i ] * pointLightWeighting * lDistance;",
 
 			"}",
@@ -377,16 +375,12 @@ THREE.ShaderChunk = {
 			"for( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {",
 
 				"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );",
-
 				"vec3 lVector = lPosition.xyz - mvPosition.xyz;",
 
 				"float lDistance = 1.0;",
-
 				"if ( pointLightDistance[ i ] > 0.0 )",
 					"lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );",
 
-				"lVector = normalize( lVector );",
-
 				"vPointLight[ i ] = vec4( lVector, lDistance );",
 
 			"}",
@@ -451,8 +445,8 @@ THREE.ShaderChunk = {
 
 					"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );",
 					"vec3 lVector = lPosition.xyz + vViewPosition.xyz;",
-					"float lDistance = 1.0;",
 
+					"float lDistance = 1.0;",
 					"if ( pointLightDistance[ i ] > 0.0 )",
 						"lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );",
 
@@ -532,7 +526,7 @@ THREE.ShaderChunk = {
 
 				// specular
 
-				"vec3 dirHalfVector = normalize( lDirection.xyz + viewPosition );",
+				"vec3 dirHalfVector = normalize( dirVector + viewPosition );",
 				"float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );",
 				"float dirSpecularWeight = max( pow( dirDotNormalHalf, shininess ), 0.0 );",
 

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