Browse Source

ways to define ThreeJS "uniforms" for structs and struct arrays. ways to set those values. still missing some glue code.

Ben Houston 9 years ago
parent
commit
c1df1730d3
2 changed files with 95 additions and 19 deletions
  1. 76 0
      src/renderers/WebGLRenderer.js
  2. 19 19
      src/renderers/shaders/UniformsLib.js

+ 76 - 0
src/renderers/WebGLRenderer.js

@@ -2140,6 +2140,82 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 					break;
 
+				case 'fs':
+
+					_gl.uniform1f( location[ uniform.property ], value );
+
+					break;
+
+				case 'v2s':
+	
+					_gl.uniform2f( location[ uniform.property ], value.x, value.y );
+
+					break;
+
+				case 'v3s':
+
+					_gl.uniform3f( location[ uniform.property ], value.x, value.y, value.z );
+
+					break;
+
+				case 'v4s':
+
+					_gl.uniform4f( location[ uniform.property ], value.x, value.y, value.z, value.w );
+
+					break;
+
+				case 'cs':
+
+					_gl.uniform3f( location[ uniform.property ], value.r, value.g, value.b );
+
+					break;
+
+				case 'fsa':
+
+					for( var i = 0; i < value.length; i ++ ) {
+
+						_gl.uniform1f( location[ i ][ uniform.property ], value );
+
+					}
+
+					break;
+
+				case 'v2sa':
+
+					for( var i = 0; i < value.length; i ++ ) {
+	
+						_gl.uniform2f( location[ i ][ uniform.property ], value.x, value.y );
+
+					}
+					break;
+
+				case 'v3sa':
+
+					for( var i = 0; i < value.length; i ++ ) {
+
+						_gl.uniform3f( location[ i ][ uniform.property ], value.x, value.y, value.z );
+
+					}
+					break;
+
+				case 'v4sa':
+
+					for( var i = 0; i < value.length; i ++ ) {
+	
+						_gl.uniform4f( location[ i ][ uniform.property ], value.x, value.y, value.z, value.w );
+
+					}
+					break;
+
+				case 'csa':
+
+					for( var i = 0; i < value.length; i ++ ) {
+	
+						_gl.uniform3f( location[ i ][ uniform.property ], value.r, value.g, value.b );
+
+					}
+					break;
+
 				case 'iv1':
 
 					// flat array of integers (JS or typed array)

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

@@ -77,25 +77,25 @@ THREE.UniformsLib = {
 
 		"ambientLightColor" : { type: "fv", value: [] },
 
-		"directionalLightDirection" : { type: "fv", value: [] },
-		"directionalLightColor" : { type: "fv", value: [] },
-
-		"hemisphereLightDirection" : { type: "fv", value: [], array: 'hemisphereLights', property: 'direction' },
-		"hemisphereLightSkyColor" : { type: "fv", value: [], array: 'hemisphereLights', property: 'skyColor' },
-		"hemisphereLightGroundColor" : { type: "fv", value: [], array: 'hemisphereLights', property: 'groundColor' },
-
-		"pointLightColor" : { type: "fv", value: [], array: 'pointLights', property: 'color' },
-		"pointLightPosition" : { type: "fv", value: [], array: 'pointLights', property: 'position' },
-		"pointLightDistance" : { type: "fv1", value: [], array: 'pointLights', property: 'distance' },
-		"pointLightDecay" : { type: "fv1", value: [], array: 'pointLights', property: 'decay' },
-
-		"spotLightColor" : { type: "fv", value: [], array: 'spotLights', property: 'color' },
-		"spotLightPosition" : { type: "fv", value: [], array: 'spotLights', property: 'position' },
-		"spotLightDirection" : { type: "fv", value: [], array: 'spotLights', property: 'direction' },
-		"spotLightDistance" : { type: "fv1", value: [], array: 'spotLights', property: 'distance' },
-		"spotLightAngleCos" : { type: "fv1", value: [], array: 'spotLights', property: 'angleCos' },
-		"spotLightExponent" : { type: "fv1", value: [], array: 'spotLights', property: 'exponent' },
-		"spotLightDecay" : { type: "fv1", value: [], array: 'spotLights', property: 'decay' }
+		"directionalLightDirection" : { type: "v3sa", value: [], name: 'hemisphereLights', property: 'direction' },
+		"directionalLightColor" : { type: "csa", value: [], name: 'hemisphereLights', property: 'direction' },
+
+		"hemisphereLightDirection" : { type: "v3sa", value: [], name: 'hemisphereLights', property: 'direction' },
+		"hemisphereLightSkyColor" : { type: "csa", value: [], name: 'hemisphereLights', property: 'skyColor' },
+		"hemisphereLightGroundColor" : { type: "csa", value: [], name: 'hemisphereLights', property: 'groundColor' },
+
+		"pointLightColor" : { type: "csa", value: [], name: 'pointLights', property: 'color' },
+		"pointLightPosition" : { type: "v3sa", value: [], name: 'pointLights', property: 'position' },
+		"pointLightDistance" : { type: "fsa", value: [], name: 'pointLights', property: 'distance' },
+		"pointLightDecay" : { type: "fsa", value: [], name: 'pointLights', property: 'decay' },
+
+		"spotLightColor" : { type: "csa", value: [], name: 'spotLights', property: 'color' },
+		"spotLightPosition" : { type: "v3sa", value: [], name: 'spotLights', property: 'position' },
+		"spotLightDirection" : { type: "v3sa", value: [], name: 'spotLights', property: 'direction' },
+		"spotLightDistance" : { type: "fsa", value: [], name: 'spotLights', property: 'distance' },
+		"spotLightAngleCos" : { type: "fsa", value: [], name: 'spotLights', property: 'angleCos' },
+		"spotLightExponent" : { type: "fsa", value: [], name: 'spotLights', property: 'exponent' },
+		"spotLightDecay" : { type: "fsa", value: [], name: 'spotLights', property: 'decay' }
 
 	},