Przeglądaj źródła

Cleaning up shaders, created separate mobile defaults

Ivan Safrin 9 lat temu
rodzic
commit
4fbfc4742c
31 zmienionych plików z 973 dodań i 98 usunięć
  1. 30 30
      assets/default/default/DefaultShader.frag
  2. 8 8
      assets/default/default/DefaultShader.vert
  3. 0 59
      assets/default/default/LightcubeAngular.frag
  4. 23 0
      assets/default_mobile/default/BlurH.frag
  5. 24 0
      assets/default_mobile/default/BlurV.frag
  6. 132 0
      assets/default_mobile/default/DefaultShader.frag
  7. 36 0
      assets/default_mobile/default/DefaultShader.vert
  8. 177 0
      assets/default_mobile/default/DefaultShaderShadows.frag
  9. 39 0
      assets/default_mobile/default/DefaultShaderShadows.vert
  10. 129 0
      assets/default_mobile/default/DefaultUntextured.frag
  11. 10 0
      assets/default_mobile/default/Invert.frag
  12. 43 0
      assets/default_mobile/default/LightCube.vert
  13. 45 0
      assets/default_mobile/default/LightcubePolar.frag
  14. 13 0
      assets/default_mobile/default/ScreenShader.vert
  15. 11 0
      assets/default_mobile/default/Unlit.frag
  16. 18 0
      assets/default_mobile/default/Unlit.vert
  17. 17 0
      assets/default_mobile/default/UnlitPoint.vert
  18. 9 0
      assets/default_mobile/default/UnlitUntextured.frag
  19. 15 0
      assets/default_mobile/default/UnlitUntextured.vert
  20. 10 0
      assets/default_mobile/default/UnlitUntexturedVertexColor.frag
  21. 19 0
      assets/default_mobile/default/UnlitUntexturedVertexColor.vert
  22. 9 0
      assets/default_mobile/default/UnlitWireframe.frag
  23. BIN
      assets/default_mobile/default/default.entity2d
  24. 148 0
      assets/default_mobile/default/default.mat
  25. BIN
      assets/default_mobile/default/default.png
  26. 7 0
      assets/default_mobile/default/default.sprite
  27. BIN
      assets/default_mobile/default/default.wav
  28. BIN
      assets/default_mobile/default/mono.ttf
  29. BIN
      assets/default_mobile/default/sans.ttf
  30. BIN
      assets/default_mobile/default/serif.ttf
  31. 1 1
      lib

+ 30 - 30
assets/default/default/DefaultShader.frag

@@ -1,24 +1,24 @@
 #ifdef GL_ES
-	precision mediump float;	
+	precision mediump float;
 #endif
 
-varying lowp vec2 texCoordVar;
-varying lowp vec3 varNormal;
-varying lowp vec4 varPosition;
+varying vec2 texCoordVar;
+varying vec3 varNormal;
+varying vec4 varPosition;
 
 uniform sampler2D diffuse;
-uniform lowp vec4 diffuse_color;
-uniform lowp vec4 specular_color;
-uniform lowp vec4 entityColor;
+uniform vec4 diffuse_color;
+uniform vec4 specular_color;
+uniform vec4 entityColor;
 uniform float shininess;
 
