Просмотр исходного кода

Rewrote default shaders, fixed light sorting code, fixed UV generation for cylinder, torus primitives, material properties in material files.

Ivan Safrin 14 лет назад
Родитель
Сommit
19cd891d7c
56 измененных файлов с 2136 добавлено и 2397 удалено
  1. BIN
      Assets/Default asset pack/default.pak
  2. 91 81
      Assets/Default asset pack/default/DefaultParticleShader.frag
  3. 0 11
      Assets/Default asset pack/default/DefaultParticleShader.vert
  4. 99 86
      Assets/Default asset pack/default/DefaultShader.frag
  5. 9 7
      Assets/Default asset pack/default/DefaultShader.vert
  6. 96 83
      Assets/Default asset pack/default/DefaultShaderNoTexture.frag
  7. 0 11
      Assets/Default asset pack/default/DefaultShaderNoTexture.vert
  8. 103 94
      Assets/Default asset pack/default/DefaultShaderShadows.frag
  9. 12 12
      Assets/Default asset pack/default/DefaultShaderShadows.vert
  10. 14 2
      Assets/Default asset pack/default/DefaultShaderVertex.frag
  11. 79 76
      Assets/Default asset pack/default/DefaultShaderVertex.vert
  12. 13 1
      Assets/Default asset pack/default/DefaultShaderVertexNoTexture.frag
  13. 0 100
      Assets/Default asset pack/default/DefaultShaderVertexNoTexture.vert
  14. 18 16
      Assets/Default asset pack/default/default.mat
  15. BIN
      Assets/Icon_base.psd
  16. BIN
      Assets/app_file_icon.icns
  17. BIN
      Assets/app_file_icon.png
  18. BIN
      Assets/file_icon_base.psd
  19. BIN
      Assets/main_icon.icns
  20. BIN
      Assets/main_icon.png
  21. BIN
      Assets/player_icon.icns
  22. BIN
      Assets/player_icon.png
  23. 198 153
      Core/Build/Mac OS X/PolyCore.xcodeproj/project.xcworkspace/xcuserdata/ivansafrin.xcuserdatad/UserInterfaceState.xcuserstate
  24. 11 0
      Core/Contents/Include/PolyCamera.h
  25. 1 1
      Core/Contents/Include/PolyGLSLShaderModule.h
  26. 0 81
      Core/Contents/Include/PolyGenericScene.h
  27. 4 0
      Core/Contents/Include/PolyMaterial.h
  28. 27 1
      Core/Contents/Include/PolyMesh.h
  29. 6 4
      Core/Contents/Include/PolyRenderer.h
  30. 5 0
      Core/Contents/Include/PolySceneEntity.h
  31. 59 2
      Core/Contents/Include/PolySceneLight.h
  32. 11 2
      Core/Contents/Include/PolyScenePrimitive.h
  33. 10 0
      Core/Contents/Include/PolyScreen.h
  34. 2 0
      Core/Contents/Include/PolyShader.h
  35. 9 2
      Core/Contents/Include/PolySound.h
  36. 9 2
      Core/Contents/Include/PolySoundManager.h
  37. 1 1
      Core/Contents/Source/PolyColor.cpp
  38. 3 3
      Core/Contents/Source/PolyEntity.cpp
  39. 20 1
      Core/Contents/Source/PolyGLRenderer.cpp
  40. 43 32
      Core/Contents/Source/PolyGLSLShaderModule.cpp
  41. 0 580
      Core/Contents/Source/PolyGenericScene.cpp
  42. 1 0
      Core/Contents/Source/PolyMaterial.cpp
  43. 29 1
      Core/Contents/Source/PolyMaterialManager.cpp
  44. 146 19
      Core/Contents/Source/PolyMesh.cpp
  45. 8 4
      Core/Contents/Source/PolyRenderer.cpp
  46. 10 3
      Core/Contents/Source/PolyScene.cpp
  47. 1 0
      Core/Contents/Source/PolySceneEntity.cpp
  48. 39 1
      Core/Contents/Source/PolySceneLight.cpp
  49. 13 1
      Core/Contents/Source/PolyScenePrimitive.cpp
  50. 7 0
      Core/Contents/Source/PolyShader.cpp
  51. 231 515
      Modules/Build/Mac OS X/Modules.xcodeproj/project.xcworkspace/xcuserdata/ivansafrin.xcuserdatad/UserInterfaceState.xcuserstate
  52. 7 0
      Modules/Contents/2DPhysics/Include/PolyPhysicsScreen.h
  53. 1 1
      Modules/Contents/2DPhysics/Source/PolyPhysicsScreen.cpp
  54. 0 20
      Player/Build/Mac OS X Standalone/StandalonePlayer/StandalonePlayer/StandalonePlayerAppDelegate.m
  55. 0 29
      Player/Build/Mac OS X Standalone/StandalonePlayer/StandalonePlayer/en.lproj/Credits.rtf
  56. 690 358
      Player/Build/Mac OS X/Polycode Player.xcodeproj/project.xcworkspace/xcuserdata/ivansafrin.xcuserdatad/UserInterfaceState.xcuserstate

BIN
Assets/Default asset pack/default.pak


+ 91 - 81
Assets/Default asset pack/default/DefaultParticleShader.frag

@@ -1,3 +1,8 @@
+varying vec3 normal;
+varying vec4 pos;
+varying vec4 vertexColor;
+uniform sampler2D diffuse;
+
 float calculateAttenuation(in int i, in float dist)
 {
     return(1.0 / (gl_LightSource[i].constantAttenuation +
@@ -5,99 +10,104 @@ float calculateAttenuation(in int i, in float dist)
                   gl_LightSource[i].quadraticAttenuation * dist * dist));
 }
 
