Browse Source

Started implementing lighting system in new renderer

Ivan Safrin 10 năm trước cách đây
mục cha
commit
b3a9c610f1

BIN
assets/default/default.pak


+ 129 - 0
assets/default/default/DefaultShader.frag

@@ -0,0 +1,129 @@
+varying vec2 texCoordVar;
+varying vec3 varNormal;
+varying vec4 varPosition;
+
+uniform sampler2D diffuse;
+uniform vec4 diffuse_color;
+uniform vec4 specular_color;
+uniform vec4 ambient_color;
+uniform vec4 entityColor;
+uniform float shininess;
+
+#define MAX_LIGHTS 8
+
+struct LightInfo {
+	vec3 position;
+	vec3 direction;
+	vec4 specular;
+	vec4 diffuse;
+
+	float spotExponent;
+	float spotCosCutoff;
+
+	float constantAttenuation;
+	float linearAttenuation;	
+	float quadraticAttenuation;
+};
+
+uniform LightInfo lights[MAX_LIGHTS];
+
+float calculateAttenuation(in int i, in float dist)
+{
+    return(1.0 / (lights[i].constantAttenuation +
+                  lights[i].linearAttenuation * dist +
+                  lights[i].quadraticAttenuation * dist * dist));
+}
+
+void pointLight(in int i, in vec3 normal, in vec4 pos, inout vec4 diffuse, inout vec4 specular) {
+	vec4 color = diffuse_color;
+	vec4 matspec = specular_color;
+	float shininess = shininess;
+	vec4 lightspec = lights[i].specular;
+	vec4 lpos = vec4(lights[i].position, 1.0);
+	vec4 s = pos-lpos; 
+	vec4 sn = -normalize(s);
+	
+	vec3 light = sn.xyz;
+	vec3 n = normalize(normal);
+	vec3 r = -reflect(light, n);
+	r = normalize(r);
+	vec3 v = -pos.xyz;
+	v = normalize(v);
+
+	float nDotL = dot(n, sn.xyz);
+	if(nDotL > 0.0) {
+		float dist = length(s);    
+		float attenuation = calculateAttenuation(i, dist);
+
+		diffuse  += color * max(0.0, nDotL) * lights[i].diffuse * attenuation;
+
+	  if (shininess != 0.0) {
+    	specular += lightspec * matspec * pow(max(0.0,dot(r, v)), shininess) * attenuation;
+	  }
+	}
+}
+
+
+void spotLight(in int i, in vec3 normal, in vec4 pos, inout vec4 diffuse, inout vec4 specular) {
+	vec4 color = diffuse_color;
+	vec4 matspec = specular_color;
+	float shininess = shininess;
+	vec4 lightspec = lights[i].specular;
+	vec4 lpos = vec4(lights[i].position, 1.0);
+	vec4 s = pos-lpos; 
+	vec4 sn = -normalize(s);
+
+	vec3 light = sn.xyz;
+	vec3 n = normalize(normal);
+	vec3 r = -reflect(light, n);
+	r = normalize(r);
+	vec3 v = -pos.xyz;
+	v = normalize(v);
+
+	float cos_outer_cone_angle = (1.0-lights[i].spotExponent) * lights[i].spotCosCutoff;
+	float cos_cur_angle = dot(-normalize(lights[i].direction), sn.xyz);
+	float cos_inner_cone_angle = lights[i].spotCosCutoff;
+
+	float cos_inner_minus_outer_angle = cos_inner_cone_angle - cos_outer_cone_angle;
+	float spot = 0.0;
+	spot = clamp((cos_cur_angle - cos_outer_cone_angle) / cos_inner_minus_outer_angle, 0.0, 1.0);
+	       
+	float nDotL = dot(n, sn.xyz);
+	if(nDotL > 0.0) {
+		float dist = length(s);    
+		float attenuation = calculateAttenuation(i, dist);
+		diffuse  += color * max(0.0, nDotL) * lights[i].diffuse * attenuation * spot;
+
+	  if (shininess != 0.0) {
+    	specular += lightspec * matspec * pow(max(0.0,dot(r, v)), shininess) * attenuation * spot;
+	  }
+	}
+}
+
+void doLights(in int numLights, in vec3 normal, in vec4 pos, inout vec4 diffuse, inout vec4 specular) {
+	for (int i = 0; i < numLights; i++) {
+//		if (lights[i].spotCosCutoff == 180.0) {
+			pointLight(i, normal, pos, diffuse, specular);
+//		} else {
+//			spotLight(i, normal, pos, diffuse, specular);
+//		}
+    }
+}
+
+
+void main()
+{
+	vec4 diffuse_val  = vec4(0.0);
+	vec4 specular_val = vec4(0.0);
+
+	doLights(MAX_LIGHTS, varNormal, varPosition, diffuse_val, specular_val);
+		
+	vec4 texColor = texture2D(diffuse, texCoordVar);		
+		
+    vec4 color = diffuse_val + ambient_color; 	           
+    color = clamp((color*entityColor*texColor) + specular_val, 0.0, 1.0);  
+
+	color.a = entityColor.a * texColor.a * diffuse_color.a;	
+	gl_FragColor = color;
+
+}

+ 37 - 0
assets/default/default/DefaultShader.vert

@@ -0,0 +1,37 @@
+#ifdef GLES2
+	precision mediump float;
+#endif
+
+attribute vec4 position;
+attribute vec3 normal;
+attribute vec2 texCoord;
+
+uniform mat4 modelMatrix;
+uniform mat4 viewMatrix;
+uniform mat4 projectionMatrix;
+
+varying vec2 texCoordVar;
+varying vec3 varNormal;
+varying vec4 varPosition;
+
+mat3 mat3_emu(mat4 m4) {
+  return mat3(
+      m4[0][0], m4[0][1], m4[0][2],
+      m4[1][0], m4[1][1], m4[1][2],
+      m4[2][0], m4[2][1], m4[2][2]);
+}
+
+void main()
+{
+	mat4 modelViewMatrix = viewMatrix * modelMatrix;
+	vec4 p = modelViewMatrix  * position;
+
+	mat3 rotN = mat3_emu(modelMatrix);
+	varNormal = normalize(rotN * normal);
+
+
+	varPosition = modelMatrix  * position;
+	gl_Position = projectionMatrix * p;
+
+	texCoordVar = texCoord;
+}

+ 9 - 1
assets/default/default/default.mat

@@ -1,6 +1,10 @@
 <?xml version="1.0" ?>
 <polycode>	
-	<shaders>														
+	<shaders>		
+		<shader type="glsl" name="DefaultShader" numPointLights="6" numSpotLights="2">
+			<vp source="default/DefaultShader.vert"/>
+			<fp source="default/DefaultShader.frag"/>
+		</shader>
 		<shader type="glsl" name="Unlit" numPointLights="0" numSpotLights="0">		
 			<vp source="default/Unlit.vert"/>
 			<fp source="default/Unlit.frag"/>
@@ -19,6 +23,10 @@
 		</shader>	
 	</shaders>	
 	<materials>	
+		<material name="DefaultTextured">
+			<shader name="DefaultShader">
+			</shader>
+		</material>		
 		<material name="Unlit">
 			<shader name="Unlit">
 			</shader>

+ 1 - 4
build/osx/PolycodeStudio/PolycodeStudio.xcodeproj/project.pbxproj