-#define MAX_LIGHTS 4
+#define MAX_LIGHTS 8
 
 struct LightInfo {
-	lowp vec3 position;
-	lowp vec3 direction;
-	lowp vec4 specular;
-	lowp vec4 diffuse;
+	vec3 position;
+	vec3 direction;
+	vec4 specular;
+	vec4 diffuse;
 
 	float spotExponent;
 	float spotCosCutoff;
@@ -38,19 +38,19 @@ float calculateAttenuation(in int i, in float dist)
 }
 
 void pointLight(in int i, in vec3 normal, in vec4 pos, inout vec4 diffuse, inout vec4 specular) {
-	lowp vec4 color = diffuse_color;
-	lowp vec4 matspec = specular_color;
+	vec4 color = diffuse_color;
+	vec4 matspec = specular_color;
 	float shininess = shininess;
-	lowp vec4 lightspec = lights[i].specular;
-	lowp vec4 lpos = vec4(lights[i].position, 1.0);
-	lowp vec4 s = pos-lpos; 
-	lowp vec4 sn = -normalize(s);
+	vec4 lightspec = lights[i].specular;
+	vec4 lpos = vec4(lights[i].position, 1.0);
+	vec4 s = pos-lpos; 
+	vec4 sn = -normalize(s);
 	
-	lowp vec3 light = sn.xyz;
-	lowp vec3 n = normalize(normal);
-	lowp vec3 r = -reflect(light, n);
+	vec3 light = sn.xyz;
+	vec3 n = normalize(normal);
+	vec3 r = -reflect(light, n);
 	r = normalize(r);
-	lowp vec3 v = -pos.xyz;
+	vec3 v = -pos.xyz;
 	v = normalize(v);
 
 	float nDotL = dot(n, sn.xyz);
@@ -105,25 +105,25 @@ void spotLight(in int i, in vec3 normal, in vec4 pos, inout vec4 diffuse, inout
 
 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) {
+		if (lights[i].spotCosCutoff == 180.0) {
 			pointLight(i, normal, pos, diffuse, specular);
-		//} else {
-		//	spotLight(i, normal, pos, diffuse, specular);
-		//}
+		} else {
+			spotLight(i, normal, pos, diffuse, specular);
+		}
     }
 }
 
 
 void main()
 {
-	lowp vec4 diffuse_val  = vec4(0.0);
-	lowp vec4 specular_val = vec4(0.0);
+	vec4 diffuse_val  = vec4(0.0);
+	vec4 specular_val = vec4(0.0);
 
 	doLights(MAX_LIGHTS, varNormal, varPosition, diffuse_val, specular_val);
 		
-	lowp vec4 texColor = texture2D(diffuse, texCoordVar);		
+	vec4 texColor = texture2D(diffuse, texCoordVar);		
 		
-    lowp vec4 color = diffuse_val; 	           
+    vec4 color = diffuse_val; 	           
     color = clamp((color*entityColor*texColor) + specular_val, 0.0, 1.0);  
 
 	color.a = entityColor.a * texColor.a * diffuse_color.a;	

+ 8 - 8
assets/default/default/DefaultShader.vert

@@ -2,17 +2,17 @@
 	precision mediump float;
 #endif
 
-attribute lowp vec4 position;
-attribute lowp vec3 normal;
-attribute lowp vec2 texCoord;
+attribute vec4 position;
+attribute vec3 normal;
+attribute vec2 texCoord;
 
 uniform mat4 modelMatrix;
 uniform mat4 viewMatrix;
 uniform mat4 projectionMatrix;
 
-varying lowp vec2 texCoordVar;
-varying lowp vec3 varNormal;
-varying lowp vec4 varPosition;
+varying vec2 texCoordVar;
+varying vec3 varNormal;
+varying vec4 varPosition;
 
 mat3 mat3_emu(mat4 m4) {
   return mat3(
@@ -24,9 +24,9 @@ mat3 mat3_emu(mat4 m4) {
 void main()
 {
 	mat4 modelViewMatrix = viewMatrix * modelMatrix;
-	lowp vec4 p = modelViewMatrix  * position;
+	vec4 p = modelViewMatrix  * position;
 
-	lowp mat3 rotN = mat3_emu(modelViewMatrix);
+	mat3 rotN = mat3_emu(modelViewMatrix);
 	varNormal = normalize(rotN * normal);
 
 	varPosition = modelViewMatrix  * position;

+ 0 - 59
assets/default/default/LightcubeAngular.frag

@@ -1,59 +0,0 @@
-#ifdef GL_ES
-   precision mediump float;
-#endif
-
-uniform sampler2D angularMap;
-varying vec4 vertexColor;
-varying vec3 normal;
-uniform vec4 ambient_color;
-varying vec3 worldNormal;
-
-uniform float lightFactor;
-
-vec3 hash3( float n )
-{
-    return fract(sin(vec3(n,n+1.0,n+2.0))*vec3(43758.5453123,22578.1459123,19642.3490423));
-}
-
-void main()
-{
-	vec3 col = vec3(0.0);
-	for( int i=0; i<32; i++ )
-	{			
-		vec3 rr = normalize(-1.0 + 2.0*hash3(float(i)*123.5463));
-		rr = normalize( worldNormal + 7.0*rr );
-		rr = rr * sign(dot(worldNormal,rr));
-
-
-		float m = 2. * sqrt( 
-        pow( rr.x, 2. ) + 
-        pow( rr.y, 2. ) + 
-        pow( rr.z + 1., 2. ) 
- 	   );
-	
-		vec2 vN = rr.xy / m + .5;
-        col += pow( texture2D( angularMap, vN).xyz, vec3(1.0) ) * dot(rr,worldNormal);
-	}
-
-	col = col * lightFactor / 32.0;
-
-    vec4 texColor = vec4(col, 1.0);
-
-    vec4 color = vec4(1.0,1.0,1.0,1.0) + ambient_color; 	           
-    color = clamp((color*vertexColor*texColor), 0.0, 1.0);  
-
-    // fog
-	const float LOG2 = 1.442695;
-	float z = gl_FragCoord.z / gl_FragCoord.w;
-	float fogFactor = exp2( -gl_Fog.density * 
-				   gl_Fog.density * 
-				   z * 
-				   z * 
-				   LOG2 );
-
-	fogFactor = clamp(fogFactor, 0.0, 1.0);
-	color = mix(gl_Fog.color, color, fogFactor );   
-
-	color.a = vertexColor.a * texColor.a;    
-    gl_FragColor = color;
-}

+ 23 - 0
assets/default_mobile/default/BlurH.frag

@@ -0,0 +1,23 @@
+#ifdef GL_ES
+   precision mediump float;
+#endif
+
+uniform sampler2D screenTexture;
+uniform float blurSize;
+varying vec2 texCoordVar;
+
+void main(void)
+{
+   vec4 sum = vec4(0.0);
+   sum += texture2D(screenTexture, vec2(texCoordVar.x - 4.0*blurSize, texCoordVar.y)) * 0.05;
+   sum += texture2D(screenTexture, vec2(texCoordVar.x - 3.0*blurSize, texCoordVar.y)) * 0.09;
+   sum += texture2D(screenTexture, vec2(texCoordVar.x - 2.0*blurSize, texCoordVar.y)) * 0.12;
+   sum += texture2D(screenTexture, vec2(texCoordVar.x - blurSize, texCoordVar.y)) * 0.15;
+   sum += texture2D(screenTexture, vec2(texCoordVar.x, texCoordVar.y)) * 0.16;
+   sum += texture2D(screenTexture, vec2(texCoordVar.x + blurSize, texCoordVar.y)) * 0.15;
+   sum += texture2D(screenTexture, vec2(texCoordVar.x + 2.0*blurSize, texCoordVar.y)) * 0.12;
+   sum += texture2D(screenTexture, vec2(texCoordVar.x + 3.0*blurSize, texCoordVar.y)) * 0.09;
+   sum += texture2D(screenTexture, vec2(texCoordVar.x + 4.0*blurSize, texCoordVar.y)) * 0.05;
+   
+   gl_FragColor = sum;
+}

+ 24 - 0
assets/default_mobile/default/BlurV.frag

@@ -0,0 +1,24 @@
+#ifdef GL_ES
+   precision mediump float;
+#endif
+
+uniform sampler2D screenTexture;
+uniform float blurSize;
+varying vec2 texCoordVar;
+
+void main(void)
+{
+   vec4 sum = vec4(0.0);
+   sum += texture2D(screenTexture, vec2(texCoordVar.x, texCoordVar.y - 4.0*blurSize)) * 0.05;
+   sum += texture2D(screenTexture, vec2(texCoordVar.x, texCoordVar.y - 3.0*blurSize)) * 0.09;
+   sum += texture2D(screenTexture, vec2(texCoordVar.x, texCoordVar.y - 2.0*blurSize)) * 0.12;
+   sum += texture2D(screenTexture, vec2(texCoordVar.x, texCoordVar.y - blurSize)) * 0.15;
+   sum += texture2D(screenTexture, vec2(texCoordVar.x, texCoordVar.y)) * 0.16;
+   sum += texture2D(screenTexture, vec2(texCoordVar.x, texCoordVar.y + blurSize)) * 0.15;
+   sum += texture2D(screenTexture, vec2(texCoordVar.x, texCoordVar.y + 2.0*blurSize)) * 0.12;
+   sum += texture2D(screenTexture, vec2(texCoordVar.x, texCoordVar.y + 3.0*blurSize)) * 0.09;
+   sum += texture2D(screenTexture, vec2(texCoordVar.x, texCoordVar.y + 4.0*blurSize)) * 0.05;
+   
+   gl_FragColor = sum;
+
+}

+ 132 - 0
assets/default_mobile/default/DefaultShader.frag

@@ -0,0 +1,132 @@
+#ifdef GL_ES
+	precision mediump float;	
+#endif
+
+varying lowp vec2 texCoordVar;
+varying lowp vec3 varNormal;
+varying lowp vec4 varPosition;
+
+uniform sampler2D diffuse;
+uniform lowp vec4 diffuse_color;
+uniform lowp vec4 specular_color;
+uniform lowp vec4 entityColor;
+uniform float shininess;
+
+#define MAX_LIGHTS 4
+
+struct LightInfo {
+	lowp vec3 position;
+	lowp vec3 direction;
+	lowp vec4 specular;
+	lowp 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) {
+	lowp vec4 color = diffuse_color;
+	lowp vec4 matspec = specular_color;
+	float shininess = shininess;
+	lowp vec4 lightspec = lights[i].specular;
+	lowp vec4 lpos = vec4(lights[i].position, 1.0);
+	lowp vec4 s = pos-lpos; 
+	lowp vec4 sn = -normalize(s);
+	
+	lowp vec3 light = sn.xyz;
+	lowp vec3 n = normalize(normal);
+	lowp vec3 r = -reflect(light, n);
+	r = normalize(r);
+	lowp 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()
+{
+	lowp vec4 diffuse_val  = vec4(0.0);
+	lowp vec4 specular_val = vec4(0.0);
+
+	doLights(MAX_LIGHTS, varNormal, varPosition, diffuse_val, specular_val);
+		
+	lowp vec4 texColor = texture2D(diffuse, texCoordVar);		
+		
+    lowp vec4 color = diffuse_val; 	           
+    color = clamp((color*entityColor*texColor) + specular_val, 0.0, 1.0);  
+
+	color.a = entityColor.a * texColor.a * diffuse_color.a;	
+	gl_FragColor = color;
+
+}

+ 36 - 0
assets/default_mobile/default/DefaultShader.vert

@@ -0,0 +1,36 @@
+#ifdef GL_ES
+	precision mediump float;
+#endif
+
+attribute lowp vec4 position;
+attribute lowp vec3 normal;
+attribute lowp vec2 texCoord;
+
+uniform mat4 modelMatrix;
+uniform mat4 viewMatrix;
+uniform mat4 projectionMatrix;
+
+varying lowp vec2 texCoordVar;
+varying lowp vec3 varNormal;
+varying lowp 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;
+	lowp vec4 p = modelViewMatrix  * position;
+
+	lowp mat3 rotN = mat3_emu(modelViewMatrix);
+	varNormal = normalize(rotN * normal);
+
+	varPosition = modelViewMatrix  * position;
+	gl_Position = projectionMatrix * p;
+
+	texCoordVar = texCoord;
+}

+ 177 - 0
assets/default_mobile/default/DefaultShaderShadows.frag

@@ -0,0 +1,177 @@
+#ifdef GL_ES
+	precision mediump float;
+#endif
+
+varying vec2 texCoordVar;
+varying vec3 varNormal;
+varying vec4 varPosition;
+varying vec4 rawPosition;
+
+uniform sampler2D diffuse;
+
+uniform mat4 modelMatrix;
+uniform vec4 diffuse_color;
+uniform vec4 specular_color;
+uniform vec4 entityColor;
+uniform float shininess;
+uniform float shadowAmount;
+
+#define MAX_LIGHTS 8
+#define MAX_LIGHT_SHADOWS 2
+
+struct LightInfo {
+	vec3 position;
+	vec3 direction;
+	vec4 specular;
+	vec4 diffuse;
+
+	float spotExponent;
+	float spotCosCutoff;
+
+	float constantAttenuation;
+	float linearAttenuation;	
+	float quadraticAttenuation;
+	float shadowEnabled;
+};
+
+struct LightShadowInfo {
+	sampler2D shadowBuffer;
+	mat4 shadowMatrix;	
+};
+
+uniform LightInfo lights[MAX_LIGHTS];
+uniform LightShadowInfo lightsShadows[MAX_LIGHT_SHADOWS];
+
+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, in float shadow) {
+
+	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 * shadow;
+
+	  if (shininess != 0.0) {
+    	specular += lightspec * matspec * pow(max(0.0,dot(r, v)), shininess) * attenuation * spot * shadow;
+	  }
+	}
+}
+
+void doSpotLightShadow(in int i, in vec3 normal, in vec4 pos, inout vec4 diffuse, inout vec4 specular, inout int shadowIndex) {
+	if(lights[i].shadowEnabled == 1.0) {
+
+		float shadow = 1.0;
+		float bias = 0.00001;
+
+		if(shadowIndex == 0) {
+			vec4 shadowCoord = lightsShadows[0].shadowMatrix * modelMatrix * rawPosition;
+			vec4 shadowCoordinateWdivide = shadowCoord / shadowCoord.w;
+			float distanceFromLight = texture2D(lightsShadows[0].shadowBuffer, shadowCoordinateWdivide.st).z;
+
+			if (shadowCoordinateWdivide.x > 0.001 && shadowCoordinateWdivide.y > 0.001 && shadowCoordinateWdivide.x < 0.999 && shadowCoordinateWdivide.y < 0.999) {
+				shadow = step(shadowCoordinateWdivide.z, distanceFromLight+bias);
+			}
+		} else {
+			vec4 shadowCoord = lightsShadows[1].shadowMatrix * modelMatrix * rawPosition;
+			vec4 shadowCoordinateWdivide = shadowCoord / shadowCoord.w;
+			float distanceFromLight = texture2D(lightsShadows[1].shadowBuffer, shadowCoordinateWdivide.st).z;
+
+			if (shadowCoordinateWdivide.x > 0.001 && shadowCoordinateWdivide.y > 0.001 && shadowCoordinateWdivide.x < 0.999 && shadowCoordinateWdivide.y < 0.999) {
+				shadow = step(shadowCoordinateWdivide.z, distanceFromLight+bias);
+			}
+		}
+		shadowIndex++;
+		spotLight(i, normal, pos, diffuse, specular, shadow);		
+	} else {
+		spotLight(i, normal, pos, diffuse, specular, 1.0);
+	}	
+}
+
+void doLights(in int numLights, in vec3 normal, in vec4 pos, inout vec4 diffuse, inout vec4 specular) {
+
+	int shadowIndex = 0;
+	for (int i = 0; i < numLights; i++) {
+		if (lights[i].spotCosCutoff == 180.0) {
+			pointLight(i, normal, pos, diffuse, specular);
+		} else {		
+			doSpotLightShadow(i, normal, pos, diffuse, specular, shadowIndex);
+		}
+    }
+}
+
+
+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; 	           
+    color = clamp((color*entityColor*texColor) + specular_val, 0.0, 1.0);  
+
+	color.a = entityColor.a * texColor.a * diffuse_color.a;	
+	gl_FragColor = color;
+
+}

+ 39 - 0
assets/default_mobile/default/DefaultShaderShadows.vert

@@ -0,0 +1,39 @@
+#ifdef GL_ES
+	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;
+varying vec4 rawPosition;
+
+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(modelViewMatrix);
+	varNormal = normalize(rotN * normal);
+
+	rawPosition = position;
+
+	varPosition = modelViewMatrix  * position;
+	gl_Position = projectionMatrix * p;
+
+	texCoordVar = texCoord;
+}

+ 129 - 0
assets/default_mobile/default/DefaultUntextured.frag

@@ -0,0 +1,129 @@
+#ifdef GL_ES
+	precision mediump float;
+#endif
+
+varying vec2 texCoordVar;
+varying vec3 varNormal;
+varying vec4 varPosition;
+
+uniform vec4 diffuse_color;
+uniform vec4 specular_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 color = diffuse_val; 	           
+    color = clamp((color*entityColor) + specular_val, 0.0, 1.0);  
+
+	color.a = entityColor.a * diffuse_color.a;	
+	gl_FragColor = color;
+
+}