-void pointLight(in int i, in vec3 N, in vec3 V, in float shininess,
-                inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
-{
-    vec3 D = gl_LightSource[i].position.xyz - V;
-    vec3 L = normalize(D);
-
-    float dist = length(D);
-    float attenuation = calculateAttenuation(i, dist);
+void pointLight(in int i, in vec3 normal, in vec4 pos, inout vec4 diffuse, inout vec4 specular) {
+	vec4 color = gl_FrontMaterial.diffuse;
+	vec4 matspec = gl_FrontMaterial.specular;
+	float shininess = gl_FrontMaterial.shininess;
+	vec4 lightspec = gl_LightSource[i].specular;
+	vec4 lpos = gl_LightSource[i].position;
+	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 = 1.0; //dot(N,L);
+	float nDotL = 1.0;
+		float dist = length(s);    
+		float attenuation = calculateAttenuation(i, dist);
 
-    if (nDotL > 0.0)
-    {   
-        vec3 E = normalize(-V);
-        vec3 R = reflect(-L, N);
-       
-        float pf = pow(max(dot(R,E), 0.0), shininess);
+		diffuse  += color * max(0.0, nDotL) * gl_LightSource[i].diffuse * attenuation;
 
-        diffuse  += gl_LightSource[i].diffuse  * attenuation * nDotL;
-        specular += gl_LightSource[i].specular * attenuation * pf;
-    }
-   
-    ambient  += gl_LightSource[i].ambient * attenuation;
+	  if (shininess != 0.0) {
+    	specular += lightspec * matspec * pow(max(0.0,dot(r, v)), shininess) * attenuation;
+	  }
 }
 
-void spotLight(in int i, in vec3 N, in vec3 V, in float shininess,
-               inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
-{
-    vec3 D = gl_LightSource[i].position.xyz - V;
-    vec3 L = normalize(D);
 
-    float dist = length(D);
-    float attenuation = calculateAttenuation(i, dist);
-	
-    float nDotL = dot(N,L);	
-    if (nDotL > 0.0)
-    {   
-        float spotEffect = dot(normalize(gl_LightSource[i].spotDirection), -L);
-       
-        if (spotEffect > gl_LightSource[i].spotCosCutoff)
-        {
-            attenuation *=  pow(spotEffect, gl_LightSource[i].spotExponent);
-
-            vec3 E = normalize(-V);
-            vec3 R = reflect(-L, N);
-       
-            float pf = pow(max(dot(R,E), 0.0), shininess);
-
-            diffuse  += gl_LightSource[i].diffuse  * attenuation * nDotL;
-            specular += gl_LightSource[i].specular * attenuation * pf;
-        }
-    }
-   
-    ambient  += gl_LightSource[i].ambient * attenuation;
-}
+void spotLight(in int i, in vec3 normal, in vec4 pos, inout vec4 diffuse, inout vec4 specular) {
+	vec4 color = gl_FrontMaterial.diffuse;
+	vec4 matspec = gl_FrontMaterial.specular;
+	float shininess = gl_FrontMaterial.shininess;
+	vec4 lightspec = gl_LightSource[i].specular;
+	vec4 lpos = gl_LightSource[i].position;
+	vec4 s = pos-lpos; 
+	vec4 sn = -normalize(s);
 
-void calculateLighting(in int numLights, in vec3 N, in vec3 V, in float shininess,
-                       inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
-{
-    // Just loop through each light, and if its enabled add
-    // its contributions to the color of the pixel.
-    for (int i = 0; i < numLights; i++)
-    {
-		if (gl_LightSource[i].spotCutoff == 180.0)
-                pointLight(i, N, V, shininess, ambient, diffuse, specular);
-            else
-                 spotLight(i, N, V, shininess, ambient, diffuse, specular);
+	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 = gl_LightSource[i].spotExponent;
+	float cos_cur_angle = dot(-normalize(gl_LightSource[i].spotDirection), sn.xyz);
+	float cos_inner_cone_angle = gl_LightSource[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 = 1.0;
+		float dist = length(s);    
+		float attenuation = calculateAttenuation(i, dist);
+		diffuse  += color * max(0.0, nDotL) * gl_LightSource[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 (gl_LightSource[i].spotCutoff == 180.0) {
+			pointLight(i, normal, pos, diffuse, specular);
+		} else {
+			spotLight(i, normal, pos, diffuse, specular);
+		}
     }
 }
 
-uniform sampler2D diffuse;
-varying vec3 normal;
-varying vec3 vertex;
-varying vec4 vertexColor;
 
 void main()
 {
-    vec3 n = normalize(normal);
-   
-    vec4 ambient_c  = vec4(0.0);
-    vec4 diffuse_c  = vec4(0.0);
-    vec4 specular_c = vec4(0.0);
-
-    calculateLighting(6, n, vertex, gl_FrontMaterial.shininess, ambient_c, diffuse_c, specular_c);
-   
-	vec4 texColor = texture2D(diffuse, gl_TexCoord[0].st);
+	vec4 diffuse_val  = vec4(0.0);
+	vec4 specular_val = vec4(0.0);
+	doLights(6, normal, pos, diffuse_val, specular_val);
+	diffuse_val.a = 1.0;
+	specular_val.a = 1.0;
+		
+	vec4 texColor = texture2D(diffuse, gl_TexCoord[0].st);		
+		
+    vec4 color = (diffuse_val  * 1.0) +
+                 (specular_val * 1.0)+
+                 gl_FrontMaterial.ambient;
+    color = clamp(color*vertexColor*texColor, 0.0, 1.0);
     
-    vec4 color = gl_FrontLightModelProduct.sceneColor  +
-                 (ambient_c  * 1.0) +
-                 (diffuse_c  * 1.0) +
-                 (specular_c * 1.0);
-	color.a = 1.0;
-    color = clamp(color*texColor*vertexColor, 0.0, 1.0);
-    gl_FragColor = color;
-}
+    // 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);
+	gl_FragColor = mix(gl_Fog.color, color, fogFactor );    
+
+}

+ 0 - 11
Assets/Default asset pack/default/DefaultParticleShader.vert

@@ -1,11 +0,0 @@
-varying vec3 normal;
-varying vec3 vertex;
-varying vec4 vertexColor;
-void main()
-{
-    gl_TexCoord[0] = gl_MultiTexCoord0;		
-    normal = normalize(gl_NormalMatrix * gl_Normal);   
-    vertex = vec3(gl_ModelViewMatrix * gl_Vertex);     
-    vertexColor = gl_Color;
-    gl_Position = ftransform();
-}

+ 99 - 86
Assets/Default asset pack/default/DefaultShader.frag

@@ -1,3 +1,8 @@
+varying vec3 normal;
+varying vec4 pos;
+varying vec4 vertexColor;
+uniform sampler2D diffuse;
+
 float calculateAttenuation(in int i, in float dist)
 {
     return(1.0 / (gl_LightSource[i].constantAttenuation +
@@ -5,100 +10,108 @@ float calculateAttenuation(in int i, in float dist)
                   gl_LightSource[i].quadraticAttenuation * dist * dist));
 }
 
-void pointLight(in int i, in vec3 N, in vec3 V, in float shininess,
-                inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
-{
-    vec3 D = gl_LightSource[i].position.xyz - V;
-    vec3 L = normalize(D);
-
-    float dist = length(D);
-    float attenuation = calculateAttenuation(i, dist);
-
-    float nDotL = dot(N,L);
-
-    if (nDotL > 0.0)
-    {   
-        vec3 E = normalize(-V);
-        vec3 R = reflect(-L, N);
-       
-        float pf = pow(max(dot(R,E), 0.0), shininess);
-
-        diffuse  += gl_LightSource[i].diffuse  * attenuation * nDotL;
-        specular += gl_LightSource[i].specular * attenuation * pf;
-    }
-   
-    ambient  += gl_LightSource[i].ambient * attenuation;
+void pointLight(in int i, in vec3 normal, in vec4 pos, inout vec4 diffuse, inout vec4 specular) {
+	vec4 color = gl_FrontMaterial.diffuse;
+	vec4 matspec = gl_FrontMaterial.specular;
+	float shininess = gl_FrontMaterial.shininess;
+	vec4 lightspec = gl_LightSource[i].specular;
+	vec4 lpos = gl_LightSource[i].position;
+	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) * gl_LightSource[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 N, in vec3 V, in float shininess,
-               inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
-{
-    vec3 D = gl_LightSource[i].position.xyz - V;
-    vec3 L = normalize(D);
-
-    float dist = length(D);
-    float attenuation = calculateAttenuation(i, dist);
-
-    float nDotL = dot(N,L);
-
-    if (nDotL > 0.0)
-    {   
-        float spotEffect = dot(normalize(gl_LightSource[i].spotDirection), -L);
-       
-        if (spotEffect > gl_LightSource[i].spotCosCutoff)
-        {
-            attenuation *=  pow(spotEffect, gl_LightSource[i].spotExponent);
-
-            vec3 E = normalize(-V);
-            vec3 R = reflect(-L, N);
-       
-            float pf = pow(max(dot(R,E), 0.0), shininess);
-
-            diffuse  += gl_LightSource[i].diffuse  * attenuation * nDotL;
-            specular += gl_LightSource[i].specular * attenuation * pf;
-        }
-    }
-   
-    ambient  += gl_LightSource[i].ambient * attenuation;
-}
 
-void calculateLighting(in int numLights, in vec3 N, in vec3 V, in float shininess,
-                       inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
-{
-    // Just loop through each light, and if its enabled add
-    // its contributions to the color of the pixel.
-    for (int i = 0; i < numLights; i++)
-    {
-		if (gl_LightSource[i].spotCutoff == 180.0)
-                pointLight(i, N, V, shininess, ambient, diffuse, specular);
-            else
-                 spotLight(i, N, V, shininess, ambient, diffuse, specular);
+void spotLight(in int i, in vec3 normal, in vec4 pos, inout vec4 diffuse, inout vec4 specular) {
+	vec4 color = gl_FrontMaterial.diffuse;
+	vec4 matspec = gl_FrontMaterial.specular;
+	float shininess = gl_FrontMaterial.shininess;
+	vec4 lightspec = gl_LightSource[i].specular;
+	vec4 lpos = gl_LightSource[i].position;
+	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 = gl_LightSource[i].spotExponent;
+	float cos_cur_angle = dot(-normalize(gl_LightSource[i].spotDirection), sn.xyz);
+	float cos_inner_cone_angle = gl_LightSource[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) * gl_LightSource[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 (gl_LightSource[i].spotCutoff == 180.0) {
+			pointLight(i, normal, pos, diffuse, specular);
+		} else {
+			spotLight(i, normal, pos, diffuse, specular);
+		}
     }
 }
 
-uniform sampler2D diffuse;
-varying vec3 normal;
-varying vec3 vertex;
-varying vec4 vertexColor;
 
 void main()
 {
-    vec3 n = normalize(normal);
-   
-    vec4 ambient_c  = vec4(0.0);
-    vec4 diffuse_c  = vec4(0.0);
-    vec4 specular_c = vec4(0.0);
-
-    calculateLighting(6, n, vertex, gl_FrontMaterial.shininess, ambient_c, diffuse_c, specular_c);
-   
-	vec4 texColor = texture2D(diffuse, gl_TexCoord[0].st);
+	vec4 diffuse_val  = vec4(0.0);
+	vec4 specular_val = vec4(0.0);
+	doLights(6, normal, pos, diffuse_val, specular_val);
+	diffuse_val.a = 1.0;
+	specular_val.a = 1.0;
+		
+	vec4 texColor = texture2D(diffuse, gl_TexCoord[0].st);		
+		
+    vec4 color = (diffuse_val  * 1.0) +
+                 (specular_val * 1.0)+
+                 gl_FrontMaterial.ambient;
+    color = clamp(color*vertexColor*texColor, 0.0, 1.0);
     
-    vec4 color = gl_FrontLightModelProduct.sceneColor  +
-                 (ambient_c  * 1.0) +
-                 (diffuse_c  * 1.0) +
-                 (specular_c * 1.0);
-	color.a = 1.0;				 
-    color = clamp(color*texColor*vertexColor, 0.0, 1.0);
-    gl_FragColor = color;
-}
+    // 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);
+	gl_FragColor = mix(gl_Fog.color, color, fogFactor );    
+
+}

+ 9 - 7
Assets/Default asset pack/default/DefaultShader.vert

@@ -1,11 +1,13 @@
 varying vec3 normal;
-varying vec3 vertex;
+varying vec4 pos;
+varying vec4 rawpos;
 varying vec4 vertexColor;
-void main()
-{
-    gl_TexCoord[0] = gl_MultiTexCoord0;		
-    normal = normalize(gl_NormalMatrix * gl_Normal);   
-    vertex = vec3(gl_ModelViewMatrix * gl_Vertex);     
+
+void main() {
+	normal = gl_NormalMatrix * gl_Normal;
+	gl_Position = ftransform();
+	pos = gl_ModelViewMatrix * gl_Vertex;
+	rawpos = gl_Vertex;
     vertexColor = gl_Color;
-    gl_Position = ftransform();
+	gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
 }

+ 96 - 83
Assets/Default asset pack/default/DefaultShaderNoTexture.frag

@@ -1,3 +1,7 @@
+varying vec3 normal;
+varying vec4 pos;
+varying vec4 vertexColor;
+
 float calculateAttenuation(in int i, in float dist)
 {
     return(1.0 / (gl_LightSource[i].constantAttenuation +
@@ -5,97 +9,106 @@ float calculateAttenuation(in int i, in float dist)
                   gl_LightSource[i].quadraticAttenuation * dist * dist));
 }
 
-void pointLight(in int i, in vec3 N, in vec3 V, in float shininess,
-                inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
-{
-    vec3 D = gl_LightSource[i].position.xyz - V;
-    vec3 L = normalize(D);
-
-    float dist = length(D);
-    float attenuation = calculateAttenuation(i, dist);
-
-    float nDotL = dot(N,L);
-
-    if (nDotL > 0.0)
-    {   
-        vec3 E = normalize(-V);
-        vec3 R = reflect(-L, N);
-       
-        float pf = pow(max(dot(R,E), 0.0), shininess);
-
-        diffuse  += gl_LightSource[i].diffuse  * attenuation * nDotL;
-        specular += gl_LightSource[i].specular * attenuation * pf;
-    }
-   
-    ambient  += gl_LightSource[i].ambient * attenuation;
+void pointLight(in int i, in vec3 normal, in vec4 pos, inout vec4 diffuse, inout vec4 specular) {
+	vec4 color = gl_FrontMaterial.diffuse;
+	vec4 matspec = gl_FrontMaterial.specular;
+	float shininess = gl_FrontMaterial.shininess;
+	vec4 lightspec = gl_LightSource[i].specular;
+	vec4 lpos = gl_LightSource[i].position;
+	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) * gl_LightSource[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 N, in vec3 V, in float shininess,
-               inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
-{
-    vec3 D = gl_LightSource[i].position.xyz - V;
-    vec3 L = normalize(D);
-
-    float dist = length(D);
-    float attenuation = calculateAttenuation(i, dist);
-
-    float nDotL = dot(N,L);
-
-    if (nDotL > 0.0)
-    {   
-        float spotEffect = dot(normalize(gl_LightSource[i].spotDirection), -L);
-       
-        if (spotEffect > gl_LightSource[i].spotCosCutoff)
-        {
-            attenuation *=  pow(spotEffect, gl_LightSource[i].spotExponent);
-
-            vec3 E = normalize(-V);
-            vec3 R = reflect(-L, N);
-       
-            float pf = pow(max(dot(R,E), 0.0), shininess);
-
-            diffuse  += gl_LightSource[i].diffuse  * attenuation * nDotL;
-            specular += gl_LightSource[i].specular * attenuation * pf;
-        }
-    }
-   
-    ambient  += gl_LightSource[i].ambient * attenuation;
-}
 
-void calculateLighting(in int numLights, in vec3 N, in vec3 V, in float shininess,
-                       inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
-{
-    // Just loop through each light, and if its enabled add
-    // its contributions to the color of the pixel.
-    for (int i = 0; i < numLights; i++)
-    {
-		if (gl_LightSource[i].spotCutoff == 180.0)
-                pointLight(i, N, V, shininess, ambient, diffuse, specular);
-            else
-                 spotLight(i, N, V, shininess, ambient, diffuse, specular);
+void spotLight(in int i, in vec3 normal, in vec4 pos, inout vec4 diffuse, inout vec4 specular) {
+	vec4 color = gl_FrontMaterial.diffuse;
+	vec4 matspec = gl_FrontMaterial.specular;
+	float shininess = gl_FrontMaterial.shininess;
+	vec4 lightspec = gl_LightSource[i].specular;
+	vec4 lpos = gl_LightSource[i].position;
+	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 = gl_LightSource[i].spotExponent;
+	float cos_cur_angle = dot(-normalize(gl_LightSource[i].spotDirection), sn.xyz);
+	float cos_inner_cone_angle = gl_LightSource[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) * gl_LightSource[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 (gl_LightSource[i].spotCutoff == 180.0) {
+			pointLight(i, normal, pos, diffuse, specular);
+		} else {
+			spotLight(i, normal, pos, diffuse, specular);
+		}
     }
 }
 
-varying vec3 normal;
-varying vec3 vertex;
-varying vec4 vertexColor;
 
 void main()
 {
-    vec3 n = normalize(normal);
-   
-    vec4 ambient_c  = vec4(0.0);
-    vec4 diffuse_c  = vec4(0.0);
-    vec4 specular_c = vec4(0.0);
-
-    calculateLighting(6, n, vertex, gl_FrontMaterial.shininess, ambient_c, diffuse_c, specular_c);
-    
-    vec4 color = gl_FrontLightModelProduct.sceneColor  +
-                 (ambient_c  * 1.0) +
-                 (diffuse_c  * 1.0) +
-                 (specular_c * 1.0);
+	vec4 diffuse_val  = vec4(0.0);
+	vec4 specular_val = vec4(0.0);
+	doLights(6, normal, pos, diffuse_val, specular_val);
+	diffuse_val.a = 1.0;
+	specular_val.a = 1.0;
+		
+    vec4 color = (diffuse_val  * 1.0) +
+                 (specular_val * 1.0)+
+                 gl_FrontMaterial.ambient;
     color = clamp(color*vertexColor, 0.0, 1.0);
-    color.a = vertexColor.a;
-    gl_FragColor = color;
-}
+    
+    // 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);
+	gl_FragColor = mix(gl_Fog.color, color, fogFactor );    
+
+}

+ 0 - 11
Assets/Default asset pack/default/DefaultShaderNoTexture.vert

@@ -1,11 +0,0 @@
-varying vec3 normal;
-varying vec3 vertex;
-varying vec4 vertexColor;
-void main()
-{
-    gl_TexCoord[0] = gl_MultiTexCoord0;		
-    normal = normalize(gl_NormalMatrix * gl_Normal);   
-    vertex = vec3(gl_ModelViewMatrix * gl_Vertex);     
-   vertexColor = gl_Color;
-    gl_Position = gl_ProjectionMatrix * vec4(vertex, 1.0);
-}

+ 103 - 94
Assets/Default asset pack/default/DefaultShaderShadows.frag

@@ -1,17 +1,15 @@
+varying vec3 normal;
+varying vec4 pos;
+varying vec4 vertexColor;
 uniform sampler2D diffuse;
 uniform sampler2D shadowMap0;
 uniform sampler2D shadowMap1;
-varying vec3 normal;
-varying vec3 vertex;
-varying vec4 vertexColor;
 varying vec4 ShadowCoord0;
 varying vec4 ShadowCoord1;
 uniform mat4 shadowMatrix0;
 uniform mat4 shadowMatrix1;
 
 
-
-
 float calculateAttenuation(in int i, in float dist)
 {
     return(1.0 / (gl_LightSource[i].constantAttenuation +
@@ -19,113 +17,124 @@ float calculateAttenuation(in int i, in float dist)
                   gl_LightSource[i].quadraticAttenuation * dist * dist));
 }
 
-void pointLight(in int i, in vec3 N, in vec3 V, in float shininess,
-                inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
-{
-    vec3 D = gl_LightSource[i].position.xyz - V;
-    vec3 L = normalize(D);
-
-    float dist = length(D);
-    float attenuation = calculateAttenuation(i, dist);
-
-    float nDotL = dot(N,L);
-
-    if (nDotL > 0.0)
-    {   
-        vec3 E = normalize(-V);
-        vec3 R = reflect(-L, N);
-       
-        float pf = pow(max(dot(R,E), 0.0), shininess);
-
-        diffuse  += gl_LightSource[i].diffuse  * attenuation * nDotL;
-        specular += gl_LightSource[i].specular * attenuation * pf;
-    }
-   
-    ambient  += gl_LightSource[i].ambient * attenuation;
+void pointLight(in int i, in vec3 normal, in vec4 pos, inout vec4 diffuse, inout vec4 specular) {
+	vec4 color = gl_FrontMaterial.diffuse;
+	vec4 matspec = gl_FrontMaterial.specular;
+	float shininess = gl_FrontMaterial.shininess;
+	vec4 lightspec = gl_LightSource[i].specular;
+	vec4 lpos = gl_LightSource[i].position;
+	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) * gl_LightSource[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 N, in vec3 V, in float shininess,
-               inout vec4 ambient, inout vec4 diffuse, inout vec4 specular, sampler2D shadowMap, vec4 ShadowCoord)
-{
+
+void spotLight(in int i, in vec3 normal, in vec4 pos, inout vec4 diffuse, inout vec4 specular, sampler2D shadowMap, vec4 ShadowCoord) {
 	
 	vec4 shadowCoordinateWdivide = ShadowCoord / ShadowCoord.w;
-	shadowCoordinateWdivide.z -= 0.000000005;
+	shadowCoordinateWdivide.z -= 0.000005;
 	float distanceFromLight = texture2D(shadowMap,shadowCoordinateWdivide.st).z;
 	float shadow = 1.0;
-	if (ShadowCoord.w > 0.0)
+	if (shadowCoordinateWdivide.x > 0.01 && shadowCoordinateWdivide.y > 0.01 && shadowCoordinateWdivide.x < 0.99 && shadowCoordinateWdivide.y < 0.99)
 		shadow = distanceFromLight < shadowCoordinateWdivide.z ? 0.0 : 1.0 ;
 	
-    vec3 D = gl_LightSource[i].position.xyz - V;
-    vec3 L = normalize(D);
-
-    float dist = length(D);
-    float attenuation = calculateAttenuation(i, dist);
-
-    float nDotL = dot(N,L);
-
-    if (nDotL > 0.0)
-    {   
-        float spotEffect = dot(normalize(gl_LightSource[i].spotDirection), -L);
-       
-        if (spotEffect > gl_LightSource[i].spotCosCutoff)
-        {
-            attenuation *=  pow(spotEffect, gl_LightSource[i].spotExponent);
-
-            vec3 E = normalize(-V);
-            vec3 R = reflect(-L, N);
-       
-            float pf = pow(max(dot(R,E), 0.0), shininess);
-
-            diffuse  += gl_LightSource[i].diffuse  * attenuation * nDotL * shadow;
-            specular += gl_LightSource[i].specular * attenuation * pf * shadow;
-        }
-    }
-   
-    ambient  += gl_LightSource[i].ambient * attenuation;
+	vec4 color = gl_FrontMaterial.diffuse;
+	vec4 matspec = gl_FrontMaterial.specular;
+	float shininess = gl_FrontMaterial.shininess;
+	vec4 lightspec = gl_LightSource[i].specular;
+	vec4 lpos = gl_LightSource[i].position;
+	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 = gl_LightSource[i].spotExponent;
+	float cos_cur_angle = dot(-normalize(gl_LightSource[i].spotDirection), sn.xyz);
+	float cos_inner_cone_angle = gl_LightSource[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) * gl_LightSource[i].diffuse * attenuation * spot * shadow;
+
+	  if (shininess != 0.0) {
+    	specular += lightspec * matspec * pow(max(0.0,dot(r, v)), shininess) * attenuation * spot * shadow;
+	  }
+	}
 }
 
-void calculateLighting(in int numLights, in vec3 N, in vec3 V, in float shininess,
-                       inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
-{
-	int spot = 0;
-    // Just loop through each light, and if its enabled add
-    // its contributions to the color of the pixel.
+void doLights(in int numLights, in vec3 normal, in vec4 pos, inout vec4 diffuse, inout vec4 specular) {    
+   	int spot = 0;
     for (int i = 0; i < numLights; i++)
     {
-		if (gl_LightSource[i].spotCutoff == 180.0)
-                pointLight(i, N, V, shininess, ambient, diffuse, specular);
-            else {
+		if (gl_LightSource[i].spotCutoff == 180.0) {
+				pointLight(i, normal, pos, diffuse, specular);
+		}  else {
             	if(spot == 0) {
-                 spotLight(i, N, V, shininess, ambient, diffuse, specular, shadowMap0, ShadowCoord0);            		
-                 spot = 1;
+					spotLight(i, normal, pos, diffuse, specular,shadowMap0, ShadowCoord0);            		                 
+					spot = 1;
             	} else {
-                 spotLight(i, N, V, shininess, ambient, diffuse, specular, shadowMap1, ShadowCoord1);
+					spotLight(i, normal, pos, diffuse, specular,shadowMap1, ShadowCoord1);            		
             	}
-            }
-
-    }
+        }
+    } 
+    
 }
 
 
-
 void main()
 {
-  vec3 n = normalize(normal);
-   
-    vec4 ambient_c  = vec4(0.0);
-    vec4 diffuse_c  = vec4(0.0);
-    vec4 specular_c = vec4(0.0);
-
-    calculateLighting(6, n, vertex, gl_FrontMaterial.shininess, ambient_c, diffuse_c, specular_c);
-   
-	vec4 texColor = texture2D(diffuse, gl_TexCoord[0].st);
+	vec4 diffuse_val  = vec4(0.0);
+	vec4 specular_val = vec4(0.0);
+	doLights(6, normal, pos, diffuse_val, specular_val);
+	diffuse_val.a = 1.0;
+	specular_val.a = 1.0;
+		
+	vec4 texColor = texture2D(diffuse, gl_TexCoord[0].st);		
+		
+    vec4 color = (diffuse_val  * 1.0) +
+                 (specular_val * 1.0)+
+                 gl_FrontMaterial.ambient;
+    color = clamp(color*vertexColor*texColor, 0.0, 1.0);
     
-    vec4 color = gl_FrontLightModelProduct.sceneColor  +
-                 (ambient_c  * 1.0) +
-                 (diffuse_c  * 1.0) +
-                 (specular_c * 1.0);
-	color.a = 1.0;				 
-    color = clamp(color*texColor*vertexColor, 0.0, 1.0);
-    gl_FragColor = color;
-
-}
+    // 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);
+	gl_FragColor = mix(gl_Fog.color, color, fogFactor );    
+
+}

+ 12 - 12
Assets/Default asset pack/default/DefaultShaderShadows.vert

@@ -1,22 +1,22 @@
 varying vec3 normal;
-varying vec3 vertex;
+varying vec4 pos;
+varying vec4 rawpos;
 varying vec4 vertexColor;
 varying vec4 ShadowCoord0;
 varying vec4 ShadowCoord1;
 uniform mat4 shadowMatrix0;
 uniform mat4 shadowMatrix1;
 
-void main()
-{
-    gl_TexCoord[0] = gl_MultiTexCoord0;		
-    normal = normalize(gl_NormalMatrix * gl_Normal);   
-    vec4 v = gl_ModelViewMatrix * gl_Vertex;
-    vertex = vec3(v);     
-    
+
+void main() {
+	normal = gl_NormalMatrix * gl_Normal;
+	gl_Position = ftransform();
+	pos = gl_ModelViewMatrix * gl_Vertex;
+	rawpos = gl_Vertex;
+	
 	ShadowCoord0 = shadowMatrix0 * gl_Vertex;	
-	ShadowCoord1 = shadowMatrix1 * gl_Vertex;	
-		    
-    
+	ShadowCoord1 = shadowMatrix1 * gl_Vertex;		
+	
     vertexColor = gl_Color;
-    gl_Position = ftransform();
+	gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
 }

+ 14 - 2
Assets/Default asset pack/default/DefaultShaderVertex.frag

@@ -4,6 +4,18 @@ varying vec4 vertexColor;
 void main()
 {
 	vec4 texColor = texture2D(diffuse, gl_TexCoord[0].st);	
-    vec4 color = texColor*vertexColor;
-    gl_FragColor = color;
+    vec4 color = texColor*vertexColor;    
+    
+    // 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);
+	gl_FragColor = mix(gl_Fog.color, color, fogFactor );        
+    
 }

+ 79 - 76
Assets/Default asset pack/default/DefaultShaderVertex.vert

@@ -5,97 +5,100 @@ float calculateAttenuation(in int i, in float dist)
                   gl_LightSource[i].quadraticAttenuation * dist * dist));
 }
 
-void pointLight(in int i, in vec3 N, in vec3 V, in float shininess,
-                inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
-{
-    vec3 D = gl_LightSource[i].position.xyz - V;
-    vec3 L = normalize(D);
-
-    float dist = length(D);
-    float attenuation = calculateAttenuation(i, dist);
+void pointLight(in int i, in vec3 normal, in vec4 pos, inout vec4 diffuse, inout vec4 specular) {
+	vec4 color = gl_FrontMaterial.diffuse;
+	vec4 matspec = gl_FrontMaterial.specular;
+	float shininess = gl_FrontMaterial.shininess;
+	vec4 lightspec = gl_LightSource[i].specular;
+	vec4 lpos = gl_LightSource[i].position;
+	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,L);
+	float nDotL = dot(n, sn.xyz);
+	if(nDotL > 0.0) {
+		float dist = length(s);    
+		float attenuation = calculateAttenuation(i, dist);
 
-    if (nDotL > 0.0)
-    {   
-        vec3 E = normalize(-V);
-        vec3 R = reflect(-L, N);
-       
-        float pf = pow(max(dot(R,E), 0.0), shininess);
+		diffuse  += color * max(0.0, nDotL) * gl_LightSource[i].diffuse * attenuation;
 
-        diffuse  += gl_LightSource[i].diffuse  * attenuation * nDotL;
-        specular += gl_LightSource[i].specular * attenuation * pf;
-    }
-   
-    ambient  += gl_LightSource[i].ambient * attenuation;
+	  if (shininess != 0.0) {
+    	specular += lightspec * matspec * pow(max(0.0,dot(r, v)), shininess) * attenuation;
+	  }
+	}
 }
 
-void spotLight(in int i, in vec3 N, in vec3 V, in float shininess,
-               inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
-{
-    vec3 D = gl_LightSource[i].position.xyz - V;
-    vec3 L = normalize(D);
 
-    float dist = length(D);
-    float attenuation = calculateAttenuation(i, dist);
+void spotLight(in int i, in vec3 normal, in vec4 pos, inout vec4 diffuse, inout vec4 specular) {
+	vec4 color = gl_FrontMaterial.diffuse;
+	vec4 matspec = gl_FrontMaterial.specular;
+	float shininess = gl_FrontMaterial.shininess;
+	vec4 lightspec = gl_LightSource[i].specular;
+	vec4 lpos = gl_LightSource[i].position;
+	vec4 s = pos-lpos; 
+	vec4 sn = -normalize(s);
 
-    float nDotL = dot(N,L);
+	vec3 light = sn.xyz;
+	vec3 n = normalize(normal);
+	vec3 r = -reflect(light, n);
+	r = normalize(r);
+	vec3 v = -pos.xyz;
+	v = normalize(v);
 
-    if (nDotL > 0.0)
-    {   
-        float spotEffect = dot(normalize(gl_LightSource[i].spotDirection), -L);
-       
-        if (spotEffect > gl_LightSource[i].spotCosCutoff)
-        {
-            attenuation *=  pow(spotEffect, gl_LightSource[i].spotExponent);
+	float cos_outer_cone_angle = gl_LightSource[i].spotExponent;
+	float cos_cur_angle = dot(-normalize(gl_LightSource[i].spotDirection), sn.xyz);
+	float cos_inner_cone_angle = gl_LightSource[i].spotCosCutoff;
 
-            vec3 E = normalize(-V);
-            vec3 R = reflect(-L, N);
-       
-            float pf = pow(max(dot(R,E), 0.0), shininess);
+	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) * gl_LightSource[i].diffuse * attenuation * spot;
 
-            diffuse  += gl_LightSource[i].diffuse  * attenuation * nDotL;
-            specular += gl_LightSource[i].specular * attenuation * pf;
-        }
-    }
-   
-    ambient  += gl_LightSource[i].ambient * attenuation;
+	  if (shininess != 0.0) {
+    	specular += lightspec * matspec * pow(max(0.0,dot(r, v)), shininess) * attenuation * spot;
+	  }
+	}
 }
 
-void calculateLighting(in int numLights, in vec3 N, in vec3 V, in float shininess,
-                       inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
-{
-    // Just loop through each light, and if its enabled add
-    // its contributions to the color of the pixel.
-    for (int i = 0; i < numLights; i++)
-    {
-		if (gl_LightSource[i].spotCutoff == 180.0)
-                pointLight(i, N, V, shininess, ambient, diffuse, specular);
-            else
-                 spotLight(i, N, V, shininess, ambient, diffuse, specular);
-
+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 (gl_LightSource[i].spotCutoff == 180.0) {
+			pointLight(i, normal, pos, diffuse, specular);
+		} else {
+			spotLight(i, normal, pos, diffuse, specular);
+		}
     }
 }
 
 varying vec4 vertexColor;
-void main()
-{
 
-    gl_TexCoord[0] = gl_MultiTexCoord0;		
-    vec3 normal = normalize(gl_NormalMatrix * gl_Normal);   
-    vec3 vertex = vec3(gl_ModelViewMatrix * gl_Vertex);     
-    gl_Position = ftransform();    
-   
-    vec4 ambient_c  = vec4(0.0);
-    vec4 diffuse_c  = vec4(0.0);
-    vec4 specular_c = vec4(0.0);
-    
-    calculateLighting(6, normal, vertex, gl_FrontMaterial.shininess, ambient_c, diffuse_c, specular_c);   
-    vec4 color = gl_FrontLightModelProduct.sceneColor  +
-                 (ambient_c  * 1.0) +
-                 (diffuse_c  * 1.0) +
-                 (specular_c * 1.0);
-	color.a = 1.0;				 
-    color = clamp(color*gl_Color, 0.0, 1.0);
-   vertexColor = color;    
+void main() {
+	vec3 normal = gl_NormalMatrix * gl_Normal;
+	gl_Position = ftransform();
+	vec4 pos = gl_ModelViewMatrix * gl_Vertex;
+	vec4 rawpos = gl_Vertex;
+    vertexColor = gl_Color;
+	gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
+	
+	vec4 diffuse_val  = vec4(0.0);
+	vec4 specular_val = vec4(0.0);
+	doLights(6, normal, pos, diffuse_val, specular_val);
+	diffuse_val.a = 1.0;
+	specular_val.a = 1.0;		
+		
+    vec4 color = (diffuse_val  * 1.0) +
+                 (specular_val * 1.0)+
+                 gl_FrontMaterial.ambient;
+    vertexColor = clamp(color*vertexColor, 0.0, 1.0);  	
 }

+ 13 - 1
Assets/Default asset pack/default/DefaultShaderVertexNoTexture.frag

@@ -4,5 +4,17 @@ varying vec4 vertexColor;
 void main()
 {
     vec4 color = vertexColor;
-    gl_FragColor = color;
+    
+    // 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);
+	gl_FragColor = mix(gl_Fog.color, color, fogFactor );    	 
+    
 }

+ 0 - 100
Assets/Default asset pack/default/DefaultShaderVertexNoTexture.vert

@@ -1,100 +0,0 @@
-float calculateAttenuation(in int i, in float dist)
-{
-    return(1.0 / (gl_LightSource[i].constantAttenuation +
-                  gl_LightSource[i].linearAttenuation * dist +
-                  gl_LightSource[i].quadraticAttenuation * dist * dist));
-}
-
-void pointLight(in int i, in vec3 N, in vec3 V, in float shininess,
-                inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
-{
-    vec3 D = gl_LightSource[i].position.xyz - V;
-    vec3 L = normalize(D);
-
-    float dist = length(D);
-    float attenuation = calculateAttenuation(i, dist);
-
-    float nDotL = dot(N,L);
-
-    if (nDotL > 0.0)
-    {   
-        vec3 E = normalize(-V);
-        vec3 R = reflect(-L, N);
-       
-        float pf = pow(max(dot(R,E), 0.0), shininess);
-
-        diffuse  += gl_LightSource[i].diffuse  * attenuation * nDotL;
-        specular += gl_LightSource[i].specular * attenuation * pf;
-    }
-   
-    ambient  += gl_LightSource[i].ambient * attenuation;
-}
-
-void spotLight(in int i, in vec3 N, in vec3 V, in float shininess,
-               inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
-{
-    vec3 D = gl_LightSource[i].position.xyz - V;
-    vec3 L = normalize(D);
-
-    float dist = length(D);
-    float attenuation = calculateAttenuation(i, dist);
-
-    float nDotL = dot(N,L);
-
-    if (nDotL > 0.0)
-    {   
-        float spotEffect = dot(normalize(gl_LightSource[i].spotDirection), -L);
-       
-        if (spotEffect > gl_LightSource[i].spotCosCutoff)
-        {
-            attenuation *=  pow(spotEffect, gl_LightSource[i].spotExponent);
-
-            vec3 E = normalize(-V);
-            vec3 R = reflect(-L, N);
-       
-            float pf = pow(max(dot(R,E), 0.0), shininess);
-
-            diffuse  += gl_LightSource[i].diffuse  * attenuation * nDotL;
-            specular += gl_LightSource[i].specular * attenuation * pf;
-        }
-    }
-   
-    ambient  += gl_LightSource[i].ambient * attenuation;
-}
-
-void calculateLighting(in int numLights, in vec3 N, in vec3 V, in float shininess,
-                       inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
-{
-    // Just loop through each light, and if its enabled add
-    // its contributions to the color of the pixel.
-    for (int i = 0; i < numLights; i++)
-    {
-		if (gl_LightSource[i].spotCutoff == 180.0)
-                pointLight(i, N, V, shininess, ambient, diffuse, specular);
-            else
-                 spotLight(i, N, V, shininess, ambient, diffuse, specular);
-
-    }
-}
-
-varying vec4 vertexColor;
-void main()
-{
-
-    gl_TexCoord[0] = gl_MultiTexCoord0;		
-    vec3 normal = normalize(gl_NormalMatrix * gl_Normal);   
-    vec3 vertex = vec3(gl_ModelViewMatrix * gl_Vertex);     
-    gl_Position = ftransform();    
-   
-    vec4 ambient_c  = vec4(0.0);
-    vec4 diffuse_c  = vec4(0.0);
-    vec4 specular_c = vec4(0.0);
-    
-    calculateLighting(6, normal, vertex, gl_FrontMaterial.shininess, ambient_c, diffuse_c, specular_c);   
-    vec4 color = gl_FrontLightModelProduct.sceneColor  +
-                 (ambient_c  * 1.0) +
-                 (diffuse_c  * 1.0) +
-                 (specular_c * 1.0);
-    color = clamp(color*gl_Color, 0.0, 1.0);
-   vertexColor = color;    
-}

+ 18 - 16
Assets/Default asset pack/default/default.mat

@@ -12,7 +12,7 @@
 			</fp>
 		</shader>	
 		<shader type="glsl" name="DefaultShaderNoTexture" numAreaLights="4" numSpotLights="2">		
-			<vp source="DefaultShaderNoTexture.vert">
+			<vp source="DefaultShader.vert">
 				<params>			
 				</params>				
 			</vp>
@@ -20,39 +20,41 @@
 				<params>			
 				</params>				
 			</fp>
-		</shader>		
-		<shader type="glsl" name="DefaultShaderVertex" numAreaLights="4" numSpotLights="2">		
-			<vp source="DefaultShaderVertex.vert">
+		</shader>
+		<shader type="glsl" name="DefaultShaderShadows" numAreaLights="4" numSpotLights="2">		
+			<vp source="DefaultShaderShadows.vert">
 				<params>			
 				</params>				
 			</vp>
-			<fp source="DefaultShaderVertex.frag">
+			<fp source="DefaultShaderShadows.frag">
 				<params>			
 				</params>				
 			</fp>
-		</shader>			
-		<shader type="glsl" name="DefaultShaderVertexNoTexture" numAreaLights="4" numSpotLights="2">		
-			<vp source="DefaultShaderVertexNoTexture.vert">
+		</shader>
+		
+		<shader type="glsl" name="DefaultShaderVertex" numAreaLights="4" numSpotLights="2">		
+			<vp source="DefaultShaderVertex.vert">
 				<params>			
 				</params>				
 			</vp>
-			<fp source="DefaultShaderVertexNoTexture.frag">
+			<fp source="DefaultShaderVertex.frag">
 				<params>			
 				</params>				
 			</fp>
 		</shader>			
-		<shader type="glsl" name="DefaultShaderShadows" numAreaLights="4" numSpotLights="2">		
-			<vp source="DefaultShaderShadows.vert">
+		<shader type="glsl" name="DefaultShaderVertexNoTexture" numAreaLights="4" numSpotLights="2">		
+			<vp source="DefaultShaderVertex.vert">
 				<params>			
 				</params>				
 			</vp>
-			<fp source="DefaultShaderShadows.frag">
+			<fp source="DefaultShaderVertexNoTexture.frag">
 				<params>			
 				</params>				
 			</fp>
-		</shader>	
+		</shader>			
+		
 		<shader type="glsl" name="DefaultParticleShader" numAreaLights="4" numSpotLights="2">		
-			<vp source="DefaultParticleShader.vert">
+			<vp source="DefaultShader.vert">
 				<params>			
 				</params>				
 			</vp>
@@ -60,7 +62,7 @@
 				<params>			
 				</params>				
 			</fp>
-		</shader>	
+		</shader>															
 		<shader type="glsl" name="Unlit" numAreaLights="0" numSpotLights="0">		
 			<vp source="Unlit.vert">
 				<params>			
@@ -71,7 +73,7 @@
 				</params>				
 			</fp>
 		</shader>										
-	</shaders>
+	</shaders>	
 	<materials>
 		<material name="Default">
 			<shader name="DefaultShaderNoTexture">

BIN
Assets/Icon_base.psd


BIN
Assets/app_file_icon.icns


BIN
Assets/app_file_icon.png


BIN
Assets/file_icon_base.psd


BIN
Assets/main_icon.icns


BIN
Assets/main_icon.png


BIN
Assets/player_icon.icns


BIN
Assets/player_icon.png


Разница между файлами не показана из-за своего большого размера
+ 198 - 153
Core/Build/Mac OS X/PolyCore.xcodeproj/project.xcworkspace/xcuserdata/ivansafrin.xcuserdatad/UserInterfaceState.xcuserstate


+ 11 - 0
Core/Contents/Include/PolyCamera.h

@@ -111,6 +111,17 @@ namespace Polycode {
 			*/
 			void removePostFilter();
 			
+			/**
+			* Returns the local shader options for the camera post processing material.
+			*/
+			vector<ShaderBinding*> getLocalShaderOptions() { return localShaderOptions; }
+			
+			/**
+			* Returns the shader material applied to the camera.
+			*/			
+			Material *getScreenShaderMaterial() { return filterShaderMaterial; }
+			
+			
 		private:
 		
 			Number exposureLevel;

+ 1 - 1
Core/Contents/Include/PolyGLSLShaderModule.h

@@ -64,7 +64,7 @@ namespace Polycode {
 		void addParamToProgram(GLSLProgram *program,TiXmlNode *node);		
 		void recreateGLSLProgram(GLSLProgram *prog, String fileName, int type);
 		GLSLProgram *createGLSLProgram(String fileName, int type);		
-		void updateGLSLParam(Renderer *renderer, GLSLProgramParam &param, ShaderBinding *materialOptions, ShaderBinding *localOptions);		
+		void updateGLSLParam(Renderer *renderer, GLSLShader *glslShader, GLSLProgramParam &param, ShaderBinding *materialOptions, ShaderBinding *localOptions);		
 			
 		void setGLSLAreaLightPositionParameter(Renderer *renderer, GLSLProgramParam &param, int lightIndex);
 		void setGLSLAreaLightColorParameter(Renderer *renderer, GLSLProgramParam &param, int lightIndex);	

+ 0 - 81
Core/Contents/Include/PolyGenericScene.h

@@ -1,81 +0,0 @@
-/*
- *  PolyGenericScene.h
- *  Poly
- *
- *  Created by Ivan Safrin on 3/18/08.
- *  Copyright 2008 Ivan Safrin. All rights reserved.
- *
- */
-// @package Scene
- 
-#pragma once
-#include "PolyString.h"
-#include "PolyLogger.h"
-#include "PolyGlobals.h"
-#include <vector>
-#include "PolyScene.h"
-#include "PolySceneMesh.h"
-#include "PolyScenePrimitive.h"
-#include "OSBasics.h"
-
-using std::vector;
-
-namespace Polycode {
-	
-	class _PolyExport GenericScene : public Scene {
-		public:
-			GenericScene();
-			GenericScene(bool virtualScene);
-		
-			virtual ~GenericScene();
-			
-			void Render();
-			void RenderDepthOnly(Camera *targetCamera);
-			void addGrid(String gridTexture);
-	
-			static String readString(OSFILE *inFile);
-			void loadScene(String fileName);
-			void generateLightmaps(Number lightMapRes, Number lightMapQuality, int numRadPasses);
-
-			void addLight(SceneLight *light);
-			SceneLight *getNearestLight(Vector3 pos);
-			
-			void writeEntityMatrix(SceneEntity *entity, OSFILE *outFile);
-			void writeString(String str, OSFILE *outFile);
-			void saveScene(String fileName);
-	
-			int getNumStaticGeometry();
-			SceneMesh *getStaticGeometry(int index);
-			
-			virtual void loadCollisionChild(SceneEntity *entity, bool autoCollide=false, int type=0){}
-			
-			int getNumLights();
-			SceneLight *getLight(int index);
-			
-			SceneEntity *getCustomEntityByType(String type);
-			vector<SceneEntity*> getCustomEntitiesByType(String type);		
-			
-			static const unsigned int ENTITY_MESH = 0;
-			static const unsigned int ENTITY_LIGHT = 1;			
-			static const unsigned int ENTITY_CAMERA = 2;			
-			static const unsigned int ENTITY_ENTITY = 3;
-			static const unsigned int ENTITY_COLLMESH = 4;
-
-			Color clearColor;
-			Color ambientColor;		
-			Color fogColor;				
-		
-		private:
-		
-			bool useClearColor;
-			bool virtualScene;
-			bool hasLightmaps;
-//			LightmapPacker *packer;
-			
-			vector <SceneLight*> lights;				
-			vector <SceneMesh*> staticGeometry;
-			vector <SceneMesh*> collisionGeometry;
-			vector <SceneEntity*> customEntities;
-	};
-
-}

+ 4 - 0
Core/Contents/Include/PolyMaterial.h

@@ -52,6 +52,10 @@ namespace Polycode {
 			ShaderBinding *getShaderBinding(unsigned int index);
 			void loadMaterial(String fileName);
 			
+			Number specularValue;
+			Color specularColor;
+			Color diffuseColor;
+						
 		protected:
 		
 			vector<Shader*> materialShaders;

+ 27 - 1
Core/Contents/Include/PolyMesh.h

@@ -34,6 +34,12 @@ using namespace std;
  
 namespace Polycode {
 	
+	class _PolyExport VertexSorter {
+		public:
+			Vertex *target;
+			bool operator() (Vertex *v1,Vertex *v2) { return (v1->distance(*target)<v2->distance(*target));}
+	};	
+	
 	class _PolyExport VertexBuffer {
 		public:	
 			VertexBuffer(){}
@@ -168,6 +174,22 @@ namespace Polycode {
 			*/ 
 			void createPlane(Number w, Number h);
 			
+			/**
+			* Creates a vertical plane mesh of specified size.
+			* @param w Width of plane.
+			* @param h Depth of plane.			
+			*/ 
+			void createVPlane(Number w, Number h);
+
+			/**
+			* Creates a torus.
+			* @param radius Radius of the torus.
+			* @param tubeRadius Radious of the tube.
+			* @param rSegments Number of radial segments.
+			* @param tSegments Number of tube segments.
+			*/ 	
+			void createTorus(Number radius, Number tubeRadius, int rSegments, int tSegments);
+			
 			/**
 			* Creates a cube mesh of specified size.
 			* @param w Width of cube.
@@ -232,8 +254,12 @@ namespace Polycode {
 			
 			/**
 			* Recalculates the mesh normals (flat normals only).
+			* @param smooth If true, will use smooth normals.
+			* @param smoothAngle If smooth, this parameter sets the angle tolerance for the approximation function.
 			*/
-			void calculateNormals();	
+			void calculateNormals(bool smooth=true, Number smoothAngle=90.0);	
+			
+			vector<Polygon*> getConnectedFaces(Vertex *v);
 			
 			/**
 			* Returns the mesh type.

+ 6 - 4
Core/Contents/Include/PolyRenderer.h

@@ -42,6 +42,7 @@ namespace Polycode {
 		public:
 			Vector3 position;
 			Vector3 color;
+			Color specularColor;
 			Vector3 dir;
 			Number constantAttenuation;
 			Number linearAttenuation;
@@ -52,6 +53,7 @@ namespace Polycode {
 			int type;
 			bool shadowsEnabled;
 			Matrix4 textureMatrix;
+			Texture* shadowMapTexture;
 	};
 
 	class _PolyExport LightSorter {
@@ -173,7 +175,7 @@ namespace Polycode {
 		virtual void cullFrontFaces(bool val) = 0;
 		
 		void clearLights();
-		void addLight(Vector3 position, Vector3 direction, int type, Color color, Number constantAttenuation, Number linearAttenuation, Number quadraticAttenuation, Number intensity, Number spotlightCutoff, Number spotlightExponent, bool shadowsEnabled, Matrix4 *textureMatrix);
+		void addLight(Vector3 position, Vector3 direction, int type, Color color, Color specularColor, Number constantAttenuation, Number linearAttenuation, Number quadraticAttenuation, Number intensity, Number spotlightCutoff, Number spotlightExponent, bool shadowsEnabled, Matrix4 *textureMatrix, Texture *shadowMapTexture);
 		
 		void setExposureLevel(Number level);
 		
@@ -207,8 +209,8 @@ namespace Polycode {
 		static const int TEX_FILTERING_NEAREST = 0;
 		static const int TEX_FILTERING_LINEAR = 1;
 		
-		void addShadowMap(Texture *texture);
-		vector<Texture*> getShadowMapTextures(){ return shadowMapTextures; };
+//		void addShadowMap(Texture *texture);
+//		vector<Texture*> getShadowMapTextures(){ return shadowMapTextures; };
 		
 		virtual Vector3 Unproject(Number x, Number y) = 0;
 		
@@ -233,7 +235,7 @@ namespace Polycode {
 		Texture *currentTexture;
 		Material *currentMaterial;
 		
-		vector<Texture*> shadowMapTextures;
+//		vector<Texture*> shadowMapTextures;
 		
 		Texture *currentFrameBufferTexture;
 		Texture *previousFrameBufferTexture;

+ 5 - 0
Core/Contents/Include/PolySceneEntity.h

@@ -53,6 +53,11 @@ namespace Polycode {
 			*/
 			virtual bool testMouseCollision(Number x, Number y) { return false;}
 			
+			/**
+			* If set to true, will cast shadows (Defaults to true).
+			*/
+			bool castShadows;
+			
 		protected:
 
 	};

+ 59 - 2
Core/Contents/Include/PolySceneLight.h

@@ -29,11 +29,13 @@ THE SOFTWARE.
 #include "PolyScene.h"
 #include "PolyCamera.h"
 #include "PolyMesh.h"
+//#include "PolyScenePrimitive.h"
 
 namespace Polycode {
 
 	class Scene;
 	class Camera;
+//	class ScenePrimitive;
 	
 	/**
 	* 3D light source. Lights can be area or spot lights and can be set to different colors. 
@@ -57,6 +59,21 @@ namespace Polycode {
 			* Returns the light's intensity.
 			*/
 			Number getIntensity();
+
+			/**
+			* Sets the light's intensity
+			* @param newIntensity New intensity value.
+			*/
+			void setIntensity(Number newIntensity);
+						
+			/**
+			* Sets the attenuation values for the light.
+			* @param constantAttenuation Constant falloff attenuation value	
+			* @param linearAttenuation Linear falloff attenuation value	
+			* @param quadraticAttenuation Quadratic falloff attenuation value
+			* 
+			*/
+			void setAttenuation(Number constantAttenuation, Number linearAttenuation, Number quadraticAttenuation);			
 						
 			Number getConstantAttenuation() { return constantAttenuation; }
 			Number getLinearAttenuation() { return linearAttenuation; }
@@ -78,6 +95,21 @@ namespace Polycode {
 			
 			Texture *getZBufferTexture();
 			
+			/**
+			* Color of the light.
+			*/ 
+			Color specularLightColor;
+		
+			/**
+			* Sets the light color.
+			* @param r Red value 0-1.
+			* @param g Green value 0-1
+			* @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; }
+						
+			
 			/**
 			* Color of the light.
 			*/ 
@@ -90,7 +122,24 @@ namespace Polycode {
 			* @param b Blue value 0-1
 			* @param a Alpha value 0-1									
 			*/	
-			void setLightColor(Number r, Number g, Number b) { lightColor.r = r; lightColor.g = g; lightColor.b = b; }
+			void setDiffuseLightColor(Number r, Number g, Number b) { lightColor.r = r; lightColor.g = g; lightColor.b = b; }
+			
+			
+			
+			/**
+			* Sets both the specular and diffust light colors. Use setDiffuseLightColor and setSpecularLightColor to set the individual light colors.
+			* @param r Red value 0-1.
+			* @param g Green value 0-1
+			* @param b Blue value 0-1
+			* @param a Alpha value 0-1									
+			*/	
+			void setLightColor(Number r, Number g, Number b, Number a=1.0) { 
+				setDiffuseLightColor(r,g,b);
+				setSpecularLightColor(r,g,b,a);
+			}
+			
+			
+						
 			
 			/**
 			* Sets the spotlight properties. These control the shape of the spotlight beam.
@@ -99,7 +148,8 @@ namespace Polycode {
 			*/
 			void setSpotlightProperties(Number spotlightCutoff, Number spotlightExponent) {
 				this->spotlightCutoff = spotlightCutoff;
-				this->spotlightExponent = spotlightExponent;				
+				Number cosVal = cos(spotlightCutoff*(PI/180.0));
+				this->spotlightExponent = cosVal - (0.02*spotlightExponent);				
 			}
 			
 			Number getSpotlightCutoff() { return spotlightCutoff; }
@@ -129,6 +179,13 @@ namespace Polycode {
 			*/
 			int getLightType() { return type; }
 		
+			/**
+			* If set to true, draws a wireframe primitive visualizing the light.
+			*/
+			void enableDebugDraw(bool val);
+		
+			SceneEntity *lightShape;
+			
 		private:
 		
 			Number spotlightExponent;

+ 11 - 2
Core/Contents/Include/PolyScenePrimitive.h

@@ -34,14 +34,15 @@ namespace Polycode {
 	/**
 	* 3D primitive mesh. 
 	*/
+	
 	class _PolyExport ScenePrimitive : public SceneMesh {
 		public:
 		
 			/**
 			* Create a primitive mesh of specified type and size.
-			* @param type Type of primitive to create. Current types are ScenePrimitive::TYPE_BOX, ScenePrimitive::TYPE_PLANE and ScenePrimitive::TYPE_SPHERE
+			* @param type Type of primitive to create. Current types are ScenePrimitive::TYPE_BOX, ScenePrimitive::TYPE_PLANE, ScenePrimitive::TYPE_VPLANE, ScenePrimitive::TYPE_SPHERE, ScenePrimitive::TYPE_CYLINDER, ScenePrimitive::TYPE_CONE and ScenePrimitive::TYPE_TORUS
 			*/
-			ScenePrimitive(int type, Number v1=1.0f, Number v2=1.0f, Number v3=1.0f);
+			ScenePrimitive(int type, Number v1=1.0f, Number v2=1.0f, Number v3=1.0f,Number v4=0.0f,Number v5=0.0f);
 			virtual ~ScenePrimitive();
 
 			/**
@@ -64,6 +65,14 @@ namespace Polycode {
 			* A cone.
 			*/			
 			static const int TYPE_CONE = 4;
+			/**
+			* A vertical plane.
+			*/			
+			static const int TYPE_VPLANE = 5;			
+			/**
+			* A torus.
+			*/			
+			static const int TYPE_TORUS = 6;			
 
 		
 		private:

+ 10 - 0
Core/Contents/Include/PolyScreen.h

@@ -136,6 +136,16 @@ namespace Polycode {
 		*/
 		bool enabled;
 		
+		/**
+		* Returns the local shader options for the camera post processing material.
+		*/				
+		vector<ShaderBinding*> getLocalShaderOptions() { return localShaderOptions; }
+		
+		/**
+		* Returns the shader material applied to the camera.
+		*/					
+		Material *getScreenShaderMaterial() { return filterShaderMaterial; }
+		
 	protected:
 		
 		bool useNormalizedCoordinates;

+ 2 - 0
Core/Contents/Include/PolyShader.h

@@ -107,6 +107,8 @@ namespace Polycode {
 			unsigned int getNumOutTargetBindings();
 			RenderTargetBinding *getOutTargetBinding(unsigned int index);
 			
+			void addLocalParam(String name, void *ptr);
+			
 			Shader* shader;
 			vector<LocalShaderParam*> localParams;
 			vector<RenderTargetBinding*> renderTargetBindings;

+ 9 - 2
Core/Contents/Include/PolySound.h

@@ -28,8 +28,15 @@
 #include "PolyVector3.h"
 #include <string>
 #include <vector>
-#include "AL/al.h"
-#include "AL/alc.h"
+
+#if defined(__APPLE__) && defined(__MACH__)
+	#include "al.h"
+	#include "alc.h"
+#else
+	#include "AL/al.h"
+	#include "AL/alc.h"
+#endif
+
 #include "OSBasics.h"
 
 using std::string;

+ 9 - 2
Core/Contents/Include/PolySoundManager.h

@@ -25,8 +25,15 @@
 #include "PolyLogger.h"
 #include "PolyGlobals.h"
 #include <stdio.h>
-#include "AL/al.h"
-#include "AL/alc.h"
+
+#if defined(__APPLE__) && defined(__MACH__)
+	#include "al.h"
+	#include "alc.h"
+#else
+	#include "AL/al.h"
+	#include "AL/alc.h"
+#endif
+
 #include "PolyVector3.h"
 
 namespace Polycode {

+ 1 - 1
Core/Contents/Source/PolyColor.cpp

@@ -24,7 +24,7 @@
 
 using namespace Polycode;
 
-Color::Color() : r(0),g(0),b(0),a(1){
+Color::Color() : r(1),g(1),b(1),a(1){
 
 }
 

+ 3 - 3
Core/Contents/Source/PolyEntity.cpp

@@ -317,10 +317,10 @@ void Entity::transformAndRender() {
 	int mode = renderer->getRenderMode();
 	if(renderWireframe)
 		renderer->setRenderMode(Renderer::RENDER_MODE_WIREFRAME);
-		
+	else
+		renderer->setRenderMode(Renderer::RENDER_MODE_NORMAL);	
 	if(visible) {
 		Render();
-		renderer->setRenderMode(mode);
 	
 	
 //	renderer->pushMatrix();
@@ -329,7 +329,7 @@ void Entity::transformAndRender() {
 //	renderer->popMatrix();	
 	
 	}		
-	
+	renderer->setRenderMode(mode);	
 	renderer->popMatrix();
 	
 	if(hasMask) {

+ 20 - 1
Core/Contents/Source/PolyGLRenderer.cpp

@@ -434,7 +434,6 @@ void OpenGLRenderer::setFogProperties(int fogMode, Color color, Number density,
 	glHint(GL_FOG_HINT, GL_DONT_CARE);
 	glFogf(GL_FOG_START, startDepth);
 	glFogf(GL_FOG_END, endDepth);
-	glClearColor(color.r, color.g, color.b, color.a);
 }
 
 
@@ -666,6 +665,26 @@ void OpenGLRenderer::applyMaterial(Material *material,  ShaderBinding *localOpti
 		return;
 	}
 
+	GLfloat data4[] = {material->diffuseColor.r, material->diffuseColor.g, material->diffuseColor.b, material->diffuseColor.a};					
+	glMaterialfv(GL_FRONT, GL_DIFFUSE, data4);
+
+	data4[0] = material->specularColor.r;
+	data4[1] = material->specularColor.g;
+	data4[2] = material->specularColor.b;
+	data4[3] = material->specularColor.a;
+				
+	glMaterialfv(GL_FRONT, GL_SPECULAR, data4);
+
+	glMaterialf(GL_FRONT, GL_SHININESS, material->specularValue);
+
+
+
+	data4[0] = ambientColor.r;
+	data4[1] = ambientColor.g;
+	data4[2] = ambientColor.b;
+	data4[3] = 1.0;
+	glMaterialfv(GL_FRONT, GL_AMBIENT, data4);
+
 	FixedShaderBinding *fBinding;
 
 	switch(material->getShader(shaderIndex)->getType()) {

+ 43 - 32
Core/Contents/Source/PolyGLSLShaderModule.cpp

@@ -206,7 +206,7 @@ void GLSLShaderModule::setGLSLSpotLightTextureMatrixParameter(Renderer *renderer
 
 
 
-void GLSLShaderModule::updateGLSLParam(Renderer *renderer, GLSLProgramParam &param, ShaderBinding *materialOptions, ShaderBinding *localOptions) {
+void GLSLShaderModule::updateGLSLParam(Renderer *renderer, GLSLShader *glslShader, GLSLProgramParam &param, ShaderBinding *materialOptions, ShaderBinding *localOptions) {
 	if(param.isAuto) {
 		switch(param.autoID) {
 			case GLSLProgramParam::POLY_MODELVIEWPROJ_MATRIX:
@@ -346,13 +346,20 @@ void GLSLShaderModule::updateGLSLParam(Renderer *renderer, GLSLProgramParam &par
 		
 		switch(param.paramType) {
 			case GLSLProgramParam::PARAM_Number:
+			{
 				fval = (Number*)paramData;
-//				cgGLSetParameter1f(param.cgParam, *fval);
+				int paramLocation = glGetUniformLocation(glslShader->shader_id, param.name.c_str());
+				glUniform1f(paramLocation, *fval);
 				break;
+			}
 			case GLSLProgramParam::PARAM_Number3:
+			{
 				Vector3 *fval3 = (Vector3*)paramData;
-//				cgGLSetParameter3f(param.cgParam, fval3->x,fval3->y,fval3->z);
-				break;
+				fval = (Number*)paramData;
+				int paramLocation = glGetUniformLocation(glslShader->shader_id, param.name.c_str());
+				glUniform3f(paramLocation, fval3->x,fval3->y,fval3->z);
+				break;				
+			}
 		}
 	}
 }
@@ -370,14 +377,18 @@ bool GLSLShaderModule::applyShaderMaterial(Renderer *renderer, Material *materia
 	int numRendererAreaLights = renderer->getNumAreaLights();
 	int numRendererSpotLights = renderer->getNumSpotLights();
 	
-	int numTotalLights = numRendererAreaLights + numRendererSpotLights;
-	
-	
+	int numTotalLights = glslShader->numAreaLights + glslShader->numSpotLights;
+		
 	for(int i=0 ; i < numTotalLights; i++) {
 		GLfloat resetData[] = {0.0, 0.0, 0.0, 0.0};				
 		glLightfv (GL_LIGHT0+i, GL_DIFFUSE, resetData);	
+		glLightfv (GL_LIGHT0+i, GL_SPECULAR, resetData);			
 		glLightfv (GL_LIGHT0+i, GL_AMBIENT, resetData);	
-		glLightfv (GL_LIGHT0+i, GL_POSITION, resetData);			
+		glLightfv (GL_LIGHT0+i, GL_POSITION, resetData);	
+		glLightf (GL_LIGHT0+i, GL_SPOT_CUTOFF, 180);		
+		glLightf (GL_LIGHT0+i, GL_CONSTANT_ATTENUATION,1.0);			
+		glLightf (GL_LIGHT0+i, GL_LINEAR_ATTENUATION,0.0);			
+		glLightf (GL_LIGHT0+i, GL_QUADRATIC_ATTENUATION, 0.0);			
 	}
 	
 	int lightIndex = 0;
@@ -393,19 +404,17 @@ bool GLSLShaderModule::applyShaderMaterial(Renderer *renderer, Material *materia
 			ambientVal[1] = renderer->ambientColor.g;
 			ambientVal[2] = renderer->ambientColor.b;										
 			ambientVal[3] = 1;
-		} else {
-			light.color.set(0,0,0);
-			light.intensity = 0;
-			ambientVal[0] = 0;
-			ambientVal[1] = 0;
-			ambientVal[2] = 0;
-			ambientVal[3] = 0;									
-		}		
 		
 		GLfloat data4[] = {light.color.x * light.intensity, light.color.y * light.intensity, light.color.z * light.intensity, 1.0};					
 		glLightfv (GL_LIGHT0+lightIndex, GL_DIFFUSE, data4);
 		
-		glLightfv (GL_LIGHT0+lightIndex, GL_SPECULAR, data4);		
+		data4[0] = light.specularColor.r* light.intensity;
+		data4[1] = light.specularColor.g* light.intensity;
+		data4[2] = light.specularColor.b* light.intensity;
+		data4[3] = light.specularColor.a* light.intensity;
+		glLightfv (GL_LIGHT0+lightIndex, GL_SPECULAR, data4);				
+			
+		data4[3] = 1.0;
 			
 		glLightfv (GL_LIGHT0+lightIndex, GL_AMBIENT, ambientVal);		
 		glLightf (GL_LIGHT0+lightIndex, GL_SPOT_CUTOFF, 180);
@@ -418,11 +427,13 @@ bool GLSLShaderModule::applyShaderMaterial(Renderer *renderer, Material *materia
 		glLightf (GL_LIGHT0+lightIndex, GL_CONSTANT_ATTENUATION, light.constantAttenuation);		
 		glLightf (GL_LIGHT0+lightIndex, GL_LINEAR_ATTENUATION, light.linearAttenuation);				
 		glLightf (GL_LIGHT0+lightIndex, GL_QUADRATIC_ATTENUATION, light.quadraticAttenuation);				
+		
+		} 			
 		lightIndex++;
 	}
 
 	vector<LightInfo> spotLights = renderer->getSpotLights();
-	vector<Texture*> shadowMapTextures = renderer->getShadowMapTextures();	
+//	vector<Texture*> shadowMapTextures = renderer->getShadowMapTextures();	
 	char texName[32];
 	char matName[32];	
 	int shadowMapTextureIndex = 0;
@@ -445,21 +456,18 @@ bool GLSLShaderModule::applyShaderMaterial(Renderer *renderer, Material *materia
 			ambientVal[1] = renderer->ambientColor.g;
 			ambientVal[2] = renderer->ambientColor.b;										
 			ambientVal[3] = 1;
-		} else {
-			light.color.set(0,0,0);
-			light.intensity = 0;
-			ambientVal[0] = 0;
-			ambientVal[1] = 0;
-			ambientVal[2] = 0;
-			ambientVal[3] = 0;									
-			light.shadowsEnabled = false;
-		}		
 		
 		GLfloat data4[] = {light.color.x * light.intensity, light.color.y * light.intensity, light.color.z * light.intensity, 1.0};					
 		glLightfv (GL_LIGHT0+lightIndex, GL_DIFFUSE, data4);
 		
+		data4[0] = light.specularColor.r* light.intensity;
+		data4[1] = light.specularColor.g* light.intensity;
+		data4[2] = light.specularColor.b* light.intensity;
+		data4[3] = light.specularColor.a* light.intensity;
 		glLightfv (GL_LIGHT0+lightIndex, GL_SPECULAR, data4);		
 			
+		data4[3] = 1.0;			
+			
 		glLightfv (GL_LIGHT0+lightIndex, GL_AMBIENT, ambientVal);		
 		glLightf (GL_LIGHT0+lightIndex, GL_SPOT_CUTOFF, light.spotlightCutoff);
 
@@ -480,7 +488,7 @@ bool GLSLShaderModule::applyShaderMaterial(Renderer *renderer, Material *materia
 		glLightf (GL_LIGHT0+lightIndex, GL_QUADRATIC_ATTENUATION, light.quadraticAttenuation);				
 		
 		if(light.shadowsEnabled) {		
-			if(shadowMapTextureIndex < shadowMapTextures.size()) {
+			if(shadowMapTextureIndex < 4) {
 				switch(shadowMapTextureIndex) {
 					case 0:
 						strcpy(texName, "shadowMap0");
@@ -503,7 +511,7 @@ bool GLSLShaderModule::applyShaderMaterial(Renderer *renderer, Material *materia
 				int texture_location = glGetUniformLocation(glslShader->shader_id, texName);
 				glUniform1i(texture_location, textureIndex);
 				glActiveTexture(GL_TEXTURE0 + textureIndex);		
-				glBindTexture(GL_TEXTURE_2D, ((OpenGLTexture*)shadowMapTextures[shadowMapTextureIndex])->getTextureID());	
+				glBindTexture(GL_TEXTURE_2D, ((OpenGLTexture*)light.shadowMapTexture)->getTextureID());	
 				textureIndex++;
 				
 //				glMatrixMode(GL_MODELVIEW);
@@ -528,7 +536,10 @@ bool GLSLShaderModule::applyShaderMaterial(Renderer *renderer, Material *materia
 			}
 			shadowMapTextureIndex++;
 		}
-		
+	else {							
+			light.shadowsEnabled = false;
+		}		
+		} 	
 		lightIndex++;
 	}
 	glPopMatrix();
@@ -539,12 +550,12 @@ bool GLSLShaderModule::applyShaderMaterial(Renderer *renderer, Material *materia
 	
 	for(int i=0; i < glslShader->vp->params.size(); i++) {
 		GLSLProgramParam param = glslShader->vp->params[i];
-		updateGLSLParam(renderer, param, material->getShaderBinding(shaderIndex), localOptions);
+		updateGLSLParam(renderer, glslShader, param, material->getShaderBinding(shaderIndex), localOptions);
 	}
 	
 	for(int i=0; i < glslShader->fp->params.size(); i++) {
 		GLSLProgramParam param = glslShader->fp->params[i];
-		updateGLSLParam(renderer, param, material->getShaderBinding(shaderIndex), localOptions);
+		updateGLSLParam(renderer, glslShader, param, material->getShaderBinding(shaderIndex), localOptions);
 	}	
 	
 	for(int i=0; i < cgBinding->textures.size(); i++) {

+ 0 - 580
Core/Contents/Source/PolyGenericScene.cpp

@@ -1,580 +0,0 @@
-/*
- *  PolyGenericScene.cpp
- *  Poly
- *
- *  Created by Ivan Safrin on 3/18/08.
- *  Copyright 2008 Ivan Safrin. All rights reserved.
- *
- */
-
-#include "PolyGenericScene.h"
-
-using namespace Polycode;
-
-GenericScene::GenericScene() : Scene() {
-	hasLightmaps = false;
-	clearColor.setColor(0.13f,0.13f,0.13f,1.0f); 
-	virtualScene = false;
-	useClearColor = false;
-}
-
-GenericScene::GenericScene(bool virtualScene) {
-	this->virtualScene = virtualScene;	
-}
-
-GenericScene::~GenericScene() {
-}
-
-void GenericScene::Render() {
-	
-	if(!defaultCamera)
-		return;
-	
-	// prepare lights...
-	for(int i=0; i<entities.size();i++) {
-		entities[i]->doUpdates();		
-		entities[i]->updateEntityMatrix();
-	}	
-	
-	//make these the closest
-	
-	Matrix4 textureMatrix;
-	Matrix4 *matrixPtr;
-	
-	
-	defaultCamera->rebuildTransformMatrix();
-	
-	if(virtualScene)
-		return;
-	
-	if(useClearColor)
-		CoreServices::getInstance()->getRenderer()->setClearColor(clearColor.r,clearColor.g,clearColor.b);	
-	
-	CoreServices::getInstance()->getRenderer()->setAmbientColor(ambientColor.r,ambientColor.g,ambientColor.b);		
-
-	CoreServices::getInstance()->getRenderer()->clearLights();
-	
-	for(int i=0; i < lights.size(); i++) {
-		
-		SceneLight *light = lights[i];
-		
-		Vector3 direction;
-		Vector3 position;
-		matrixPtr = NULL;				
-		direction.x = 0;		
-		direction.y = 1;
-		direction.z = 0;
-
-		direction = light->getConcatenatedMatrix().rotateVector(direction);
-		direction.Normalize();
-		
-		if(light->areShadowsEnabled()) {
-			if(light->getType() == SceneLight::SPOT_LIGHT) {
-				textureMatrix.identity();
-
-				Matrix4 matTexAdj(0.5f,	0.0f,	0.0f,	0.0f,
-								  0.0f,	0.5f,	0.0f,	0.0f,
-								  0.0f,	0.0f,	0.5f,	0.0f,
-								  0.5f,	0.5f,	0.5f,	1.0f );
-
-				textureMatrix =  defaultCamera->getConcatenatedMatrix() * light->getLightViewMatrix() * matTexAdj;
-			
-				matrixPtr = &textureMatrix;
-				light->renderDepthMap(this);
-				CoreServices::getInstance()->getRenderer()->addShadowMap(light->getZBufferTexture());
-			}
-		}
-
-		position = light->getPosition();
-		if(light->getParentEntity() != NULL) {
-			position = light->getParentEntity()->getConcatenatedMatrix() * position;			
-		}
-		CoreServices::getInstance()->getRenderer()->addLight(position, direction, light->getLightType(), light->lightColor, light->getDistance(), light->getIntensity(), matrixPtr);
-	}	
-	
-	defaultCamera->doCameraTransform();
-	defaultCamera->buildFrustrumPlanes();
-	
-	if(defaultCamera->getOrthoMode()) {
-		CoreServices::getInstance()->getRenderer()->_setOrthoMode();
-	}
-	
-	for(int i=0; i<entities.size();i++) {
-		if(entities[i]->getBBoxRadius() > 0) {
-			if(defaultCamera->isSphereInFrustrum((entities[i]->getPosition()), entities[i]->getBBoxRadius()))
-				entities[i]->transformAndRender();
-		} else {
-			entities[i]->transformAndRender();		
-		}
-	}
-	
-	if(defaultCamera->getOrthoMode()) {
-		CoreServices::getInstance()->getRenderer()->setPerspectiveMode();
-	}
-	
-}
-
-
-void GenericScene::RenderDepthOnly(Camera *targetCamera) {
-
-	for(int i=0; i<entities.size();i++) {
-		entities[i]->doUpdates();		
-		entities[i]->updateEntityMatrix();
-	}
-	
-	targetCamera->doCameraTransform();
-	
-	if(virtualScene)
-		return;	
-	
-	targetCamera->buildFrustrumPlanes();
-
-	CoreServices::getInstance()->getRenderer()->setTexture(NULL);
-	CoreServices::getInstance()->getRenderer()->enableShaders(false);
-	for(int i=0; i<entities.size();i++) {
-		if(entities[i]->getBBoxRadius() > 0) {
-			if(targetCamera->isSphereInFrustrum((entities[i]->getPosition()), entities[i]->getBBoxRadius()))
-				entities[i]->transformAndRender();
-		} else {
-			entities[i]->transformAndRender();		
-		}
-	}	
-	CoreServices::getInstance()->getRenderer()->enableShaders(true);
-}
-
-void GenericScene::addLight(SceneLight *light) {
-	lights.push_back(light);
-	addEntity(light);
-}
-
-SceneLight *GenericScene::getNearestLight(Vector3 pos) {
-	if(lights.size() > 0)
-		return lights[0];
-	else
-		return NULL;
-}
-
-
-String GenericScene::readString(OSFILE *inFile) {
-	char buffer[1024];
-	unsigned int namelen;
-	OSBasics::read(&namelen, sizeof(unsigned int), 1, inFile);
-	memset(buffer, 0, 1024);
-	OSBasics::read(buffer, 1, namelen, inFile);
-	return string(buffer);
-	
-}
-
-void GenericScene::loadScene(String fileName) {
-	OSFILE *inFile = OSBasics::open(fileName.c_str(), "rb");
-	if(!inFile) {
-		Logger::log("Error opening scene file\n");
-		return;
-	}
-	
-	Number r,g,b,a;
-	
-	OSBasics::read(&r, sizeof(Number), 1, inFile);
-	OSBasics::read(&g, sizeof(Number), 1, inFile);
-	OSBasics::read(&b, sizeof(Number), 1, inFile);
-	clearColor.setColor(r,g,b,1.0f);
-
-	OSBasics::read(&r, sizeof(Number), 1, inFile);
-	OSBasics::read(&g, sizeof(Number), 1, inFile);
-	OSBasics::read(&b, sizeof(Number), 1, inFile);
-	ambientColor.setColor(r,g,b,1.0f);
-	
-	
-	unsigned int numObjects, objectType,namelen;
-	char buffer[1024];
-	char flag;
-	Number t[3],rq[4];
-	SceneEntity *newEntity;
-	
-	unsigned int lightmapIndex = 0;
-	
-	OSBasics::read(&flag, 1, 1, inFile);
-	hasLightmaps = false;
-	if(flag == 1)
-		hasLightmaps = true;
-	
-	OSBasics::read(&numObjects, sizeof(unsigned int), 1, inFile);
-	Logger::log("Loading scene (%d objects)\n", numObjects);
-	for(int i=0; i < numObjects; i++) {
-		
-		OSBasics::read(t, sizeof(Number), 3, inFile);
-		OSBasics::read(rq, sizeof(Number), 4, inFile);
-		newEntity = NULL;
-		
-		OSBasics::read(&objectType, sizeof(unsigned int), 1, inFile);
-
-		SceneMesh *newSceneMesh;
-		Mesh *newMesh;
-		Material *newMaterial;
-		
-		switch(objectType) {
-			case ENTITY_MESH:			
-
-				if(hasLightmaps) {
-					OSBasics::read(&lightmapIndex, sizeof(unsigned int), 1, inFile);			
-				} else {
-					lightmapIndex = 0;
-				}
-
-			
-				OSBasics::read(&namelen, sizeof(unsigned int), 1, inFile);
-				memset(buffer, 0, 1024);
-				OSBasics::read(buffer, 1, namelen, inFile);
-				
-				Logger::log("adding mesh (texture: %s)\n", buffer);
-				
-				OSBasics::read(&r, sizeof(Number), 1, inFile);
-				OSBasics::read(&g, sizeof(Number), 1, inFile);
-				OSBasics::read(&b, sizeof(Number), 1, inFile);
-				OSBasics::read(&a, sizeof(Number), 1, inFile);
-				
-				newMaterial = (Material*) CoreServices::getInstance()->getResourceManager()->getResource(Resource::RESOURCE_MATERIAL, buffer);
-				newMesh = new Mesh(Mesh::TRI_MESH);
-				newMesh->loadFromFile(inFile);
-				newSceneMesh = new SceneMesh(newMesh);
-				
-				newSceneMesh->setColor(r,g,b,a);
-				newSceneMesh->lightmapIndex = lightmapIndex;
-				addEntity(newSceneMesh);
-				newEntity = (SceneEntity*)newSceneMesh;
-				staticGeometry.push_back(newSceneMesh);
-				if(newMaterial != NULL)
-					newSceneMesh->setMaterial(newMaterial);
-				
-				break;
-				case ENTITY_ENTITY: {
-					Logger::log("loading entity\n");
-					String entityType = readString(inFile);					
-					SceneEntity *newCustomEntity = new SceneEntity();
-					newCustomEntity->custEntityType = entityType;					
-					newEntity = newCustomEntity;
-					customEntities.push_back(newCustomEntity);					
-				} break;
-				case ENTITY_COLLMESH: {
-					unsigned int collType,numVertices,numFaces;
-					Number co[3];
-					OSBasics::read(&collType, sizeof(unsigned int), 1, inFile);
-					OSBasics::read(&numVertices, sizeof(unsigned int), 1, inFile);
-
-					Mesh *mesh = new Mesh(Mesh::TRI_MESH);
-					
-					for(int i=0; i < numVertices; i++) {
-						OSBasics::read(co, sizeof(Number), 3, inFile);
-						Vertex *newVert = new Vertex(co[0], co[1], co[2]);
-						mesh->addVertex(newVert);
-					}
-
-					OSBasics::read(&numFaces, sizeof(unsigned int), 1, inFile);
-					
-					unsigned int fo[3];
-					for(int i=0; i < numFaces; i++) {
-						OSBasics::read(fo, sizeof(unsigned int), 3, inFile);						
-						Polygon *newPoly = new Polygon();
-						newPoly->addVertex(mesh->getVertex(fo[0]));
-						newPoly->addVertex(mesh->getVertex(fo[1]));
-						newPoly->addVertex(mesh->getVertex(fo[2]));
-						mesh->addPolygon(newPoly);
-					}
-					
-					SceneMesh *newMesh = new SceneMesh(mesh);
-					newEntity = newMesh;
-					loadCollisionChild(newEntity);
-					collisionGeometry.push_back(newMesh);
-					newMesh->visible = false;
-					
-//					ScenePrimitive *test = new ScenePrimitive(ScenePrimitive::TYPE_BOX, newMesh->bBox.x,newMesh->bBox.y,newMesh->bBox.z);				
-//					newMesh->addEntity(test);
-					
-				}
-				break;
-				case ENTITY_CAMERA:
-					newEntity = (SceneEntity*)this->getDefaultCamera();
-				break;
-				case ENTITY_LIGHT:
-				
-				Number col[3],e,d;
-				unsigned int lType;
-				OSBasics::read(&lType, sizeof(unsigned int), 1, inFile);				
-				OSBasics::read(&e, sizeof(Number), 1, inFile);
-				OSBasics::read(&d, sizeof(Number), 1, inFile);
-				OSBasics::read(col, sizeof(Number), 3, inFile);
-
-				SceneLight *newLight = new SceneLight(lType, e, d, this);
-				newLight->lightColor.setColor(col[0],col[1],col[2],1.0f);
-				addLight(newLight);
-				newEntity = (SceneEntity*)newLight;
-				break;
-		}
-		
-		
-		if(newEntity != NULL) {		
-			unsigned int numProps;
-			OSBasics::read(&numProps, sizeof(unsigned int), 1, inFile);
-			for(int i=0; i < numProps; i++) {
-				String propName,propValue;
-				propName = readString(inFile);
-				propValue = readString(inFile);
-				EntityProp prop;
-				prop.propName = propName;
-				prop.propValue = propValue;
-				newEntity->entityProps.push_back(prop);
-			}						
-			
-			if(objectType == ENTITY_MESH) {
-				if(newEntity->getEntityProp("vertexnormals") == "false")
-					((SceneMesh*)newEntity)->getMesh()->useVertexNormals(false);
-				
-				if(newEntity->getEntityProp("collision") != "") {
-					if(newEntity->getEntityProp("collision")  == "mesh") {
-						loadCollisionChild(newEntity, false, 3);
-					}
-				}
-			}
-			
-			newEntity->setPosition(t[0], t[1], t[2]);
-			newEntity->setRotationQuat(rq[0], rq[1], rq[2], rq[3]);
-			newEntity->rebuildTransformMatrix();						
-		}		
-	}
-	
-	if(!hasLightmaps) {
-		OSBasics::close(inFile);
-		return;
-	}
-	/*
-	unsigned int lmsize,numLightmaps,imageWidth, imageHeight;
-	OSBasics::read(&numLightmaps, sizeof(unsigned int), 1, inFile);
-	
-	packer = new LightmapPacker(this);
-	char *imageData;
-	
-	for(int i=0 ; i < numLightmaps; i++) {
-		OSBasics::read(&imageWidth, sizeof(unsigned int), 1, inFile);
-		OSBasics::read(&imageHeight, sizeof(unsigned int), 1, inFile);
-		OSBasics::read(&lmsize, sizeof(unsigned int), 1, inFile);
-		imageData = (char*)malloc(lmsize);
-		OSBasics::read(imageData, 1, lmsize, inFile);
-		Image *newImage = new Image(imageData, imageWidth, imageHeight);
-		packer->images.push_back(newImage);	
-		free(imageData);
-	}
-	
-	packer->bindTextures();
-	*/
-	OSBasics::close(inFile);
-}
-
-vector<SceneEntity*> GenericScene::getCustomEntitiesByType(String type) {
-	vector<SceneEntity*> retVector;
-	for(int i=0; i < customEntities.size(); i++) {
-		if(customEntities[i]->custEntityType == type) {
-			retVector.push_back(customEntities[i]);
-		}
-	}
-	return retVector;	
-}
-
-SceneEntity *GenericScene::getCustomEntityByType(String type) {
-	for(int i=0; i < customEntities.size(); i++) {
-		if(customEntities[i]->custEntityType == type) {
-			return customEntities[i];
-		}
-	}
-	return NULL;
-}
-
-void GenericScene::writeEntityMatrix(SceneEntity *entity, OSFILE *outFile) {
-	Number t[3],rq[4];
-	Vector3 pos = entity->getPosition();
-	t[0] = pos.x;
-	t[1] = pos.y;
-	t[2] = pos.z;
-	
-	rq[0] = entity->getRotationQuat().w;
-	rq[1] = entity->getRotationQuat().x;
-	rq[2] = entity->getRotationQuat().y;
-	rq[3] = entity->getRotationQuat().z;						
-	
-	OSBasics::write(t, sizeof(Number), 3, outFile);
-	OSBasics::write(rq, sizeof(Number), 4, outFile);
-	
-}
-
-void GenericScene::saveScene(String fileName) {
-	OSFILE *outFile = OSBasics::open(fileName.c_str(), "wb");
-	if(!outFile) {
-		Logger::log("Error opening scene file for writing\n");
-		return;
-	}
-	
-	// geometry
-	unsigned int totalObjects = staticGeometry.size() + lights.size() + collisionGeometry.size() + customEntities.size();
-	unsigned int objType;
-	char flag = 0;
-	if(hasLightmaps)
-		flag = 1;
-	OSBasics::write(&flag, 1, 1, outFile);
-	OSBasics::write(&totalObjects, sizeof(unsigned int), 1, outFile);
-	
-	unsigned int stLen;
-	
-	for(int i=0; i <staticGeometry.size(); i++) {
-		SceneMesh *mesh = staticGeometry[i];
-		
-		writeEntityMatrix(mesh, outFile);
-		
-		objType = GenericScene::ENTITY_MESH;		
-		OSBasics::write(&objType, sizeof(unsigned int), 1, outFile);
-
-		if(hasLightmaps) {
-			unsigned int lightmapIndex = mesh->lightmapIndex;
-			OSBasics::write(&lightmapIndex, sizeof(unsigned int), 1, outFile);			
-		}
-
-		stLen = mesh->getMaterial()->getName().length();
-		OSBasics::write(&stLen, sizeof(unsigned int), 1, outFile);
-		OSBasics::write(mesh->getMaterial()->getName().c_str(), 1, stLen, outFile);
-		
-		mesh->getMesh()->saveToFile(outFile);		
-	}
-	
-
-	for(int i=0; i < collisionGeometry.size(); i++) {
-		SceneMesh *mesh = collisionGeometry[i];
-		writeEntityMatrix(mesh, outFile);
-		objType = GenericScene::ENTITY_COLLMESH;
-		OSBasics::write(&objType, sizeof(unsigned int), 1, outFile);
-	
-		unsigned int collType = 1;
-		OSBasics::write(&collType, sizeof(unsigned int), 1, outFile);
-		
-		unsigned int numVertices = mesh->getMesh()->getNumVertices();
-		OSBasics::write(&numVertices, sizeof(unsigned int), 1, outFile);
-		Number pos[3];
-		for(int j=0; j < numVertices; j++) {
-			Vertex *vert = mesh->getMesh()->getVertex(j);
-			pos[0] = vert->x;
-			pos[1] = vert->y;
-			pos[2] = vert->z;			
-			OSBasics::write(pos, sizeof(Number),3, outFile);
-		}
-
-		unsigned int numFaces = mesh->getMesh()->getPolygonCount();
-		OSBasics::write(&numFaces, sizeof(unsigned int), 1, outFile);
-		unsigned int ind[3];
-		for(int j=0; j < numFaces; j++) {
-			Polygon *poly = mesh->getMesh()->getPolygon(j);
-			ind[0] = mesh->getMesh()->getVertexIndex(poly->getVertex(0));
-			ind[1] = mesh->getMesh()->getVertexIndex(poly->getVertex(1));
-			ind[2] = mesh->getMesh()->getVertexIndex(poly->getVertex(2));			
-			OSBasics::write(ind, sizeof(unsigned int),3, outFile);
-		}
-	}
-	
-	Number col[3],e,d;
-	for(int i=0; i < lights.size(); i++) {
-	
-		writeEntityMatrix(lights[i], outFile);
-		objType = GenericScene::ENTITY_LIGHT;		
-		OSBasics::write(&objType, sizeof(unsigned int), 1, outFile);
-	
-		col[0] = lights[i]->lightColor.r;
-		col[1] = lights[i]->lightColor.g;
-		col[2] = lights[i]->lightColor.b;
-		e = lights[i]->getIntensity();
-		d = lights[i]->getDistance();
-		
-		OSBasics::write(&e, sizeof(Number), 1, outFile);
-		OSBasics::write(&d, sizeof(Number), 1, outFile);
-		OSBasics::write(col, sizeof(Number), 3, outFile);
-	}
-
-	for(int i=0; i < customEntities.size(); i++) {
-		SceneEntity *custEnt = customEntities[i];
-		
-		writeEntityMatrix(custEnt, outFile);	
-		objType = GenericScene::ENTITY_ENTITY;
-		OSBasics::write(&objType, sizeof(unsigned int), 1, outFile);
-		
-		
-		writeString(custEnt->custEntityType, outFile);
-		unsigned int numProps = custEnt->entityProps.size();
-		OSBasics::write(&numProps, sizeof(unsigned int), 1, outFile);		
-		for(int j=0; j < numProps; j++) {
-			writeString(custEnt->entityProps[j].propName, outFile);
-			writeString(custEnt->entityProps[j].propValue, outFile);
-		}
-	}
-
-	if(!hasLightmaps) {
-		OSBasics::close(outFile);
-		return;
-	}
-	
-	/*
-	unsigned int lmsize;
-	lmsize = packer->images.size();
-	OSBasics::write(&lmsize, sizeof(unsigned int), 1, outFile);
-	for(int i=0; i < packer->images.size(); i++) {
-		lmsize = packer->images[i]->getWidth();
-		OSBasics::write(&lmsize, sizeof(unsigned int), 1, outFile);
-		lmsize = packer->images[i]->getHeight();
-		OSBasics::write(&lmsize, sizeof(unsigned int), 1, outFile);
-		
-		lmsize = packer->images[i]->getWidth() * packer->images[i]->getHeight() * 4;
-		OSBasics::write(&lmsize, sizeof(unsigned int), 1, outFile);
-		OSBasics::write(packer->images[i]->getPixels(), 1, lmsize, outFile);
-	}
-	*/
-	
-	OSBasics::close(outFile);
-}
-
-void GenericScene::writeString(String str, OSFILE *outFile) {
-	unsigned int stLen = str.length();
-	OSBasics::write(&stLen, sizeof(unsigned int), 1, outFile);
-	OSBasics::write(str.c_str(), 1, stLen, outFile);
-	
-}
-
-int GenericScene::getNumStaticGeometry() {
-	return staticGeometry.size();
-}
-
-SceneMesh *GenericScene::getStaticGeometry(int index) {
-	return staticGeometry[index];
-}
-
-int GenericScene::getNumLights() {
-	return lights.size();
-}
-
-SceneLight *GenericScene::getLight(int index) {
-	return lights[index];
-}
-
-void GenericScene::generateLightmaps(Number lightMapRes, Number lightMapQuality, int numRadPasses) {
-/*	
-	packer = new LightmapPacker(this);
-	packer->generateTextures(lightMapRes, lightMapQuality);
-	
-	RadTool *radTool = new RadTool(this, packer);
-	radTool->fiatLux(numRadPasses);
-	
-	packer->bindTextures();
-	packer->saveLightmaps("/Users/ivansafrin/Desktop/lightmaps");
-	hasLightmaps = true;
- */
-}
-
-void GenericScene::addGrid(String gridTexture) {
-	ScenePrimitive *gridMesh = new ScenePrimitive(ScenePrimitive::TYPE_PLANE, 20,20,0);
-	gridMesh->loadTexture(gridTexture);
-	gridMesh->setPitch(-90.0f);
-	addEntity(gridMesh);
-}

+ 1 - 0
Core/Contents/Source/PolyMaterial.cpp

@@ -26,6 +26,7 @@ using namespace Polycode;
 
 Material::Material(String name) : Resource(Resource::RESOURCE_MATERIAL) {
 	this->name = name;
+	specularValue = 75.0;
 }
 
 Material::~Material() {

+ 29 - 1
Core/Contents/Source/PolyMaterialManager.cpp

@@ -233,6 +233,8 @@ Material *MaterialManager::materialFromXMLNode(TiXmlNode *node) {
 	vector<ShaderBinding*> newShaderBindings;
 	vector<ShaderRenderTarget*> renderTargets;	
 
+	Material *newMaterial = new Material(mname);
+
 	for (pChild3 = node->FirstChild(); pChild3 != 0; pChild3 = pChild3->NextSibling()) {
 		if(strcmp(pChild3->Value(), "rendertargets") == 0) {
 			for (pChild = pChild3->FirstChild(); pChild != 0; pChild = pChild->NextSibling()) {
@@ -271,6 +273,32 @@ Material *MaterialManager::materialFromXMLNode(TiXmlNode *node) {
 	}
 	
 	for (pChild3 = node->FirstChild(); pChild3 != 0; pChild3 = pChild3->NextSibling()) {
+	
+		if(strcmp(pChild3->Value(), "specularValue") == 0) {
+			newMaterial->specularValue = atof(pChild3->ToElement()->GetText());
+		}
+
+		if(strcmp(pChild3->Value(), "specularColor") == 0) {		
+			String value = pChild3->ToElement()->GetText();
+			vector<String> values = value.split(" ");
+			if(values.size() == 4) {
+				newMaterial->specularColor.setColor(atof(values[0].c_str()), atof(values[1].c_str()), atof(values[2].c_str()),atof(values[3].c_str()));
+			} else {
+				Logger::log("Error: Incorrect number of values for specularColor (%d provided)!\n", values.size());
+			}
+		}
+
+		if(strcmp(pChild3->Value(), "diffuseColor") == 0) {
+			String value = pChild3->ToElement()->GetText();
+			vector<String> values = value.split(" ");
+			if(values.size() == 4) {
+				newMaterial->diffuseColor.setColor(atof(values[0].c_str()), atof(values[1].c_str()), atof(values[2].c_str()),atof(values[3].c_str()));
+			} else {
+				Logger::log("Error: Incorrect number of values for diffuseColor (%d provided)!\n", values.size());
+			}
+
+		}
+		
 		if(strcmp(pChild3->Value(), "shader") == 0) {
 			materialShader = setShaderFromXMLNode(pChild3);
 			if(materialShader) {
@@ -350,7 +378,7 @@ Material *MaterialManager::materialFromXMLNode(TiXmlNode *node) {
 		}
 	}
 	
-	Material *newMaterial = new Material(mname);
+
 	for(int i=0; i< materialShaders.size(); i++) {
 		newMaterial->addShader(materialShaders[i],newShaderBindings[i]);
 	}

+ 146 - 19
Core/Contents/Source/PolyMesh.cpp

@@ -228,6 +228,30 @@ namespace Polycode {
 		
 	}
 	
+	void Mesh::createVPlane(Number w, Number h) { 
+		Polygon *imagePolygon = new Polygon();
+		imagePolygon->addVertex(0,h,0,0,0);	
+		imagePolygon->addVertex(w,h,0, 1, 0);			
+		imagePolygon->addVertex(w,0,0, 1, 1);		
+		imagePolygon->addVertex(0,0,0,0,1);
+
+		addPolygon(imagePolygon);
+		
+		for(int i=0; i < polygons.size(); i++) {
+			for(int j=0; j < polygons[i]->getVertexCount(); j++) {
+				polygons[i]->getVertex(j)->x = polygons[i]->getVertex(j)->x - (w/2.0f);
+				polygons[i]->getVertex(j)->z = polygons[i]->getVertex(j)->y - (h/2.0f);
+			}
+		}
+
+		calculateNormals();
+		arrayDirtyMap[RenderDataArray::VERTEX_DATA_ARRAY] = true;		
+		arrayDirtyMap[RenderDataArray::COLOR_DATA_ARRAY] = true;				
+		arrayDirtyMap[RenderDataArray::TEXCOORD_DATA_ARRAY] = true;						
+		arrayDirtyMap[RenderDataArray::NORMAL_DATA_ARRAY] = true;										
+		
+	}	
+	
 	void Mesh::createPlane(Number w, Number h) { 
 		Polygon *imagePolygon = new Polygon();
 		imagePolygon->addVertex(0,0,h,0,0);	
@@ -358,45 +382,112 @@ namespace Polycode {
 		return total;
 	}
 
+	void Mesh::createTorus(Number radius, Number tubeRadius, int rSegments, int tSegments) {
+	
+		setMeshType(Mesh::TRI_MESH);
+			
+		Vector3 **grid = (Vector3 **) malloc(sizeof(Vector3*) * rSegments);
+		for (int i=0 ; i < rSegments; i++) {
+			grid[i] = (Vector3*) malloc(sizeof(Vector3) * tSegments);		
+		}
+		
+		for (int i=0 ; i < rSegments; i++) {
+			for (int j = 0; j < tSegments; ++j) {
+				Number u = ((Number)i) / rSegments * 2.0 * PI;
+				Number v = ((Number)j) / tSegments * 2.0 * PI;	
+
+				grid[i][j] = Vector3((radius + tubeRadius*cos(v))*cos(u), tubeRadius*sin(v), (radius + tubeRadius*cos(v))*sin(u));							
+													
+			}
+		}	
+		
+		for (int i=0 ; i < rSegments; i++) {
+			for (int j = 0; j < tSegments; ++j) {
+
+				int ip = (i+1) % rSegments;
+				int jp = (j+1) % tSegments;
+					
+				Vector3 a = grid[i ][j];
+				Vector3 b = grid[ip][j];
+				Vector3 c = grid[i ][jp];
+				Vector3 d = grid[ip][jp];
+
+				Vector2 uva = Vector2(((Number)i)     / ((Number)rSegments), ((Number)j)     / ((Number)tSegments));
+				Vector2 uvb = Vector2((((Number)i)+1.0) / ((Number)rSegments), ((Number)j)     / ((Number)tSegments));
+				Vector2 uvc = Vector2(((Number)i)    / ((Number)rSegments), (((Number)j)+1.0) / ((Number)tSegments));
+				Vector2 uvd = Vector2((((Number)i)+1.0) / ((Number)rSegments), (((Number)j)+1.0) / ((Number)tSegments));
+
+
+				Polygon *polygon = new Polygon();
+				polygon->addVertex(c.x, c.y, c.z, uvc.x ,uvc.y);
+				polygon->addVertex(b.x, b.y, b.z, uvb.x ,uvb.y);							
+				polygon->addVertex(a.x, a.y, a.z, uva.x ,uva.y);
+				addPolygon(polygon);	
+
+				polygon = new Polygon();
+				polygon->addVertex(b.x, b.y, b.z, uvb.x ,uvb.y);
+				polygon->addVertex(c.x, c.y, c.z, uvc.x ,uvc.y);					
+				polygon->addVertex(d.x, d.y, d.z, uvd.x ,uvd.y);				
+				addPolygon(polygon);	
+			}
+		}
+		
+		for (int i=0 ; i < rSegments; i++) {
+			free(grid[i]);
+		}		
+		free(grid);
+		
+	
+		calculateNormals();
+		arrayDirtyMap[RenderDataArray::VERTEX_DATA_ARRAY] = true;		
+		arrayDirtyMap[RenderDataArray::COLOR_DATA_ARRAY] = true;				
+		arrayDirtyMap[RenderDataArray::TEXCOORD_DATA_ARRAY] = true;						
+		arrayDirtyMap[RenderDataArray::NORMAL_DATA_ARRAY] = true;										
+				
+	}
+
 	void Mesh::createCylinder(Number height, Number radius, int numSegments) {
 	
 		setMeshType(Mesh::TRI_MESH);
-		Number lastx = -1;
-		Number lastz = -1;		
+		Number lastx = 0;
+		Number lastz = 0;
+		Number lastv = 0;		
 		for (int i=0 ; i < numSegments+1; i++) {
+			Number v = ((Number)i)/((Number)numSegments);
 			Number pos = ((PI*2.0)/((Number)numSegments)) * i;
-			Number x = sinf(pos) * radius;
-			Number z = cosf(pos) * radius;
+			Number x = sin(pos) * radius;
+			Number z = cos(pos) * radius;
 			
-			if(lastx > -1) {
+			if(i > 0) {
 				Polygon *polygon = new Polygon();
-				polygon->addVertex(lastx,0,lastz,0,0);				
-				polygon->addVertex(x,0,z, 1, 0);
-				polygon->addVertex(x,height,z, 1, 1);				
+				polygon->addVertex(lastx,0,lastz,lastv,0);				
+				polygon->addVertex(x,0,z, v, 0);
+				polygon->addVertex(x,height,z, v, 1);				
 				addPolygon(polygon);							
 
 				polygon = new Polygon();	
-				polygon->addVertex(x,height,z, 1, 1);								
-				polygon->addVertex(lastx,height,lastz, 1, 1);																												
-				polygon->addVertex(lastx,0,lastz,0,0);												
+				polygon->addVertex(x,height,z, v, 1);							
+				polygon->addVertex(lastx,height,lastz, lastv, 1);
+				polygon->addVertex(lastx,0,lastz,lastv,0);												
 				addPolygon(polygon);	
 				
 				polygon = new Polygon();	
-				polygon->addVertex(lastx,height,lastz, 1, 1);				
-				polygon->addVertex(x,height,z, 1, 1);														
-				polygon->addVertex(0,height,0,0,0);							
+				polygon->addVertex(lastx,height,lastz, 0.5+(lastz/radius*0.5), 0.5+(lastx/radius*0.5));			
+				polygon->addVertex(x,height,z, 0.5+(z/radius*0.5), 0.5+(x/radius*0.5));														
+				polygon->addVertex(0,height,0,0.5,0.5);							
 				addPolygon(polygon);			
 
 				polygon = new Polygon();	
-				polygon->addVertex(lastx,0,lastz, 1, 1);						
-				polygon->addVertex(0,0,0,0,0);																																					
-				polygon->addVertex(x,0,z, 1, 1);								
+				polygon->addVertex(lastx,0,lastz, 0.5+(lastz/radius*0.5), 0.5+(lastx/radius*0.5));						
+				polygon->addVertex(0,0,0,0.5,0.5);																																					
+				polygon->addVertex(x,0,z, 0.5+(z/radius*0.5), 0.5+(x/radius*0.5));								
 				addPolygon(polygon);			
 
 								
 			}
 			lastx = x;
 			lastz = z;			
+			lastv = v;
 		/*
 			Polygon *polygon = new Polygon();
 			polygon->addVertex(w,0,h, 1, 1);
@@ -546,10 +637,46 @@ namespace Polycode {
 		arrayDirtyMap[RenderDataArray::NORMAL_DATA_ARRAY] = true;										
 	}
 	
-	void Mesh::calculateNormals() {
+	vector<Polygon*> Mesh::getConnectedFaces(Vertex *v) {
+		vector<Polygon*> retVec;	
+		for(int i=0; i < polygons.size(); i++) {
+			bool pushed = false;		
+			for(int j=0; j < polygons[i]->getVertexCount(); j++) {		
+				Vertex *vn =  polygons[i]->getVertex(j);			
+				if(*vn == *v) {
+					if(!pushed) {
+						retVec.push_back(polygons[i]);
+						pushed = true;
+					}
+				}
+			}
+		}
+		return retVec;
+	}
+	
+	void Mesh::calculateNormals(bool smooth, Number smoothAngle) {
 		for(int i =0; i < polygons.size(); i++) {
 			polygons[i]->calculateNormal();
-		}
+		}	
+		
+		if(smooth) {
+			for(int i=0; i < polygons.size(); i++) {
+				for(int j=0; j < polygons[i]->getVertexCount(); j++) {		
+					Vertex *v =  polygons[i]->getVertex(j);
+
+					Vector3 normal;		
+					vector<Polygon*> connectedFaces = getConnectedFaces(v);
+					for(int k=0; k < connectedFaces.size(); k++) {					
+						normal += connectedFaces[k]->getFaceNormal();
+					}					
+					normal = normal / connectedFaces.size();
+					normal.Normalize();
+					v->setNormal(normal.x, normal.y, normal.z);
+				}
+			}
+		
+		} 
+		
 		arrayDirtyMap[RenderDataArray::NORMAL_DATA_ARRAY] = true;										
 	}
 	

+ 8 - 4
Core/Contents/Source/PolyRenderer.cpp

@@ -42,6 +42,7 @@ Renderer::Renderer() : currentTexture(NULL), xRes(0), yRes(0), renderMode(0), or
 	currentFrameBufferTexture = NULL;
 	previousFrameBufferTexture = NULL;
 	fov = 45.0;
+	setAmbientColor(0.0,0.0,0.0);
 	cullingFrontFaces = false;
 }
 
@@ -63,13 +64,13 @@ void Renderer::clearLights() {
 	lights.clear();
 	areaLights.clear();
 	spotLights.clear();
-	shadowMapTextures.clear();
+//	shadowMapTextures.clear();
 }
-
+/*
 void Renderer::addShadowMap(Texture *texture) {
 	shadowMapTextures.push_back(texture);
 }
-
+*/
 void Renderer::setExposureLevel(Number level) {
 	exposureLevel = level;
 }
@@ -123,6 +124,7 @@ void Renderer::addShaderModule(PolycodeShaderModule *module) {
 }
 
 void Renderer::sortLights(){
+
 	LightSorter sorter;
 	sorter.basePosition = (getModelviewMatrix()).getPosition();
 	sorter.cameraMatrix = getCameraMatrix().inverse();	
@@ -130,7 +132,7 @@ void Renderer::sortLights(){
 	sort (spotLights.begin(), spotLights.end(), sorter);	
 }
 
-void Renderer::addLight(Vector3 position, Vector3 direction, int type, Color color, Number constantAttenuation, Number linearAttenuation, Number quadraticAttenuation, Number intensity, Number spotlightCutoff, Number spotlightExponent, bool shadowsEnabled, Matrix4 *textureMatrix) {
+void Renderer::addLight(Vector3 position, Vector3 direction, int type, Color color, Color specularColor, Number constantAttenuation, Number linearAttenuation, Number quadraticAttenuation, Number intensity, Number spotlightCutoff, Number spotlightExponent, bool shadowsEnabled, Matrix4 *textureMatrix,Texture *shadowMapTexture) {
 
 	numLights++;
 	
@@ -139,6 +141,7 @@ void Renderer::addLight(Vector3 position, Vector3 direction, int type, Color col
 		info.textureMatrix = *textureMatrix;
 	}
 	
+	info.shadowMapTexture = shadowMapTexture;
 	info.shadowsEnabled = shadowsEnabled;
 	info.spotlightCutoff = spotlightCutoff;
 	info.spotlightExponent = spotlightExponent;	
@@ -150,6 +153,7 @@ void Renderer::addLight(Vector3 position, Vector3 direction, int type, Color col
 	info.quadraticAttenuation = quadraticAttenuation;
 			
 	info.color.set(color.r, color.g, color.b);
+	info.specularColor = specularColor;
 	info.position = position;
 	lights.push_back(info);
 	switch(type) {

+ 10 - 3
Core/Contents/Source/PolyScene.cpp

@@ -34,6 +34,7 @@ Scene::Scene() : EventDispatcher() {
 	
 	hasLightmaps = false;
 	clearColor.setColor(0.13f,0.13f,0.13f,1.0f); 
+	ambientColor.setColor(0.0,0.0,0.0,1.0);
 	useClearColor = false;	
 }
 
@@ -173,6 +174,7 @@ void Scene::Render(Camera *targetCamera) {
 		direction = light->getConcatenatedMatrix().rotateVector(direction);
 		direction.Normalize();
 		
+		Texture *shadowMapTexture = NULL;
 		if(light->areShadowsEnabled()) {
 			if(light->getType() == SceneLight::SPOT_LIGHT) {
 //				textureMatrix.identity();
@@ -186,7 +188,8 @@ void Scene::Render(Camera *targetCamera) {
 				light->renderDepthMap(this);
 				textureMatrix = light->getLightViewMatrix() * matTexAdj;				
 				matrixPtr = &textureMatrix;				
-				CoreServices::getInstance()->getRenderer()->addShadowMap(light->getZBufferTexture());
+			//	CoreServices::getInstance()->getRenderer()->addShadowMap(light->getZBufferTexture());
+				shadowMapTexture = light->getZBufferTexture();
 			}
 		}
 		
@@ -194,7 +197,7 @@ void Scene::Render(Camera *targetCamera) {
 		if(light->getParentEntity() != NULL) {
 			position = light->getParentEntity()->getConcatenatedMatrix() * position;			
 		}
-		CoreServices::getInstance()->getRenderer()->addLight(position, direction, light->getLightType(), light->lightColor, light->getConstantAttenuation(), light->getLinearAttenuation(), light->getQuadraticAttenuation(), light->getIntensity(), light->getSpotlightCutoff(), light->getSpotlightExponent(), light->areShadowsEnabled(), matrixPtr);
+		CoreServices::getInstance()->getRenderer()->addLight(position, direction, light->getLightType(), light->lightColor, light->specularLightColor, light->getConstantAttenuation(), light->getLinearAttenuation(), light->getQuadraticAttenuation(), light->getIntensity(), light->getSpotlightCutoff(), light->getSpotlightExponent(), light->areShadowsEnabled(), matrixPtr, shadowMapTexture);
 	}	
 	
 	targetCamera->doCameraTransform();
@@ -207,6 +210,8 @@ void Scene::Render(Camera *targetCamera) {
 	CoreServices::getInstance()->getRenderer()->enableFog(fogEnabled);	
 	if(fogEnabled) {
 		CoreServices::getInstance()->getRenderer()->setFogProperties(fogMode, fogColor, fogDensity, fogStartDepth, fogEndDepth);
+	} else {
+		CoreServices::getInstance()->getRenderer()->setFogProperties(fogMode, fogColor, 0.0, fogStartDepth, fogEndDepth);	
 	}
 	
 	
@@ -242,12 +247,14 @@ void Scene::RenderDepthOnly(Camera *targetCamera) {
 	CoreServices::getInstance()->getRenderer()->setTexture(NULL);
 	CoreServices::getInstance()->getRenderer()->enableShaders(false);
 	for(int i=0; i<entities.size();i++) {
+		if(entities[i]->castShadows) {
 		if(entities[i]->getBBoxRadius() > 0) {
 			if(targetCamera->isSphereInFrustrum((entities[i]->getPosition()), entities[i]->getBBoxRadius()))
 				entities[i]->transformAndRender();
 		} else {
 			entities[i]->transformAndRender();		
 		}
+		}
 	}	
 	CoreServices::getInstance()->getRenderer()->enableShaders(true);
 	CoreServices::getInstance()->getRenderer()->cullFrontFaces(false);	
@@ -255,7 +262,7 @@ void Scene::RenderDepthOnly(Camera *targetCamera) {
 
 void Scene::addLight(SceneLight *light) {
 	lights.push_back(light);
-	addEntity(light);
+	addEntity(light);	
 }
 
 SceneLight *Scene::getNearestLight(Vector3 pos) {

+ 1 - 0
Core/Contents/Source/PolySceneEntity.cpp

@@ -25,6 +25,7 @@
 using namespace Polycode;
 
 SceneEntity::SceneEntity() : EventHandler(), Entity() {
+	castShadows = true;
 }
 
 SceneEntity::~SceneEntity() {

+ 39 - 1
Core/Contents/Source/PolySceneLight.cpp

@@ -39,12 +39,39 @@ SceneLight::SceneLight(int type, Scene *parentScene, Number intensity, Number co
 	lightMesh->createBox(0.1,0.1,0.1);
 	bBoxRadius = lightMesh->getRadius();
 	bBox = lightMesh->calculateBBox();
-	shadowMapFOV = 70.0f;
+	shadowMapFOV = 60.0f;
 	zBufferTexture = NULL;
 	spotCamera = NULL;
 	this->parentScene = parentScene;
 	shadowsEnabled = false;
 	lightColor.setColor(1.0f,1.0f,1.0f,1.0f);
+	setSpotlightProperties(40,0.1);
+	
+	/*
+	if(type == SceneLight::SPOT_LIGHT) {
+		lightShape = new ScenePrimitive(ScenePrimitive::TYPE_CONE, 3, 1.0, 8);
+		lightShape->Translate(0,0,-1.5);
+		lightShape->setPitch(90.0);
+		lightShape->setColor(1.0,1.0,0.0, 0.75);
+		lightShape->renderWireframe = true;
+		addChild(lightShape);		
+	} else {
+		lightShape = new ScenePrimitive(ScenePrimitive::TYPE_BOX, 0.5, 0.5, 0.5);
+		lightShape->setColor(1.0,1.0,0.0, 0.75);
+		lightShape->renderWireframe = true;
+		addChild(lightShape);		
+	}
+	lightShape->castShadows = false;
+	lightShape->visible = false;
+	*/
+	
+	lightShape = NULL;
+}
+
+void SceneLight::enableDebugDraw(bool val) {
+	if(lightShape) {
+		lightShape->visible = val;
+	}
 }
 
 void SceneLight::enableShadows(bool val, Number resolution) {
@@ -68,6 +95,17 @@ bool SceneLight::areShadowsEnabled() {
 	return shadowsEnabled;
 }
 
+void SceneLight::setAttenuation(Number constantAttenuation, Number linearAttenuation, Number quadraticAttenuation) {
+	this->constantAttenuation = constantAttenuation;
+	this->linearAttenuation = linearAttenuation;
+	this->quadraticAttenuation = quadraticAttenuation;
+}			
+
+
+void SceneLight::setIntensity(Number newIntensity) {
+	intensity = newIntensity;
+}
+
 void SceneLight::setShadowMapFOV(Number fov) {
 	shadowMapFOV = fov;
 }

+ 13 - 1
Core/Contents/Source/PolyScenePrimitive.cpp

@@ -24,7 +24,7 @@
 
 using namespace Polycode;
 
-ScenePrimitive::ScenePrimitive(int type, Number v1, Number v2, Number v3) : SceneMesh(Mesh::QUAD_MESH) {
+ScenePrimitive::ScenePrimitive(int type, Number v1, Number v2, Number v3,Number v4,Number v5) : SceneMesh(Mesh::QUAD_MESH) {
 
 	switch(type) {
 		case TYPE_PLANE:
@@ -33,6 +33,12 @@ ScenePrimitive::ScenePrimitive(int type, Number v1, Number v2, Number v3) : Scen
 			bBox.y = v2;
 			bBox.z = 0;
 		break;
+		case TYPE_VPLANE:
+			mesh->createVPlane(v1,v2);
+			bBox.x = v1;
+			bBox.y = v2;
+			bBox.z = 0;
+		break;		
 		case TYPE_BOX:
 			mesh->createBox(v1,v2,v3);
 			bBox.x = v1;
@@ -57,6 +63,12 @@ ScenePrimitive::ScenePrimitive(int type, Number v1, Number v2, Number v3) : Scen
 			bBox.y = v1;
 			bBox.z = v2*2;						
 		break;				
+		case TYPE_TORUS:
+			mesh->createTorus(v1,v2,v3,v4);
+			bBox.x = v1*2;
+			bBox.y = v2;
+			bBox.z = v1*2;						
+		break;						
 	}
 }
 

+ 7 - 0
Core/Contents/Source/PolyShader.cpp

@@ -49,6 +49,13 @@ LocalShaderParam *ShaderBinding::getLocalParamByName(String name) {
 	return NULL;
 }
 
+void ShaderBinding::addLocalParam(String name, void *ptr) {
+	LocalShaderParam *newParam = new LocalShaderParam();
+	newParam->name = name;
+	newParam->data = ptr;
+	localParams.push_back(newParam);
+}
+
 void ShaderBinding::addRenderTargetBinding(RenderTargetBinding *binding) {
 	renderTargetBindings.push_back(binding);
 	if(binding->mode == RenderTargetBinding::MODE_IN) {

Разница между файлами не показана из-за своего большого размера
+ 231 - 515
Modules/Build/Mac OS X/Modules.xcodeproj/project.xcworkspace/xcuserdata/ivansafrin.xcuserdatad/UserInterfaceState.xcuserstate


+ 7 - 0
Modules/Contents/2DPhysics/Include/PolyPhysicsScreen.h

@@ -97,6 +97,13 @@ class _PolyExport PhysicsScreenEvent : public Event {
 		* Event sent out when a collision ends
 		*/							
 		static const int EVENT_END_SHAPE_COLLISION = 1;
+		
+		/**
+		* Event sent out when a collision begins
+		*/					
+		static const int EVENT_SOLVE_SHAPE_COLLISION = 3;
+
+		
 };		
 
 

+ 1 - 1
Modules/Contents/2DPhysics/Source/PolyPhysicsScreen.cpp

@@ -82,7 +82,7 @@ void PhysicsScreen::PostSolve(b2Contact* contact, const b2ContactImpulse* impuls
 
 	b2Manifold *manifold = contact->GetManifold();
 	b2Vec2 nor = manifold->localNormal;
-	b2Vec2 point = manifold->localPoint;
+	b2Vec2 point = manifold->points[0].localPoint;
 	
 
 	b2WorldManifold w_manifold;

+ 0 - 20
Player/Build/Mac OS X Standalone/StandalonePlayer/StandalonePlayer/StandalonePlayerAppDelegate.m

@@ -1,20 +0,0 @@
-//
-//  StandalonePlayerAppDelegate.m
-//  StandalonePlayer
-//
-//  Created by Ivan Safrin on 5/25/11.
-//  Copyright 2011 Tomatogon. All rights reserved.
-//
-
-#import "StandalonePlayerAppDelegate.h"
-
-@implementation StandalonePlayerAppDelegate
-
-@synthesize window;
-
-- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
-{
-	// Insert code here to initialize your application
-}
-
-@end

+ 0 - 29
Player/Build/Mac OS X Standalone/StandalonePlayer/StandalonePlayer/en.lproj/Credits.rtf

@@ -1,29 +0,0 @@
-{\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;}
-{\colortbl;\red255\green255\blue255;}
-\paperw9840\paperh8400
-\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural
-
-\f0\b\fs24 \cf0 Engineering:
-\b0 \
-	Some people\
-\
-
-\b Human Interface Design:
-\b0 \
-	Some other people\
-\
-
-\b Testing:
-\b0 \
-	Hopefully not nobody\
-\
-
-\b Documentation:
-\b0 \
-	Whoever\
-\
-
-\b With special thanks to:
-\b0 \
-	Mom\
-}

Разница между файлами не показана из-за своего большого размера
+ 690 - 358
Player/Build/Mac OS X/Polycode Player.xcodeproj/project.xcworkspace/xcuserdata/ivansafrin.xcuserdatad/UserInterfaceState.xcuserstate


Некоторые файлы не были показаны из-за большого количества измененных файлов