Browse Source

structs barely work.

Ben Houston 9 years ago
parent
commit
bbace72b72

+ 36 - 30
src/renderers/WebGLRenderer.js

@@ -2110,66 +2110,74 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 				case 's':
 
+					//console.log( "uniform s", uniform, location );
 					// TODO: Optimize this.
-					for( var j = 0; j < uniform.properties.length; j ++ ) {
-					
-						var property = uniform.properties[j];
-						var uniformProperty =  location[ property ];
-						var valueProperty = values[ property ];
+					for( var propertyName in uniform.properties ) {
+						var property = uniform.properties[ propertyName ];
+						var locationProperty =  location[ propertyName ];
+						var valueProperty = value[ propertyName ];
+						//console.log( "uniformProperty", property, valueProperty );
+
 						switch( property.type ) {
 							case 'f':
-								_gl.uniform1f( uniformProperty, valueProperty );
+								_gl.uniform1f( locationProperty, valueProperty );
 								break;
 							case 'v2':
-								_gl.uniform1f( uniformProperty, valueProperty.x, valueProperty.y );
+								_gl.uniform2f( locationProperty, valueProperty.x, valueProperty.y );
 								break;
 							case 'v3':
-								_gl.uniform1f( uniformProperty, valueProperty.x, valueProperty.y, valueProperty.z );
+								_gl.uniform3f( locationProperty, valueProperty.x, valueProperty.y, valueProperty.z );
 								break;
 							case 'v4':
-								_gl.uniform1f( uniformProperty, valueProperty.x, valueProperty.y, valueProperty.z, valueProperty.w );
+								_gl.uniform4f( locationProperty, valueProperty.x, valueProperty.y, valueProperty.z, valueProperty.w );
 								break;
 							case 'c':
-								_gl.uniform1f( uniformProperty, valueProperty.r, valueProperty.g, valueProperty.b );
+								_gl.uniform3f( locationProperty, valueProperty.r, valueProperty.g, valueProperty.b );
 								break;
 						};
 
 					}
+					debugger;
 
 					break;
 
 				case 'sa':
 
+					//console.log( "uniform sa", uniform, location );
 					// TODO: Optimize this.
 					for( var i = 0; i < value.length; i ++ ) {
 
-						for( var j = 0; j < uniform.properties.length; j ++ ) {
-						
-							var property = uniform.properties[j];
-							var uniformProperty =  location[ i ][ property ];
-							var valueProperty = value[i][ property ];
+						//console.log( "uniformIndex", i );
+						for( var propertyName in uniform.properties ) {
+							
+							var property = uniform.properties[ propertyName ];
+							var locationProperty =  location[ i ][ propertyName ];
+							var valueProperty = value[i][ propertyName ];
+							//console.log( "uniformProperty", property, valueProperty, i );
+
 							switch( property.type ) {
 								case 'f':
-									_gl.uniform1f( uniformProperty, valueProperty );
+									_gl.uniform1f( locationProperty, valueProperty );
 									break;
 								case 'v2':
-									_gl.uniform1f( uniformProperty, valueProperty.x, valueProperty.y );
+									_gl.uniform2f( locationProperty, valueProperty.x, valueProperty.y );
 									break;
 								case 'v3':
-									_gl.uniform1f( uniformProperty, valueProperty.x, valueProperty.y, valueProperty.z );
+									_gl.uniform3f( locationProperty, valueProperty.x, valueProperty.y, valueProperty.z );
 									break;
 								case 'v4':
-									_gl.uniform1f( uniformProperty, valueProperty.x, valueProperty.y, valueProperty.z, valueProperty.w );
+									_gl.uniform4f( locationProperty, valueProperty.x, valueProperty.y, valueProperty.z, valueProperty.w );
 									break;
 								case 'c':
-									_gl.uniform1f( uniformProperty, valueProperty.r, valueProperty.g, valueProperty.b );
+									_gl.uniform3f( locationProperty, valueProperty.r, valueProperty.g, valueProperty.b );
 									break;
 							};
 
 						}
 
 					}
-
+					debugger;
+					
 					break;
 
 				case 'iv1':
@@ -2401,7 +2409,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 		zlights = _lights,
 
-		viewMatrix = camera.matrixWorldInverse,
+		viewMatrix = camera.matrixWorldInverse;
 
 		zlights.directional = [];
 		zlights.point = [];
@@ -2430,9 +2438,8 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 				if( ! light.__webglUniforms ) {
 					light.__webglUniforms = {
-						position: new THREE.Vector3(),
-						color: new THREE.Color(),
-						distance: 0
+						direction: new THREE.Vector3(),
+						color: new THREE.Color()
 					}
 				}
 
@@ -2449,8 +2456,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 				lightUniforms.direction.sub( _vector3 );
 				lightUniforms.direction.transformDirection( viewMatrix );
 
-				lightUniforms.color.copy( color ).multiplyScalar( intensity );
-				lightUniforms.distance = distance;
+				lightUniforms.color.copy( light.color ).multiplyScalar( light.intensity );
 
 			} else if ( light instanceof THREE.PointLight ) {
 
@@ -2474,8 +2480,8 @@ THREE.WebGLRenderer = function ( parameters ) {
 				lightUniforms.position.setFromMatrixPosition( light.matrixWorld );
 				lightUniforms.position.applyMatrix4( viewMatrix );
 
-				lightUniforms.color.copy( color ).multiplyScalar( intensity );
-				lightUniforms.distance = distance;
+				lightUniforms.color.copy( light.color ).multiplyScalar( light.intensity );
+				lightUniforms.distance = light.distance;
 				lightUniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
 
 			} else if ( light instanceof THREE.SpotLight ) {
@@ -2536,7 +2542,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 				lightUniforms.position.transformDirection( viewMatrix );
 
 				lightUniforms.skyColor.copy(  light.color ).multiplyScalar( intensity );
-				lightUniforms.groundColor.copy( groundColor ).multiplyScalar( intensity );
+				lightUniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
 
 			}
 

+ 2 - 4
src/renderers/shaders/ShaderChunk/common.glsl

@@ -102,7 +102,7 @@ vec3 F_Schlick( in vec3 specularColor, in float dotLH ) {
 
 float G_BlinnPhong_Implicit( /* in float dotNL, in float dotNV */ ) {
 
-	// geometry term is (n⋅l)(n⋅v) / 4(n⋅l)(n⋅v)
+	// geometry term is (n dot l)(n dot v) / 4(n dot l)(n dot v)
 
 	return 0.25;
 
@@ -124,6 +124,4 @@ vec3 BRDF_BlinnPhong( in vec3 specularColor, in float shininess, in float dotNH,
 
 	return F * G * D;
 
-}
-
-
+}

+ 4 - 4
src/renderers/shaders/UniformsLib.js

@@ -80,20 +80,20 @@ THREE.UniformsLib = {
 		"directionalLights" : { type: "sa", value: [], properties: {
 			"direction": { type: "v3" },
 			"color": { type: "c" }
-		} };
+		} },
 
 		"hemisphereLights" : { type: "sa", value: [], properties: {
 			"direction": { type: "v3" },
 			"skyColor": { type: "v3" },
 			"groundColor": { type: "v3" }
-		} };
+		} },
 
 		"pointLights" : { type: "sa", value: [], properties: {
 			"color": { type: "c" },
 			"position": { type: "v3" },
 			"direction": { type: "v3" },
 			"distance": { type: "f" }
-		} };
+		} },
 
 		"spotLights" : { type: "sa", value: [], properties: {
 			"color": { type: "c" },
@@ -103,7 +103,7 @@ THREE.UniformsLib = {
 			"angleCos": { type: "f" },
 			"exponent": { type: "f" },
 			"decay": { type: "f" }
-		} };
+		} }
 
 
 	},

+ 1 - 2
src/renderers/webgl/WebGLProgram.js

@@ -38,7 +38,7 @@ THREE.WebGLProgram = ( function () {
 			var name = info.name;
 			var location = gl.getUniformLocation( program, name );
 
-			console.log("THREE.WebGLProgram: ACTIVE UNIFORM:", name);
+			//console.log("THREE.WebGLProgram: ACTIVE UNIFORM:", name);
 
 			var matches = structRe.exec(name);
 			if( matches ) {
@@ -89,7 +89,6 @@ THREE.WebGLProgram = ( function () {
 
 		}
 
-		console.log("uniforms", uniforms);
 		return uniforms;
 
 	}