+ 10 - 0
assets/default_mobile/default/Invert.frag

@@ -0,0 +1,10 @@
+#ifdef GL_ES
+	precision mediump float;
+#endif
+
+uniform sampler2D screenColorBuffer;
+varying vec2 texCoordVar;
+void main()
+{
+    gl_FragColor = vec4(1.0-texture2D( screenColorBuffer, texCoordVar).xyz, 1.0);
+}

+ 43 - 0
assets/default_mobile/default/LightCube.vert

@@ -0,0 +1,43 @@
+#ifdef GL_ES
+   precision mediump float;
+#endif
+
+attribute vec4 position;
+attribute vec3 normal;
+attribute vec2 texCoord;
+
+varying vec3 varNormal;
+varying vec3 worldNormal;
+varying vec4 pos;
+varying vec4 rawpos;
+varying vec4 vertexColor;
+varying vec2 texCoordVar;
+
+uniform mat4 modelMatrix;
+uniform mat4 viewMatrix;
+uniform mat4 projectionMatrix;
+
+
+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() {
+	varNormal = normal;
+
+	mat3 rotN = mat3_emu(modelMatrix);
+	worldNormal = rotN * normal;
+	worldNormal = normalize(worldNormal);
+
+	vec4 p = viewMatrix * modelMatrix  * position;
+	gl_Position = projectionMatrix * p;
+
+	pos = viewMatrix * modelMatrix * position;
+	rawpos = position;
+
+	texCoordVar = texCoord;
+
+}

