Cleaned GLSL shaders

Cleaned GLSL shaders

diff --git a/src/engine/GPURenderer/renderProgs/lightall.fragment b/src/engine/GPURenderer/renderProgs/lightall.fragment
index 17b8d63..e986b0d 100644
--- a/src/engine/GPURenderer/renderProgs/lightall.fragment
+++ b/src/engine/GPURenderer/renderProgs/lightall.fragment
@@ -1,10 +1,8 @@
 uniform sampler2D u_DiffuseMap;
-uniform vec4   u_Local1; // 0, 0, 0, 0
-varying vec4	var_Local1; // 0, 0, 0, 0
-varying vec4	var_Local2; // surfaceType, 0, 0, 0
-varying vec2	var_Dimensions;
-
-//#define SPHERICAL_HARMONICS
+uniform vec4 u_Local1; // 0, 0, 0, 0
+varying vec4 var_Local1; // 0, 0, 0, 0
+varying vec4 var_Local2; // surfaceType, 0, 0, 0
+varying vec2 var_Dimensions;
 
 #if defined(USE_LIGHTMAP)
 uniform sampler2D u_LightMap;
@@ -87,7 +85,6 @@ varying vec4      var_PrimaryLightDir;
 #define EPSILON 0.00000001
 
 #if defined(USE_PARALLAXMAP)
-  #if defined(USE_PARALLAXMAP)
 	float SampleDepth(sampler2D normalMap, vec2 t)
 	{
 		#if defined(SWIZZLE_NORMALMAP)
@@ -96,67 +93,66 @@ varying vec4      var_PrimaryLightDir;
 			return 1.0 - texture2D(normalMap, t).a;
 		#endif
 	}
-  #endif //USE_PARALLAXMAP
 
-float RayIntersectDisplaceMap(vec2 dp, vec2 ds, sampler2D normalMap)
-{
-	const int linearSearchSteps = 16;
-	const int binarySearchSteps = 6;
+	float RayIntersectDisplaceMap(vec2 dp, vec2 ds, sampler2D normalMap)
+	{
+		const int linearSearchSteps = 16;
+		const int binarySearchSteps = 6;
 
-	// current size of search window
-	float size = 1.0 / float(linearSearchSteps);
+		// current size of search window
+		float size = 1.0 / float(linearSearchSteps);
 
-	// current depth position
-	float depth = 0.0;
+		// current depth position
+		float depth = 0.0;
 
-	// best match found (starts with last position 1.0)
-	float bestDepth = 1.0;
+		// best match found (starts with last position 1.0)
+		float bestDepth = 1.0;
 
-	// texture depth at best depth
-	float texDepth = 0.0;
+		// texture depth at best depth
+		float texDepth = 0.0;
 
-	float prevT = SampleDepth(normalMap, dp);
-	float prevTexDepth = prevT;
+		float prevT = SampleDepth(normalMap, dp);
+		float prevTexDepth = prevT;
 
-	// search front to back for first point inside object
-	for(int i = 0; i < linearSearchSteps - 1; ++i)
-	{
-		depth += size;
-		
-		float t = SampleDepth(normalMap, dp + ds * depth);
-		
-		if(bestDepth > 0.996)		// if no depth found yet
+		// search front to back for first point inside object
+		for(int i = 0; i < linearSearchSteps - 1; ++i)
+		{
+			depth += size;
+			
+			float t = SampleDepth(normalMap, dp + ds * depth);
+			
+			if(bestDepth > 0.996)		// if no depth found yet
+				if(depth >= t)
+				{
+					bestDepth = depth;	// store best depth
+					texDepth = t;
+					prevTexDepth = prevT;
+				}
+			prevT = t;
+		}
+
+		depth = bestDepth;
+
+	#if !defined (USE_RELIEFMAP)
+		float div = 1.0 / (1.0 + (prevTexDepth - texDepth) * float(linearSearchSteps));
+		bestDepth -= (depth - size - prevTexDepth) * div;
+	#else
+		// recurse around first point (depth) for closest match
+		for(int i = 0; i < binarySearchSteps; ++i)
+		{
+			size *= 0.5;
+
+			float t = SampleDepth(normalMap, dp + ds * depth);
+			
 			if(depth >= t)
 			{
-				bestDepth = depth;	// store best depth
-				texDepth = t;
-				prevTexDepth = prevT;
+				bestDepth = depth;
+				depth -= 2.0 * size;
 			}
-		prevT = t;
-	}
-
-	depth = bestDepth;
 
-#if !defined (USE_RELIEFMAP)
-	float div = 1.0 / (1.0 + (prevTexDepth - texDepth) * float(linearSearchSteps));
-	bestDepth -= (depth - size - prevTexDepth) * div;
-#else
-	// recurse around first point (depth) for closest match
-	for(int i = 0; i < binarySearchSteps; ++i)
-	{
-		size *= 0.5;
-
-		float t = SampleDepth(normalMap, dp + ds * depth);
-		
-		if(depth >= t)
-		{
-			bestDepth = depth;
-			depth -= 2.0 * size;
+			depth += size;
 		}
-
-		depth += size;
-	}
-#endif
+	#endif
 
 	return bestDepth;
 }
@@ -191,9 +187,9 @@ float LightRay(vec2 dp, vec2 ds, sampler2D normalMap)
 }
 #endif
 
-vec3 CalcDiffuse(vec3 diffuseAlbedo, float NH, float EH, float roughness) 
+vec3 CalcDiffuse(vec3 diffuseAlbedo, float NH, float EH, float roughness, float ao) 
 {
-	return diffuseAlbedo;
+	return diffuseAlbedo * ao;
 }
 
 vec2 GetParallaxOffset(in vec2 texCoords, in vec3 E, in mat3 tangentToWorld )
@@ -210,32 +206,32 @@ vec2 GetParallaxOffset(in vec2 texCoords, in vec3 E, in mat3 tangentToWorld )
 
 float spec_D( float NH, float roughness)
 {
-  // normal distribution
-  // from http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf
-  float alpha = roughness * roughness;
-  float quotient = alpha / max(1e-8,(NH*NH*(alpha*alpha-1.0)+1.0));
-  return (quotient * quotient) / M_PI;
+	// normal distribution
+	// from http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf
+	float alpha = roughness * roughness;
+	float quotient = alpha / max(1e-8,(NH*NH*(alpha*alpha-1.0)+1.0));
+	return (quotient * quotient) / M_PI;
 }
 
 vec3 spec_F( float EH, vec3 F0)
 {
-  // Fresnel
-  // from http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf
-  float pow2 = pow(2.0, (-5.55473*EH - 6.98316) * EH);
-  return F0 + (vec3(1.0) - F0) * pow2;
+	// Fresnel
+	// from http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf
+	float pow2 = pow(2.0, (-5.55473*EH - 6.98316) * EH);
+	return F0 + (vec3(1.0) - F0) * pow2;
 }
 
 float G1(float NV, float k)
 {
-  return NV / (NV*(1.0-k) +  k);
+	return NV / (NV*(1.0-k) +  k);
 }
 
 float spec_G(float NL, float NE, float roughness )
 {
-  // GXX Schlick
-  // from http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf
-  float k = max(((roughness + 1.0) * (roughness + 1.0)) / 8.0, 1e-5);
-  return G1(NL,k)*G1(NE,k);
+	// GXX Schlick
+	// from http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf
+	float k = max(((roughness + 1.0) * (roughness + 1.0)) / 8.0, 1e-5);
+	return G1(NL,k)*G1(NE,k);
  }
 
 vec3 CalcSpecular(vec3 specular, float NH, in float NL, in float NE, float EH, float roughness)
@@ -263,38 +259,6 @@ float CalcLightAttenuation(float distance, float radius)
 	return clamp(attenuation, 0.0, 1.0);
 }
 