@@ -62,7 +62,6 @@
 		8A36D3241B8E6FD5009897D0 /* libz.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A36D31A1B8E6FD5009897D0 /* libz.a */; };
 		8A36D3261B8E6FE7009897D0 /* libPolycodeUI.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A36D3251B8E6FE7009897D0 /* libPolycodeUI.a */; };
 		8A36D32A1B8E7096009897D0 /* default.pak in Resources */ = {isa = PBXBuildFile; fileRef = 8A36D3281B8E7096009897D0 /* default.pak */; };
-		8A36D32B1B8E7096009897D0 /* hdr.pak in Resources */ = {isa = PBXBuildFile; fileRef = 8A36D3291B8E7096009897D0 /* hdr.pak */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXFileReference section */
@@ -160,7 +159,6 @@
 		8A36D31A1B8E6FD5009897D0 /* libz.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libz.a; path = /Users/isafrin/Desktop/Workshop/PolycodeNoCmake/build/osx/TemplateApp/TemplateApp/../../../../lib/osx/libz.a; sourceTree = "<absolute>"; };
 		8A36D3251B8E6FE7009897D0 /* libPolycodeUI.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libPolycodeUI.a; path = ../../../../lib/osx/libPolycodeUI.a; sourceTree = "<group>"; };
 		8A36D3281B8E7096009897D0 /* default.pak */ = {isa = PBXFileReference; lastKnownFileType = file; name = default.pak; path = ../../../../assets/default/default.pak; sourceTree = "<group>"; };
-		8A36D3291B8E7096009897D0 /* hdr.pak */ = {isa = PBXFileReference; lastKnownFileType = file; name = hdr.pak; path = ../../../../assets/default/hdr.pak; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -215,7 +213,6 @@
 			isa = PBXGroup;
 			children = (
 				8A36D3281B8E7096009897D0 /* default.pak */,
-				8A36D3291B8E7096009897D0 /* hdr.pak */,
 				8A36D22C1B8E5ACC009897D0 /* PolycodeView.h */,
 				8A36D22D1B8E5ACC009897D0 /* PolycodeView.mm */,
 				8A36D20E1B8E5751009897D0 /* AppDelegate.h */,
@@ -391,7 +388,6 @@
 				8A36D2141B8E5751009897D0 /* Images.xcassets in Resources */,
 				8A36D2171B8E5751009897D0 /* MainMenu.xib in Resources */,
 				8A36D32A1B8E7096009897D0 /* default.pak in Resources */,
-				8A36D32B1B8E7096009897D0 /* hdr.pak in Resources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -614,6 +610,7 @@
 				8A36D2281B8E5751009897D0 /* Release */,
 			);
 			defaultConfigurationIsVisible = 0;
+			defaultConfigurationName = Release;
 		};
 /* End XCConfigurationList section */
 	};

+ 22 - 0
include/polycode/core/PolyGPUDrawBuffer.h

@@ -27,9 +27,29 @@
 #include "polycode/core/PolyRectangle.h"
 #include "polycode/core/PolyMaterial.h"
 #include "polycode/core/PolyColor.h"