+ 45 - 0
assets/default_mobile/default/LightcubePolar.frag

@@ -0,0 +1,45 @@
+#ifdef GL_ES
+   precision mediump float;
+#endif
+
+uniform sampler2D polarMap;
+uniform sampler2D diffuse;
+uniform vec4 entityColor;
+
+varying vec3 varNormal;
+varying vec3 worldNormal;
+varying vec2 texCoordVar;
+uniform float lightFactor;
+
+const float PI = 3.14159265359;
+
+vec2 sphere_map(vec3 n) {
+	return vec2(atan(n.z,n.x)/(2.0 * PI), acos(-n.y) / (PI));
+}
+
+vec3 hash3( float n )
+{
+    return fract(sin(vec3(n,n+1.0,n+2.0))*vec3(43758.5453123,22578.1459123,19642.3490423));
+}
+
+void main()
+{
+	vec3 col = vec3(0.0);
+	for( int i=0; i<32; i++ )
+	{			
+		vec3 rr = normalize(-1.0 + 2.0*hash3(float(i)*123.5463));
+		rr = normalize( worldNormal +7.0*rr );
+		rr = rr * sign(dot(worldNormal,rr));
+		vec2 vN = sphere_map(rr);
+
+        col += pow( texture2D( polarMap, vN).xyz, vec3(1.0) ) * dot(rr,worldNormal);
+	}
+
+	col = col / 32.0 * lightFactor;
+
+	vec4 texColor = texture2D(diffuse, texCoordVar);
+    vec4 color = mix(entityColor,texColor, texColor.a);
+    color.xyz = color.xyz * col;
+	color.a = 1.0;
+    gl_FragColor = color;
+}