-#ifdef SPHERICAL_HARMONICS
-vec3 sphericalHarmonics(vec3 normal)
-{
-   const float C1 = 0.429043;
-   const float C2 = 0.511664;
-   const float C3 = 0.743125;
-   const float C4 = 0.886227;
-   const float C5 = 0.247708;
-   
-   const vec3 L00  = vec3( 0.6841148,  0.6929004,  0.7069543);
-   const vec3 L1m1 = vec3( 0.3173355,  0.3694407,  0.4406839);
-   const vec3 L10  = vec3(-0.1747193, -0.1737154, -0.1657420);
-   const vec3 L11  = vec3(-0.4496467, -0.4155184, -0.3416573);
-   const vec3 L2m2 = vec3(-0.1690202, -0.1703022, -0.1525870);
-   const vec3 L2m1 = vec3(-0.0837808, -0.0940454, -0.1027518);
-   const vec3 L20  = vec3(-0.0319670, -0.0214051, -0.0147691);
-   const vec3 L21  = vec3( 0.1641816,  0.1377558,  0.1010403);
-   const vec3 L22  = vec3( 0.3697189,  0.3097930,  0.2029923);
-   
-   return C1 * L22 * (normal.x * normal.x - normal.y * normal.y) +
-          C3 * L20 * normal.z * normal.z +
-          C4 * L00 -
-          C5 * L20 +
-          2.0 * C1 * L2m2 * normal.x * normal.y +
-          2.0 * C1 * L21  * normal.x * normal.z +
-          2.0 * C1 * L2m1 * normal.y * normal.z +
-          2.0 * C2 * L11  * normal.x +
-          2.0 * C2 * L1m1 * normal.y +
-          2.0 * C2 * L10  * normal.z;
-}
-#endif //SPHERICAL_HARMONICS
-
 vec4 hitCube(vec3 ray, vec3 pos, vec3 invSize, float lod, samplerCube tex)
 {
 	// find any hits on cubemap faces facing the camera
@@ -331,35 +295,37 @@ void main()
 	vec3 L, N, E, H;
 	float NL, NH, NE, EH, attenuation;
 	vec4 specular = vec4(0.0);
-	vec3 DETAILED_NORMAL = vec3(1.0);
 	
-#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
-	mat3 tangentToWorld = mat3(var_Tangent.xyz, var_Bitangent.xyz, var_Normal.xyz);

[... diff too long, it was truncated ...]

GitHub
sha: c922b229