+#include "polycode/core/PolyVector3.h"
 
 namespace Polycode {
     
+    class _PolyExport LightInfo {
+        public:
+            unsigned short importance;
+            Vector3 position;
+            Vector3 direction;
+            unsigned short type;
+            Color diffuseColor;
+            Color specularColor;
+            Number constantAttenuation;
+            Number linearAttenuation;
+            Number quadraticAttenuation;
+            Number intensity;
+            Number spotlightCutoff;
+            Number spotlightExponent;
+            bool shadowsEnabled;
+            Texture *shadowMapTexture;
+            Matrix4 lightViewMatrix;
+    };
+    
     class _PolyExport GPUDrawOptions {
     public:
         bool depthTest;
@@ -74,6 +94,8 @@ namespace Polycode {
         Vector2 backingResolutionScale;
         Material *globalMaterial;
         
+        std::vector<LightInfo> lights;
+        
         Polycode::Rectangle viewport;
         std::vector<GPUDrawCall> drawCalls;
     };

+ 18 - 0
include/polycode/core/PolyRenderer.h

@@ -35,6 +35,8 @@ THE SOFTWARE.
 #include <stack>
 #include <queue>  
 
+#define RENDERER_MAX_LIGHTS 8
+
 namespace Polycode {
     
     class _PolyExport GraphicsInterface : public PolyBase {
@@ -86,6 +88,19 @@ namespace Polycode {
             unsigned int timeTaken;
     };
     
+    class LightInfoBinding {
+        public:
+            LocalShaderParam *position;
+            LocalShaderParam *direction;
+            LocalShaderParam *specular;
+            LocalShaderParam *diffuse;
+            LocalShaderParam *spotExponent;
+            LocalShaderParam *spotCosCutoff;
+            LocalShaderParam *constantAttenuation;
+            LocalShaderParam *linearAttenuation;
+            LocalShaderParam *quadraticAttenuation;
+    };
+    
     class _PolyExport RenderThread : public Threaded {
         public:
             RenderThread();
@@ -124,6 +139,9 @@ namespace Polycode {
             LocalShaderParam *projectionMatrixParam;
             LocalShaderParam *viewMatrixParam;
             LocalShaderParam *modelMatrixParam;
+        
+            LightInfoBinding lights[RENDERER_MAX_LIGHTS];
+        
     };
     
     class _PolyExport Renderer : public PolyBase {

+ 26 - 47
include/polycode/core/PolySceneLight.h

@@ -71,9 +71,9 @@ namespace Polycode {
 			*/
 			void setAttenuation(Number constantAttenuation, Number linearAttenuation, Number quadraticAttenuation);			
 						
-			Number getConstantAttenuation() const { return constantAttenuation; }
-			Number getLinearAttenuation() const { return linearAttenuation; }
-			Number getQuadraticAttenuation() const { return quadraticAttenuation; }
+            Number getConstantAttenuation() const;
+            Number getLinearAttenuation() const;
+            Number getQuadraticAttenuation() const;
 									
 			/*
 			* Returns the light's type.
@@ -81,9 +81,7 @@ namespace Polycode {
 			int getType() const;
 			
 			void renderDepthMap(Scene *scene);
-			
-			void Render();
-
+		
 			const Matrix4& getLightViewMatrix() const;
 			
 			static const int POINT_LIGHT = 0;
@@ -91,11 +89,6 @@ namespace Polycode {
 			
 			Texture *getZBufferTexture() const;
 			
-			/**
-			* Color of the light.
-			*/ 
-			Color specularLightColor;
-		
 			/**
 			* Sets the light color.
 			* @param r Red value 0-1.
@@ -103,13 +96,8 @@ namespace Polycode {
 			* @param b Blue value 0-1
 			* @param a Alpha value 0-1									
 			*/	
-			void setSpecularLightColor(Number r, Number g, Number b, Number a) { specularLightColor.r = r; specularLightColor.g = g; specularLightColor.b = b; specularLightColor.a = a; }
+			void setSpecularLightColor(Number r, Number g, Number b, Number a) { lightInfo.specularColor.r = r; lightInfo.specularColor.g = g; lightInfo.specularColor.b = b; lightInfo.specularColor.a = a; }
 						
-			
-			/**
-			* Color of the light.
-			*/ 
-			Color lightColor;
 		
 			/**
 			* Sets the light color.
@@ -118,10 +106,18 @@ namespace Polycode {
 			* @param b Blue value 0-1
 			* @param a Alpha value 0-1									
 			*/	
-			void setDiffuseLightColor(Number r, Number g, Number b) { lightColor.r = r; lightColor.g = g; lightColor.b = b; }
-			
-			
+			void setDiffuseLightColor(Number r, Number g, Number b, Number a=1.0) { lightInfo.diffuseColor.r = r; lightInfo.diffuseColor.g = g; lightInfo.diffuseColor.b = b; lightInfo.diffuseColor.a = a; }
 			
+        
+        	void setDiffuseLightColor(const Color &color) {
+                lightInfo.diffuseColor = color;
+            }
+
+            void setSpecularLightColor(const Color &color) {
+                lightInfo.specularColor = color;
+            }
+        
+        
 			/**
 			* Sets both the specular and diffust light colors. Use setDiffuseLightColor and setSpecularLightColor to set the individual light colors.
 			* @param r Red value 0-1.
@@ -142,13 +138,10 @@ namespace Polycode {
 			* @param spotlightExponent Spotlight exponent size
 			* @param spotlightCutoff Spotlight furstrum cutoff.
 			*/
-			void setSpotlightProperties(Number spotlightCutoff, Number spotlightExponent) {
-				this->spotlightCutoff = spotlightCutoff;
-                this->spotlightExponent = spotlightExponent;
-			}
+            void setSpotlightProperties(Number spotlightCutoff, Number spotlightExponent);
 			
-			Number getSpotlightCutoff() const { return spotlightCutoff; }
-			Number getSpotlightExponent() const { return spotlightExponent; }
+            Number getSpotlightCutoff() const;
+            Number getSpotlightExponent() const;
 			
 			/**
 			* If this is called with 'true', the light will generate a shadow map.
@@ -178,7 +171,7 @@ namespace Polycode {
 			/**
 			* Returns the light type.
 			*/
-			int getLightType() const { return type; }
+            int getLightType() const;
 			
 			void setLightImportance(int newImportance);
 			int getLightImportance() const;
@@ -193,31 +186,17 @@ namespace Polycode {
         
             Camera *getSpotlightCamera();
         
+            LightInfo getLightInfo() const;
+        
 		protected:
-		
-			Number spotlightExponent;
-			Number spotlightCutoff;
-		
-			int lightImportance;
-		
-			Number constantAttenuation;
-			Number linearAttenuation;
-			Number quadraticAttenuation;
-		
-			int type;
-			Number intensity;
-			
-			Camera *spotCamera;
-			Texture *zBufferTexture;
+        
+            LightInfo lightInfo;
 
+			Camera *spotCamera;
 			Scene *parentScene;
-			
-			Matrix4 lightViewMatrix;
 		
 			unsigned int shadowMapRes;
-			Number shadowMapFOV;	
-			bool shadowsEnabled;
-		
+			Number shadowMapFOV;
 			Number distance;
 	};
 }

+ 2 - 0
include/polycode/core/PolyShader.h

@@ -36,6 +36,7 @@ namespace Polycode {
 	class ShaderBinding;
 	class Texture;
     class VertexDataArray;
+    class LocalShaderParam;
 	
 	class _PolyExport ProgramParam {
 		public:
@@ -45,6 +46,7 @@ namespace Polycode {
         String name;
         int type;
         void *platformData;
+        LocalShaderParam *globalParam;
 
         static void *createParamData(int type);
         

+ 1 - 3
include/polycode/ide/EntityEditorPropertyView.h

@@ -60,9 +60,7 @@ class EntityEditorPropertyView : public UIElement {
         SceneCurveSheet *curveSheet;
         CameraSheet *cameraSheet;
         EntityPropSheet *propSheet;
-        SceneMeshSheet *sceneMeshSheet;
-    
-        ShaderTexturesSheet *shaderTexturesSheet;
+        SceneMeshSheet *sceneMeshSheet;    
         ShaderOptionsSheet *shaderOptionsSheet;
 };
 

+ 0 - 2
include/polycode/ide/PolycodeMaterialEditor.h

@@ -201,7 +201,6 @@ class PostEditorPane : public UIElement {
 		PropList *optionsPropList;
 		
 		TargetBindingsSheet *targetBindingProps;
-		ShaderTexturesSheet *shaderTextureSheet;
 		ShaderOptionsSheet *shaderOptionsSheet;			
 			
 		UIVSizer *mainSizer;
@@ -280,7 +279,6 @@ class MaterialEditorPane : public UIElement {
 		ComboProp *blendModeProp;
 		ComboProp *shaderProp;
 		
-		ShaderTexturesSheet *shaderTextureSheet;
 		ShaderOptionsSheet *shaderOptionsSheet;	
 };
 

+ 0 - 20
include/polycode/ide/PolycodeProps.h

@@ -526,26 +526,6 @@ class ShaderOptionsSheet : public PropSheet {
 		
 };
 
-class ShaderTexturesSheet : public PropSheet {
-	public:
-		ShaderTexturesSheet();
-		~ShaderTexturesSheet();
-		
-		void handleEvent(Event *event);
-		void Update();
-		
-		void clearShader();
-		void setShader(Shader *shader, Material *material, ShaderBinding *binding);
-				
-	private:
-		Shader *shader;
-		Material *material;
-		ShaderBinding *binding;
-						
-		std::vector<TextureProp*> textureProps;
-		std::vector<ComboProp*> cubemapProps;		
-};
-
 class EntitySheet : public PropSheet {
 	public:
 		EntitySheet();

+ 69 - 7
src/core/PolyOpenGLGraphicsInterface.cpp

@@ -55,31 +55,93 @@ void OpenGLGraphicsInterface::setParamInShader(Shader *shader, ProgramParam *par
     switch(param->type) {
         case ProgramParam::PARAM_NUMBER:
             if(localParam) {
-                glUniform1f(paramLocation, localParam->getNumber());
+                
+                if(localParam->arraySize > 0) {
+                    
+                    GLfloat *data = (GLfloat*) malloc(sizeof(GLfloat) * localParam->arraySize);
+                    for(int i=0; i < localParam->arraySize; i++ ){
+                        Number *dataPtr = (Number*)localParam->data;
+                        data[i] = dataPtr[i];
+                    }
+                    glUniform1fv(paramLocation, localParam->arraySize, data);
+                    free(data);
+                    
+                } else {
+                    glUniform1f(paramLocation, localParam->getNumber());
+                }
+                
             } else {
                 glUniform1f(paramLocation, 0.0f);
             }
             break;
         case ProgramParam::PARAM_VECTOR2:
             if(localParam) {
-                Vector2 vec2 = localParam->getVector2();
-                glUniform2f(paramLocation, vec2.x, vec2.y);
+                
+                if(localParam->arraySize > 0) {
+                    
+                    GLfloat *data = (GLfloat*) malloc(sizeof(GLfloat) * localParam->arraySize * 2);
+                    for(int i=0; i < localParam->arraySize; i++ ){
+                        Vector2 *dataPtr = (Vector2*)localParam->data;
+                        data[(i*2)] = dataPtr[i].x;
+                        data[(i*2)+1] = dataPtr[i].y;
+                    }
+                    glUniform2fv(paramLocation, localParam->arraySize, data);
+                    free(data);
+                    
+                } else {
+                    Vector2 vec2 = localParam->getVector2();
+                    glUniform2f(paramLocation, vec2.x, vec2.y);
+                }
+                
             } else {
                 glUniform2f(paramLocation, 0.0f, 0.0f);
             }
             break;
         case ProgramParam::PARAM_VECTOR3:
             if(localParam) {
-                Vector3 vec3 = localParam->getVector3();
-                glUniform3f(paramLocation, vec3.x, vec3.y, vec3.z);
+                
+                if(localParam->arraySize > 0) {
+                    
+                    GLfloat *data = (GLfloat*) malloc(sizeof(GLfloat) * localParam->arraySize * 3);
+                    for(int i=0; i < localParam->arraySize; i++ ){
+                        Vector3 *dataPtr = (Vector3*)localParam->data;
+                        data[(i*3)] = dataPtr[i].x;
+                        data[(i*3)+1] = dataPtr[i].y;
+                        data[(i*3)+2] = dataPtr[i].z;
+                    }
+                    glUniform3fv(paramLocation, localParam->arraySize, data);
+                    free(data);
+                    
+                } else {
+                    Vector3 vec3 = localParam->getVector3();
+                    glUniform3f(paramLocation, vec3.x, vec3.y, vec3.z);
+                }
+                
             } else {
                 glUniform3f(paramLocation, 0.0f, 0.0f, 0.0f);
             }
             break;
         case ProgramParam::PARAM_COLOR:
             if(localParam) {
-                Color color = localParam->getColor();
-                glUniform4f(paramLocation, color.r, color.g, color.b, color.a);
+                
+                if(localParam->arraySize > 0) {
+                    
+                    GLfloat *data = (GLfloat*) malloc(sizeof(GLfloat) * localParam->arraySize * 4);
+                    for(int i=0; i < localParam->arraySize; i++ ){
+                        Color *dataPtr = (Color*)localParam->data;
+                        data[(i*3)] = dataPtr[i].r;
+                        data[(i*3)+1] = dataPtr[i].g;
+                        data[(i*3)+2] = dataPtr[i].b;
+                        data[(i*3)+3] = dataPtr[i].a;
+                    }
+                    glUniform4fv(paramLocation, localParam->arraySize, data);
+                    free(data);
+                    
+                } else {
+                    Color color = localParam->getColor();
+                    glUniform4f(paramLocation, color.r, color.g, color.b, color.a);
+                }
+                
             } else {
                 glUniform4f(paramLocation, 1.0f, 1.0f, 1.0f, 1.0f);
             }

+ 51 - 18
src/core/PolyRenderer.cpp

@@ -40,6 +40,19 @@ RenderThread::RenderThread() : graphicsInterface(NULL) {
     modelMatrixParam = rendererShaderBinding->addParam(ProgramParam::PARAM_MATRIX, "modelMatrix");
     viewMatrixParam = rendererShaderBinding->addParam(ProgramParam::PARAM_MATRIX, "viewMatrix");
     
+    for(int i=0; i < RENDERER_MAX_LIGHTS; i++) {
+        lights[i].position = rendererShaderBinding->addParam(ProgramParam::PARAM_VECTOR3, "lights["+String::IntToString(i)+"].position");
+        lights[i].direction = rendererShaderBinding->addParam(ProgramParam::PARAM_VECTOR3, "lights["+String::IntToString(i)+"].direction");
+        lights[i].specular = rendererShaderBinding->addParam(ProgramParam::PARAM_COLOR, "lights["+String::IntToString(i)+"].specular");
+        lights[i].diffuse = rendererShaderBinding->addParam(ProgramParam::PARAM_COLOR, "lights["+String::IntToString(i)+"].diffuse");
+        lights[i].spotExponent = rendererShaderBinding->addParam(ProgramParam::PARAM_NUMBER, "lights["+String::IntToString(i)+"].spotExponent");
+        lights[i].spotCosCutoff = rendererShaderBinding->addParam(ProgramParam::PARAM_NUMBER, "lights["+String::IntToString(i)+"].spotCosCutoff");
+        lights[i].constantAttenuation = rendererShaderBinding->addParam(ProgramParam::PARAM_NUMBER, "lights["+String::IntToString(i)+"].constantAttenuation");
+        lights[i].linearAttenuation = rendererShaderBinding->addParam(ProgramParam::PARAM_NUMBER, "lights["+String::IntToString(i)+"].linearAttenuation");
+        lights[i].quadraticAttenuation = rendererShaderBinding->addParam(ProgramParam::PARAM_NUMBER, "lights["+String::IntToString(i)+"].quadraticAttenuation");
+        
+    }
+    
     jobQueueMutex = Services()->getCore()->createMutex();
 }
 
@@ -74,6 +87,26 @@ void RenderThread::processDrawBuffer(GPUDrawBuffer *buffer) {
     projectionMatrixParam->setMatrix4(buffer->projectionMatrix);
     viewMatrixParam->setMatrix4(buffer->viewMatrix);
 
+    for(int i=0; i <RENDERER_MAX_LIGHTS; i++) {
+        if(i < buffer->lights.size()) {
+            lights[i].diffuse->setColor(buffer->lights[i].diffuseColor * buffer->lights[i].intensity);
+            lights[i].specular->setColor(buffer->lights[i].specularColor  * buffer->lights[i].intensity);
+            
+            lights[i].position->setVector3(buffer->lights[i].position);
+            lights[i].direction->setVector3(buffer->lights[i].direction);
+            lights[i].spotExponent->setNumber(buffer->lights[i].spotlightExponent);
+            lights[i].spotCosCutoff->setNumber(buffer->lights[i].spotlightCutoff);
+            
+            lights[i].constantAttenuation->setNumber(buffer->lights[i].constantAttenuation);
+            lights[i].linearAttenuation->setNumber(buffer->lights[i].linearAttenuation);
+            lights[i].quadraticAttenuation->setNumber(buffer->lights[i].quadraticAttenuation);
+            
+        } else {
+            lights[i].diffuse->setColor(Color(0.0, 0.0, 0.0, 1.0));
+            lights[i].specular->setColor(Color(0.0, 0.0, 0.0, 1.0));
+        }
+    }
+    
     for(int i=0; i < buffer->drawCalls.size(); i++) {
         
         
@@ -132,30 +165,17 @@ void RenderThread::processDrawBuffer(GPUDrawBuffer *buffer) {
                 
                 graphicsInterface->useShader(shaderPass.shader);
 
-
                 graphicsInterface->setWireframeMode(shaderPass.wireframe);
                 
                 ShaderBinding *materialShaderBinding = material->getShaderBinding(s);
-                
-                // set shader uniforms
-                
-                for(int p=0; p < rendererShaderBinding->getNumLocalParams(); p++) {
-                    
-                    LocalShaderParam *localParam = rendererShaderBinding->getLocalParam(p);
-                    if(localParam) {
 
-        // TODO: can't cache the param here, need a better system (move to material binding?)
-                        
-//                        if(!localParam->param) {
-                            localParam->param = shaderPass.shader->getParamPointer(localParam->name);
-  //                      }
-                        if(localParam->param) {
-                            graphicsInterface->setParamInShader(shaderPass.shader, localParam->param, localParam);
-                        }
+                // set global params
+                for(int p=0; p < shaderPass.shader->expectedParams.size(); p++) {
+                    if(shaderPass.shader->expectedParams[p].globalParam) {
+                        graphicsInterface->setParamInShader(shaderPass.shader, &shaderPass.shader->expectedParams[p], shaderPass.shader->expectedParams[p].globalParam);
                     }
-                    
                 }
-   
+                 
                 if(materialShaderBinding) {
                     for(int p=0; p < materialShaderBinding->getNumLocalParams(); p++) {                        
                         LocalShaderParam *localParam = materialShaderBinding->getLocalParam(p);
@@ -278,6 +298,19 @@ void RenderThread::processJob(const RendererThreadJob &job) {
         {
             Shader *shader = (Shader*) job.data;
             graphicsInterface->createShader(shader);
+            
+            // set renderer global params
+            for(int p=0; p < rendererShaderBinding->getNumLocalParams(); p++) {
+                LocalShaderParam *localParam = rendererShaderBinding->getLocalParam(p);
+                if(localParam) {
+                    ProgramParam *paramPtr = shader->getParamPointer(localParam->name);
+                    if(paramPtr) {
+                        paramPtr->globalParam = localParam;
+                    }
+                }
+            }
+            
+            
         }
         break;
         case JOB_CREATE_VERTEX_BUFFERS:

+ 5 - 2
src/core/PolyScene.cpp

@@ -227,7 +227,7 @@ void Scene::Render(Camera *targetCamera, Texture *targetFramebuffer) {
     drawBuffer->clearDepthBuffer = useClearDepth;
     drawBuffer->targetFramebuffer = targetFramebuffer;
     drawBuffer->viewport = targetCamera->getViewport();
-    drawBuffer->globalMaterial = overrideMaterial;
+    drawBuffer->globalMaterial = overrideMaterial;	
 		
 	//make these the closest
 	
@@ -282,7 +282,10 @@ void Scene::Render(Camera *targetCamera, Texture *targetFramebuffer) {
 			position = light->getParentEntity()->getConcatenatedMatrix() * position;			
 		}
         
-		//CoreServices::getInstance()->getRenderer()->addLight(light->getLightImportance(), position, direction, light->getLightType(), light->lightColor, light->specularLightColor, light->getConstantAttenuation(), light->getLinearAttenuation(), light->getQuadraticAttenuation(), light->getIntensity(), light->getSpotlightCutoff(), light->getSpotlightExponent(), light->areShadowsEnabled(), matrixPtr, shadowMapTexture);
+        
+        drawBuffer->lights.push_back(light->getLightInfo());
+        drawBuffer->lights[drawBuffer->lights.size()-1].position = position;
+        drawBuffer->lights[drawBuffer->lights.size()-1].direction = direction;
 	}	
 		
     	/*

+ 2 - 2
src/core/PolySceneEntityInstance.cpp

@@ -426,8 +426,8 @@ Entity *SceneEntityInstance::loadObjectEntryIntoEntity(ObjectEntry *entry, Entit
                     newLight->setLightImportance(importanceEntry->intVal);
                 }
                 
-                newLight->lightColor.setColor((*lightEntry)["cR"]->NumberVal, (*lightEntry)["cG"]->NumberVal, (*lightEntry)["cB"]->NumberVal, (*lightEntry)["cA"]->NumberVal);
-                newLight->specularLightColor.setColor((*lightEntry)["scR"]->NumberVal, (*lightEntry)["scG"]->NumberVal, (*lightEntry)["scB"]->NumberVal, (*lightEntry)["scA"]->NumberVal);
+                newLight->setDiffuseLightColor((*lightEntry)["cR"]->NumberVal, (*lightEntry)["cG"]->NumberVal, (*lightEntry)["cB"]->NumberVal, (*lightEntry)["cA"]->NumberVal);
+                newLight->setSpecularLightColor((*lightEntry)["scR"]->NumberVal, (*lightEntry)["scG"]->NumberVal, (*lightEntry)["scB"]->NumberVal, (*lightEntry)["scA"]->NumberVal);
 
                 newLight->setAttenuation((*lightEntry)["cAtt"]->NumberVal, (*lightEntry)["lAtt"]->NumberVal, (*lightEntry)["qAtt"]->NumberVal);
                 

+ 64 - 35
src/core/PolySceneLight.cpp

@@ -32,39 +32,39 @@
 using namespace Polycode;
 
 SceneLight::SceneLight(int type, Scene *parentScene, Number intensity, Number constantAttenuation, Number linearAttenuation, Number quadraticAttenuation) : Entity() {
-	this->type = type;
-	this->intensity = intensity;
-	this->constantAttenuation = constantAttenuation;
-	this->linearAttenuation = linearAttenuation;
-	this->quadraticAttenuation = quadraticAttenuation;
+	lightInfo.type = type;
+	lightInfo.intensity = intensity;
+	lightInfo.constantAttenuation = constantAttenuation;
+	lightInfo.linearAttenuation = linearAttenuation;
+	lightInfo.quadraticAttenuation = quadraticAttenuation;
 	
-	spotlightCutoff = 40;
-	spotlightExponent = 10;
+	lightInfo.spotlightCutoff = 40;
+	lightInfo.spotlightExponent = 10;
 		
     shadowMapRes = 256;
 	this->depthWrite = false;
 	    
 	shadowMapFOV = 60.0f;
-	zBufferTexture = NULL;
+	lightInfo.shadowMapTexture = NULL;
 	spotCamera = NULL;
 	this->parentScene = parentScene;
-	shadowsEnabled = false;
-	lightColor.setColor(1.0f,1.0f,1.0f,1.0f);
+	lightInfo.shadowsEnabled = false;
+	lightInfo.diffuseColor.setColor(1.0f,1.0f,1.0f,1.0f);
 	setSpotlightProperties(40,0.1);
 	
-	lightImportance = 0;
+	lightInfo.importance = 0;
 }
 
 void SceneLight::setLightType(int lightType) {
-    this->type = lightType;
+    lightInfo.type = lightType;
 }
 
 void SceneLight::setLightImportance(int newImportance) {
-	lightImportance = newImportance;
+	lightInfo.importance = newImportance;
 }
 
 int SceneLight::getLightImportance() const {
-	return lightImportance;
+	return lightInfo.importance;
 }
 
 void SceneLight::enableShadows(bool val, unsigned int resolution) {
@@ -91,18 +91,18 @@ void SceneLight::enableShadows(bool val, unsigned int resolution) {
 }
 
 bool SceneLight::areShadowsEnabled() const {
-	return shadowsEnabled;
+	return lightInfo.shadowsEnabled;
 }
 
 void SceneLight::setAttenuation(Number constantAttenuation, Number linearAttenuation, Number quadraticAttenuation) {
-	this->constantAttenuation = constantAttenuation;
-	this->linearAttenuation = linearAttenuation;
-	this->quadraticAttenuation = quadraticAttenuation;
+	lightInfo.constantAttenuation = constantAttenuation;
+	lightInfo.linearAttenuation = linearAttenuation;
+	lightInfo.quadraticAttenuation = quadraticAttenuation;
 }			
 
 
 void SceneLight::setIntensity(Number newIntensity) {
-	intensity = newIntensity;
+	lightInfo.intensity = newIntensity;
 }
 
 void SceneLight::setShadowMapFOV(Number fov) {
@@ -147,8 +147,12 @@ void SceneLight::renderDepthMap(Scene *scene) {
      */
 }
 
+LightInfo SceneLight::getLightInfo() const {
+    return lightInfo;
+}
+
 Entity *SceneLight::Clone(bool deepClone, bool ignoreEditorOnly) const {
-    SceneLight *newLight = new SceneLight(type, NULL, intensity, constantAttenuation, linearAttenuation, quadraticAttenuation);
+    SceneLight *newLight = new SceneLight(lightInfo.type, NULL, lightInfo.intensity, lightInfo.constantAttenuation, lightInfo.linearAttenuation, lightInfo.quadraticAttenuation);
     applyClone(newLight, deepClone, ignoreEditorOnly);
     return newLight;
 }
@@ -157,20 +161,49 @@ void SceneLight::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly
     Entity::applyClone(clone, deepClone, ignoreEditorOnly);
     SceneLight *cloneLight = (SceneLight*) clone;
     
-    cloneLight->setAttenuation(constantAttenuation, linearAttenuation, quadraticAttenuation);
-    cloneLight->setIntensity(intensity);
-    cloneLight->lightColor = lightColor;
-    cloneLight->specularLightColor = specularLightColor;
-    cloneLight->enableShadows(shadowsEnabled, shadowMapRes);
+    cloneLight->setAttenuation(lightInfo.constantAttenuation, lightInfo.linearAttenuation, lightInfo.quadraticAttenuation);
+    cloneLight->setIntensity(lightInfo.intensity);
+    cloneLight->setDiffuseLightColor(lightInfo.diffuseColor.r, lightInfo.diffuseColor.g, lightInfo.diffuseColor.b);
+    cloneLight->setSpecularLightColor(lightInfo.specularColor.r, lightInfo.specularColor.g, lightInfo.specularColor.b, lightInfo.specularColor.a);
+    cloneLight->enableShadows(lightInfo.shadowsEnabled, shadowMapRes);
     cloneLight->setShadowMapFOV(shadowMapFOV);
-    cloneLight->setSpotlightProperties(spotlightCutoff, spotlightExponent);
-    cloneLight->setLightType(type);
+    cloneLight->setSpotlightProperties(lightInfo.spotlightCutoff, lightInfo.spotlightExponent);
+    cloneLight->setLightType(lightInfo.type);
+}
+
+Number SceneLight::getConstantAttenuation() const {
+    return lightInfo.constantAttenuation;
+}
+
+Number SceneLight::getLinearAttenuation() const {
+    return lightInfo.linearAttenuation;
+}
+
+Number SceneLight::getQuadraticAttenuation() const {
+    return lightInfo.quadraticAttenuation;
+}
+
+void SceneLight::setSpotlightProperties(Number spotlightCutoff, Number spotlightExponent) {
+    lightInfo.spotlightCutoff = spotlightCutoff;
+    lightInfo.spotlightExponent = spotlightExponent;
+}
+
+Number SceneLight::getSpotlightCutoff() const {
+    return lightInfo.spotlightCutoff;
+}
+
+Number SceneLight::getSpotlightExponent() const{
+    return lightInfo.spotlightExponent;
 }
 
 Scene *SceneLight::getParentScene() const {
     return parentScene;
 }
 
+int SceneLight::getLightType() const {
+    return lightInfo.type;
+}
+
 void SceneLight::setParentScene(Scene *scene) {
     parentScene = scene;
     if(spotCamera) {
@@ -183,21 +216,17 @@ Camera *SceneLight::getSpotlightCamera() {
 }
 
 const Matrix4& SceneLight::getLightViewMatrix() const {
-	return lightViewMatrix;
+	return lightInfo.lightViewMatrix;
 }
 
 Texture *SceneLight::getZBufferTexture() const {
-	return zBufferTexture;
+	return lightInfo.shadowMapTexture;
 }
 
 Number SceneLight::getIntensity() const {
-	return intensity;
-}
-
-void SceneLight::Render() {
-    
+	return lightInfo.intensity;
 }
 
 int SceneLight::getType() const {
-	return type;
+	return lightInfo.type;
 }

+ 1 - 1
src/core/PolyShader.cpp

@@ -30,7 +30,7 @@ ShaderRenderTarget::ShaderRenderTarget() : PolyBase() {
 	texture = NULL;
 }
 
-ProgramParam::ProgramParam() : type(PARAM_UNKNOWN), platformData(NULL) {
+ProgramParam::ProgramParam() : type(PARAM_UNKNOWN), platformData(NULL), globalParam(NULL) {
 }
 
 ProgramAttribute::ProgramAttribute() : platformData(NULL) {

+ 2 - 9
src/ide/EntityEditorPropertyView.cpp

@@ -38,10 +38,6 @@ EntityEditorPropertyView::EntityEditorPropertyView() : UIElement() {
     entityProps->addPropSheet(materialSheet);
     materialSheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE);
     materialSheet->addEventListener(this, Event::CHANGE_EVENT);
-    
-    shaderTexturesSheet = new ShaderTexturesSheet();
-    entityProps->addPropSheet(shaderTexturesSheet);
-    shaderTexturesSheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE);
 
     shaderOptionsSheet = new ShaderOptionsSheet();
     entityProps->addPropSheet(shaderOptionsSheet);
@@ -129,7 +125,6 @@ void EntityEditorPropertyView::updateShaderOptions() {
     SceneLabel *sceneLabel = dynamic_cast<SceneLabel*>(targetEntity);
     SceneSprite *sceneSprite = dynamic_cast<SceneSprite*>(targetEntity);
     
-    shaderTexturesSheet->enabled = false;
     shaderOptionsSheet->enabled = false;
     
     if(sceneMesh) {
@@ -137,10 +132,8 @@ void EntityEditorPropertyView::updateShaderOptions() {
             
             // can't edit the textures manually on a scene label or sprite
             if(!sceneLabel && !sceneSprite) {
-            shaderTexturesSheet->setShader(sceneMesh->getMaterial()->getShader(0), sceneMesh->getMaterial(), sceneMesh->getShaderPass(0).shaderBinding);
-                shaderTexturesSheet->enabled = true;
-            }            
-            shaderOptionsSheet->setShader(sceneMesh->getMaterial()->getShader(0), sceneMesh->getMaterial(), sceneMesh->getShaderPass(0).shaderBinding);
+                shaderOptionsSheet->setShader(sceneMesh->getMaterial()->getShader(0), sceneMesh->getMaterial(), sceneMesh->getShaderPass(0).shaderBinding);
+            }
         }
     }
 }

+ 11 - 29
src/ide/PolycodeEntityEditor.cpp

@@ -2298,15 +2298,17 @@ void PolycodeEntityEditor::saveEntityToObjectEntry(Entity *entity, ObjectEntry *
         ObjectEntry *lightEntry = entry->addChild("SceneLight");
         lightEntry->addChild("type", light->getType());
 
-        lightEntry->addChild("cR", light->lightColor.r);
-        lightEntry->addChild("cG", light->lightColor.g);
-        lightEntry->addChild("cB", light->lightColor.b);
-        lightEntry->addChild("cA", light->lightColor.a);
+        LightInfo lightInfo = light->getLightInfo();
+        
+        lightEntry->addChild("cR", lightInfo.diffuseColor.r);
+        lightEntry->addChild("cG", lightInfo.diffuseColor.g);
+        lightEntry->addChild("cB", lightInfo.diffuseColor.b);
+        lightEntry->addChild("cA", lightInfo.diffuseColor.a);
 
-        lightEntry->addChild("scR", light->specularLightColor.r);
-        lightEntry->addChild("scG", light->specularLightColor.g);
-        lightEntry->addChild("scB", light->specularLightColor.b);
-        lightEntry->addChild("scA", light->specularLightColor.a);
+        lightEntry->addChild("scR", lightInfo.specularColor.r);
+        lightEntry->addChild("scG", lightInfo.specularColor.g);
+        lightEntry->addChild("scB", lightInfo.specularColor.b);
+        lightEntry->addChild("scA", lightInfo.specularColor.a);
 
         lightEntry->addChild("intensity", light->getIntensity());
         lightEntry->addChild("importance", light->getLightImportance());
@@ -2400,7 +2402,7 @@ void PolycodeEntityEditor::saveEntityToObjectEntry(Entity *entity, ObjectEntry *
             ObjectEntry *shaderOptions = meshEntry->addChild("shader_options");
             
             // RENDERER_TODO
-            //saveShaderOptionsToEntry(shaderOptions, sceneMesh->getMaterial(), sceneMesh->getLocalShaderOptions());
+            saveShaderOptionsToEntry(shaderOptions, sceneMesh->getMaterial(), sceneMesh->getShaderPass(0).shaderBinding);
         }
     }
     
@@ -2453,26 +2455,6 @@ void PolycodeEntityEditor::saveShaderOptionsToEntry(ObjectEntry *entry, Material
             ObjectEntry *texturesEntry = shaderEntry->addChild("textures");
             
             // RENDERER_TODO
-            /*
-            for(int j=0; j < shader->expectedTextures.size(); j++) {
-                Texture *texture = binding->getTexture(shader->expectedTextures[j]);
-                if(texture) {
-                    String texturePath = texture->getResourcePath();
-                    texturePath = texturePath.replace(parentProject->getRootFolder()+"/", "");
-                    ObjectEntry *textureEntry = texturesEntry->addChild("texture", texturePath);
-                    textureEntry->addChild("name", shader->expectedTextures[j]);
-                }
-            }
-            
-            for(int j=0; j < shader->expectedCubemaps.size(); j++) {
-                Cubemap *cubemap = binding->getCubemap(shader->expectedCubemaps[j]);
-                if(cubemap) {
-                    String cubemapName = cubemap->getResourceName();
-                    ObjectEntry *cubemapEntry = texturesEntry->addChild("cubemap", cubemapName);
-                    cubemapEntry->addChild("name", shader->expectedCubemaps[j]);
-                }
-            }
-            */
             
             if(shader->expectedParams.size() > 0 || shader->expectedParams.size() > 0) {
                 ObjectEntry *paramsEntry = shaderEntry->addChild("params");

+ 4 - 13
src/ide/PolycodeMaterialEditor.cpp

@@ -72,8 +72,6 @@ PostEditorPane::PostEditorPane(ResourcePool *resourcePool) : UIElement() {
 	optionsPropList->addPropSheet(targetBindingProps);
 	targetBindingProps->addEventListener(this, Event::CHANGE_EVENT);
 		
-	shaderTextureSheet = new ShaderTexturesSheet();
-	optionsPropList->addPropSheet(shaderTextureSheet);
 
 	shaderOptionsSheet = new ShaderOptionsSheet();
 	optionsPropList->addPropSheet(shaderOptionsSheet);
@@ -183,8 +181,7 @@ void PostEditorPane::handleEvent(Event *event) {
 				Material *material = passProps->selectedProp->material;
 				ShaderBinding *binding = material->getShaderBinding(shaderIndex);
 				targetBindingProps->setShader(currentMaterial->getShader(shaderIndex), material, binding);
-				shaderTextureSheet->setShader(currentMaterial->getShader(shaderIndex), material, binding);
-				shaderOptionsSheet->setShader(currentMaterial->getShader(shaderIndex), material, binding);		
+				shaderOptionsSheet->setShader(currentMaterial->getShader(shaderIndex), material, binding);
 				optionsPropList->visible = true;
 				optionsPropList->enabled = true;	
 				
@@ -887,10 +884,6 @@ MaterialEditorPane::MaterialEditorPane() : UIElement() {
 	
 	baseProps->propHeight = 130;	
 	
-	shaderTextureSheet = new ShaderTexturesSheet();
-	propList->addPropSheet(shaderTextureSheet);			
-	shaderTextureSheet->addEventListener(this, Event::CHANGE_EVENT);
-		
 	shaderOptionsSheet = new ShaderOptionsSheet();
 	propList->addPropSheet(shaderOptionsSheet);
 	shaderOptionsSheet->addEventListener(this, Event::CHANGE_EVENT);
@@ -929,11 +922,10 @@ void MaterialEditorPane::Resize(Number width, Number height) {
 void MaterialEditorPane::handleEvent(Event *event) {
 
 	if(event->getDispatcher() == currentMaterial) {
-		shaderTextureSheet->setShader(currentMaterial->getShader(0), currentMaterial, currentMaterial->getShaderBinding(0));
-		shaderOptionsSheet->setShader(currentMaterial->getShader(0), currentMaterial, currentMaterial->getShaderBinding(0));		
+		shaderOptionsSheet->setShader(currentMaterial->getShader(0), currentMaterial, currentMaterial->getShaderBinding(0));
 	}
 
-	if(event->getDispatcher() == shaderTextureSheet || event->getDispatcher() == shaderOptionsSheet) {
+	if(event->getDispatcher() == shaderOptionsSheet) {
 		if(!changingMaterial) {
 			dispatchEvent(new Event(), Event::CHANGE_EVENT);
 		}		
@@ -960,8 +952,7 @@ void MaterialEditorPane::handleEvent(Event *event) {
 				materialPreview->setMaterial(currentMaterial);					
 			}
 			
-			shaderTextureSheet->setShader(selectedShader, currentMaterial, currentMaterial->getShaderBinding(0));
-			shaderOptionsSheet->setShader(selectedShader, currentMaterial, currentMaterial->getShaderBinding(0));
+            shaderOptionsSheet->setShader(selectedShader, currentMaterial, currentMaterial->getShaderBinding(0));
 		}
 		
 		if(!changingMaterial) {

+ 60 - 149
src/ide/PolycodeProps.cpp

@@ -2300,14 +2300,20 @@ void ShaderOptionsSheet::handleEvent(Event *event) {
                     }
 					(*(Number*)param->data) = ((NumberProp*)props[i])->get();
 				} else if(props[i]->propType == "Color") {
-                    
                     if(!param){
                         param = binding->addParam(ProgramParam::PARAM_COLOR, props[i]->label->getText());
                     }
-                    
 					(*(Color*)param->data) = ((ColorProp*)props[i])->get();
 				
-				}
+                } else if(props[i]->propType == "Texture") {
+                    if(!param){
+                        param = binding->addParam(ProgramParam::PARAM_TEXTURE, props[i]->label->getText());
+                    }
+                    param->setTexture(((TextureProp*)props[i])->get());
+                    
+                }
+
+                
 				dispatchEvent(new Event(), Event::CHANGE_EVENT);				
 				return;
 			}
@@ -2334,40 +2340,58 @@ void ShaderOptionsSheet::clearShader() {
 void ShaderOptionsSheet::setOptionsFromParams(std::vector<ProgramParam> &params) {
 
 	for(int i=0; i < params.size(); i++) {
-        switch (params[i].type) {
-            case ProgramParam::PARAM_NUMBER:
-            {
-                String paramName = params[i].name;
-                NumberProp *numberProp = new NumberProp(paramName, this);
-                addProp(numberProp);
-                                        
-                LocalShaderParam *param = binding->getLocalParamByName(params[i].name);
-                Number numberValue = 0.0;
-                if(param) {
-                    numberValue = (*(Number*)param->data);
+        if(!params[i].globalParam) {
+            switch (params[i].type) {
+                case ProgramParam::PARAM_TEXTURE:
+                {
+                    String paramName = params[i].name;
+                    TextureProp *textureProp = new TextureProp(paramName);
+                    addProp(textureProp);
+                    
+                    LocalShaderParam *param = binding->getLocalParamByName(params[i].name);
+                    Texture *texture = NULL;
+                    if(param) {
+                        texture = param->getTexture();
+                    }
+                    textureProp->set(texture);
+                    propHeight += 30;
+
                 }
-                numberProp->set(numberValue);
-                propHeight += 30;
-            }
-            break;					
-            case ProgramParam::PARAM_COLOR:
-            {
-                String paramName = params[i].name;
+                break;
+                case ProgramParam::PARAM_NUMBER:
+                {
+                    String paramName = params[i].name;
+                    NumberProp *numberProp = new NumberProp(paramName, this);
+                    addProp(numberProp);
+                                            
+                    LocalShaderParam *param = binding->getLocalParamByName(params[i].name);
+                    Number numberValue = 0.0;
+                    if(param) {
+                        numberValue = param->getNumber();
+                    }
+                    numberProp->set(numberValue);
+                    propHeight += 30;
+                }
+                break;					
+                case ProgramParam::PARAM_COLOR:
+                {
+                    String paramName = params[i].name;
 
-                LocalShaderParam *param = binding->getLocalParamByName(params[i].name);
+                    LocalShaderParam *param = binding->getLocalParamByName(params[i].name);
 
-                ColorProp *colorProp = new ColorProp(paramName);
-                addProp(colorProp);
-                
-                Color colorValue;
-                if(param) {
-                    colorValue = (*(Color*)param->data);
+                    ColorProp *colorProp = new ColorProp(paramName);
+                    addProp(colorProp);
+                    
+                    Color colorValue;
+                    if(param) {
+                        colorValue = param->getColor();
+                    }
+                    colorProp->set(colorValue);
+                    
+                    propHeight += 40;				
                 }
-                colorProp->set(colorValue);
-                
-                propHeight += 40;				
+                break;
             }
-            break;
         }
     }
 }
@@ -2390,119 +2414,6 @@ void ShaderOptionsSheet::setShader(Shader *shader, Material *material, ShaderBin
 	Resize(getWidth(), getHeight());
 }
 
-ShaderTexturesSheet::ShaderTexturesSheet() : PropSheet("SHADER TEXTURES", "shader_textures"){
-	shader = NULL;
-	propHeight = 40;
-    customUndoHandler = true;
-    enabled = false;
-}
-
-ShaderTexturesSheet::~ShaderTexturesSheet() {
-
-}
-
-void ShaderTexturesSheet::handleEvent(Event *event) {
-
-	if(event->getEventCode() == Event::CHANGE_EVENT) {
-		for(int i=0; i < textureProps.size(); i++) {
-			if(event->getDispatcher() == textureProps[i]) {
-				binding->removeParam(textureProps[i]->label->getText());
-				binding->setTextureForParam(textureProps[i]->label->getText(), textureProps[i]->get());
-				dispatchEvent(new Event(), Event::CHANGE_EVENT);
-			}
-		}	
-		
-		for(int i=0; i < cubemapProps.size(); i++) {
-			if(event->getDispatcher() == cubemapProps[i]) {
-				binding->removeParam(cubemapProps[i]->label->getText());
-				Cubemap *cubemap = (Cubemap*)cubemapProps[i]->comboEntry->getSelectedItem()->data;
-				binding->setCubemapForParam(cubemapProps[i]->label->getText(), cubemap);
-				dispatchEvent(new Event(), Event::CHANGE_EVENT);
-			}
-		}	
-		
-	}
-	PropSheet::handleEvent(event);
-}
-
-void ShaderTexturesSheet::Update() {
-
-}
-
-void ShaderTexturesSheet::clearShader() {
-	for(int i=0; i < props.size(); i++) {
-		contents->removeChild(props[i]);
-		props[i]->removeAllHandlersForListener(this);
-		delete props[i];
-	}
-	
-	props.clear();
-	cubemapProps.clear();
-	textureProps.clear();
-	
-	propHeight = 30;
-}
-
-void ShaderTexturesSheet::setShader(Shader *shader, Material *material, ShaderBinding *binding) {
-	clearShader();
-	this->shader = shader;
-	this->material = material;
-	
-    enabled = true;
-    
-	if(!shader || !material)
-		return;
-		
-	this->binding = binding;
-
-    // RENDERER_TODO
-    /*
-	for(int i=0; i < shader->expectedCubemaps.size(); i++) {
-		ComboProp *comboProp = new ComboProp(shader->expectedCubemaps[i]);
-		
-		std::vector<Resource*> cubemaps = CoreServices::getInstance()->getResourceManager()->getResources(Resource::RESOURCE_CUBEMAP);
-		
-		for(int j=0; j < cubemaps.size(); j++) {
-			comboProp->comboEntry->addComboItem(cubemaps[j]->getResourceName(), (void*) cubemaps[j]);
-			if(material) {
-				if(binding) {
-					Cubemap *currentCubemap = binding->getCubemap(shader->expectedCubemaps[i]);
-					if(currentCubemap) {
-						if(currentCubemap->getResourceName() == cubemaps[j]->getResourceName()) {
-							comboProp->set(j);
-						}
-					}
-				}
-			}
-		}
-				
-		addProp(comboProp);
-		cubemapProps.push_back(comboProp);
-		propHeight += 45;
-	}
-	
-	for(int i=0; i < shader->expectedTextures.size(); i++) {
-		TextureProp *textureProp = new TextureProp(shader->expectedTextures[i]);
-		
-		if(material) {
-			if(binding) {
-				Texture *currentTexture = binding->getTexture(shader->expectedTextures[i]);
-				if(currentTexture) {
-					textureProp->set(currentTexture);
-				}
-			}
-		}
-		
-		addProp(textureProp);
-		textureProps.push_back(textureProp);
-		propHeight += 65;
-	}
-     */
-
-	dispatchEvent(new Event(), Event::COMPLETE_EVENT);	
-	Resize(getWidth(), getHeight());
-}
-
 TransformSheet::TransformSheet() : PropSheet("TRANSFORM", "entity_transform") {
     entity = NULL;
     
@@ -2799,8 +2710,8 @@ void SceneLightSheet::setSceneLight(SceneLight *light) {
     
     if(light) {
         typeProp->set(light->getLightType());
-        lightColorProp->set(light->lightColor);
-        specularColorProp->set(light->specularLightColor);
+        lightColorProp->set(light->getLightInfo().diffuseColor);
+        specularColorProp->set(light->getLightInfo().specularColor);
         intensityProp->set(light->getIntensity());
         constantAttenuationProp->set(light->getConstantAttenuation());
         linearAttenuationProp->set(light->getLinearAttenuation());
@@ -2832,9 +2743,9 @@ void SceneLightSheet::handleEvent(Event *event) {
         if(event->getDispatcher() == typeProp) {
             light->setLightType(typeProp->get());
         } else if(event->getDispatcher() == lightColorProp) {
-            light->lightColor = lightColorProp->get();
+            light->setDiffuseLightColor(lightColorProp->get());
         } else if(event->getDispatcher() == specularColorProp) {
-            light->specularLightColor = specularColorProp->get();
+            light->setSpecularLightColor(specularColorProp->get());
         } else if(event->getDispatcher() == intensityProp) {
             light->setIntensity(intensityProp->get());
         } else if(event->getDispatcher() == constantAttenuationProp) {