+ 13 - 0
assets/default_mobile/default/ScreenShader.vert

@@ -0,0 +1,13 @@
+#ifdef GL_ES
+	precision mediump float;
+#endif
+
+attribute vec4 position;
+attribute vec2 texCoord;
+varying vec2 texCoordVar;
+
+void main()
+{
+    gl_Position =  position;
+    texCoordVar = texCoord;
+}

+ 11 - 0
assets/default_mobile/default/Unlit.frag

@@ -0,0 +1,11 @@
+#ifdef GL_ES
+	precision mediump float;
+#endif
+
+uniform sampler2D diffuse;
+uniform vec4 entityColor;
+varying vec2 texCoordVar;
+
+void main() {
+	gl_FragColor = texture2D(diffuse, texCoordVar) * entityColor;
+}

+ 18 - 0
assets/default_mobile/default/Unlit.vert

@@ -0,0 +1,18 @@
+#ifdef GL_ES
+	precision mediump float;
+#endif
+
+attribute vec4 position;
+attribute vec2 texCoord;
+
+uniform mat4 modelMatrix;
+uniform mat4 viewMatrix;
+uniform mat4 projectionMatrix;
+varying vec2 texCoordVar;
+
+void main()
+{
+	vec4 p = viewMatrix * modelMatrix  * position;
+	gl_Position = projectionMatrix * p;
+	texCoordVar = texCoord;
+}

+ 17 - 0
assets/default_mobile/default/UnlitPoint.vert

@@ -0,0 +1,17 @@
+#ifdef GL_ES
+	precision mediump float;
+#endif
+
+attribute vec4 position;
+uniform float pointSize;
+
+uniform mat4 modelMatrix;
+uniform mat4 viewMatrix;
+uniform mat4 projectionMatrix;
+
+void main()
+{
+	vec4 p = viewMatrix * modelMatrix  * position;
+	gl_Position = projectionMatrix * p;
+	gl_PointSize = pointSize;
+}

+ 9 - 0
assets/default_mobile/default/UnlitUntextured.frag

@@ -0,0 +1,9 @@
+#ifdef GL_ES
+	precision mediump float;
+#endif
+
+uniform vec4 entityColor;
+
+void main() {
+	gl_FragColor = entityColor;
+}

+ 15 - 0
assets/default_mobile/default/UnlitUntextured.vert

@@ -0,0 +1,15 @@
+#ifdef GL_ES
+	precision mediump float;
+#endif
+
+attribute vec4 position;
+
+uniform mat4 modelMatrix;
+uniform mat4 viewMatrix;
+uniform mat4 projectionMatrix;
+
+void main()
+{
+	vec4 p = viewMatrix * modelMatrix  * position;
+	gl_Position = projectionMatrix * p;
+}

+ 10 - 0
assets/default_mobile/default/UnlitUntexturedVertexColor.frag

@@ -0,0 +1,10 @@
+#ifdef GL_ES
+	precision mediump float;
+#endif
+
+uniform vec4 entityColor;
+varying vec4 varColor;
+
+void main() {
+	gl_FragColor = varColor * entityColor;
+}

+ 19 - 0
assets/default_mobile/default/UnlitUntexturedVertexColor.vert

@@ -0,0 +1,19 @@
+#ifdef GL_ES
+	precision mediump float;
+#endif
+
+attribute vec4 position;
+attribute vec4 color;
+
+uniform mat4 modelMatrix;
+uniform mat4 viewMatrix;
+uniform mat4 projectionMatrix;
+
+varying vec4 varColor;
+
+void main()
+{
+	vec4 p = viewMatrix * modelMatrix  * position;
+	gl_Position = projectionMatrix * p;
+	varColor = color;
+}

+ 9 - 0
assets/default_mobile/default/UnlitWireframe.frag

@@ -0,0 +1,9 @@
+#ifdef GL_ES
+	precision mediump float;
+#endif
+
+uniform vec4 wireframeColor;
+
+void main() {
+	gl_FragColor = wireframeColor;
+}

BIN
assets/default_mobile/default/default.entity2d


+ 148 - 0
assets/default_mobile/default/default.mat

@@ -0,0 +1,148 @@
+<?xml version="1.0" ?>
+<polycode>	
+	<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="DefaultShaderShadows" numPointLights="6" numSpotLights="2">
+			<vp source="default/DefaultShaderShadows.vert"/>
+			<fp source="default/DefaultShaderShadows.frag"/>
+		</shader>		
+		<shader type="glsl" name="DefaultUntexturedShader" numPointLights="6" numSpotLights="2">
+			<vp source="default/DefaultShader.vert"/>
+			<fp source="default/DefaultUntextured.frag"/>
+		</shader>		
+		<shader type="glsl" name="Unlit" numPointLights="0" numSpotLights="0">		
+			<vp source="default/Unlit.vert"/>
+			<fp source="default/Unlit.frag"/>
+		</shader>
+		<shader type="glsl" name="UnlitPointUntextured" numPointLights="0" numSpotLights="0">		
+			<vp source="default/UnlitPoint.vert"/>
+			<fp source="default/UnlitUntextured.frag"/>
+		</shader>
+		<shader type="glsl" name="UnlitUntextured" numPointLights="0" numSpotLights="0">		
+			<vp source="default/UnlitUntextured.vert"/>
+			<fp source="default/UnlitUntextured.frag"/>
+		</shader>
+		<shader type="glsl" name="UnlitUntexturedVertexColor" numPointLights="0" numSpotLights="0">		
+			<vp source="default/UnlitUntexturedVertexColor.vert"/>
+			<fp source="default/UnlitUntexturedVertexColor.frag"/>
+		</shader>		
+		<shader type="glsl" name="UnlitWireframe" numPointLights="0" numSpotLights="0">		
+			<vp source="default/UnlitUntextured.vert"/>
+			<fp source="default/UnlitWireframe.frag"/>
+		</shader>
+		<shader type="glsl" name="InvertShader" screen="true">		
+			<vp source="default/ScreenShader.vert"/>
+			<fp source="default/Invert.frag"/>
+		</shader>	
+		<shader type="glsl" name="BlurHShader" screen="true">		
+			<vp source="default/ScreenShader.vert"/>
+			<fp source="default/BlurH.frag"/>
+		</shader>
+		<shader type="glsl" name="BlurVShader" screen="true">		
+			<vp source="default/ScreenShader.vert"/>
+			<fp source="default/BlurV.frag"/>
+		</shader>
+		<shader type="glsl" name="LightcubePolar" numPointLights="0" numSpotLights="0">
+			<vp source="default/LightCube.vert"/>
+			<fp source="default/LightcubePolar.frag"/>
+		</shader>
+		<shader type="glsl" name="LightcubeAngular" numPointLights="0" numSpotLights="0">
+			<vp source="default/LightCube.vert"/>
+			<fp source="default/LightcubeAngular.frag"/>
+		</shader>		
+	</shaders>	
+	<materials>
+		<material name="Blur">
+			<rendertargets type="rgba">
+				<rendertarget id="blurtarget" sizeMode="pixels" width="512" height="512"/>
+			</rendertargets>		
+			<shader name="BlurHShader">
+				<targettextures>
+					<targettexture mode="color" name="screenTexture"/>
+					<targettexture mode="out" id="blurtarget"/>					
+				</targettextures>				
+			</shader>
+			<shader name="BlurVShader">
+				<targettextures>
+					<targettexture mode="in" name="screenTexture" id="blurtarget"/>
+				</targettextures>				
+			</shader>			
+		</material>	
+		<material name="Invert">
+			<shader name="InvertShader">
+				<targettextures>			
+					<targettexture mode="color" name="screenColorBuffer"/>				
+				</targettextures>				
+			</shader>
+		</material>		
+		<material name="Default">
+			<shader name="DefaultUntexturedShader">
+				<params>
+					<param name="entityColor" value="1.0 1.0 1.0 1.0" />
+					<param name="diffuse_color" value="1.0 1.0 1.0 1.0" />
+				</params>					
+			</shader>
+		</material>				
+		<material name="DefaultTextured">
+			<shader name="DefaultShader">
+				<params>
+					<param name="entityColor" value="1.0 1.0 1.0 1.0" />
+					<param name="diffuse_color" value="1.0 1.0 1.0 1.0" />
+				</params>					
+			</shader>
+		</material>
+		<material name="DefaultTexturedShadows">
+			<shader name="DefaultShaderShadows">
+				<params>
+					<param name="entityColor" value="1.0 1.0 1.0 1.0" />
+					<param name="diffuse_color" value="1.0 1.0 1.0 1.0" />
+				</params>					
+			</shader>
+		</material>	
+		<material name="Unlit">
+			<shader name="Unlit">
+				<params>
+					<param name="entityColor" value="1.0 1.0 1.0 1.0" />
+				</params>				
+			</shader>
+		</material>
+		<material name="UnlitAdditive" blendingMode="2">
+			<shader name="Unlit">
+				<params>
+					<param name="entityColor" value="1.0 1.0 1.0 1.0" />
+				</params>				
+			</shader>
+		</material>		
+		<material name="UnlitPointUntextured">
+			<shader name="UnlitPointUntextured">
+				<params>
+					<param name="entityColor" value="1.0 1.0 1.0 1.0" />
+				</params>					
+			</shader>
+		</material>		
+		<material name="UnlitUntextured">
+			<shader name="UnlitUntextured">
+				<params>
+					<param name="entityColor" value="1.0 1.0 1.0 1.0" />
+				</params>					
+			</shader>
+		</material>
+		<material name="UnlitUntexturedVertexColor">
+			<shader name="UnlitUntexturedVertexColor">
+				<params>
+					<param name="entityColor" value="1.0 1.0 1.0 1.0" />
+				</params>					
+			</shader>
+		</material>
+		<material name="UnlitWireframe">
+			<shader name="UnlitWireframe" wireframe="true">
+				<params>
+					<param name="entityColor" value="1.0 1.0 1.0 1.0" />
+				</params>					
+			</shader>
+		</material>				
+	</materials>
+</polycode>

BIN
assets/default_mobile/default/default.png


+ 7 - 0
assets/default_mobile/default/default.sprite

@@ -0,0 +1,7 @@
+<?xml version="1.0" ?>
+<sprite>
+    <image frameWidth="32" frameHeight="32" fileName="default/default.png" />
+    <animations>
+        <animation name="default" frames="0" speed="1.0" />
+    </animations>
+</sprite>

BIN
assets/default_mobile/default/default.wav


BIN
assets/default_mobile/default/mono.ttf


BIN
assets/default_mobile/default/sans.ttf


BIN
assets/default_mobile/default/serif.ttf


+ 1 - 1
lib

@@ -1 +1 @@
-Subproject commit cd559f0ccaef1d97e5b8555eef20b0724a54e71b
+Subproject commit c2936142a3596799a95909d6abc86cdeb24a4afd