Browse Source

Minor optimizations and fixes

Panagiotis Christopoulos Charitos 9 years ago
parent
commit
e844242513
7 changed files with 64 additions and 29 deletions
  1. 35 0
      shaders/Functions.glsl
  2. 5 0
      shaders/Is.frag.glsl
  3. 0 0
      shaders/Is.vert.glsl
  4. 0 15
      shaders/Pps.frag.glsl
  5. 1 1
      src/gr/CMakeLists.txt
  6. 21 11
      src/renderer/Is.cpp
  7. 2 2
      testapp/Main.cpp

+ 35 - 0
shaders/Functions.glsl

@@ -0,0 +1,35 @@
+// Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#ifndef ANKI_SHADERS_FUNCTIONS_GLSL
+#define ANKI_SHADERS_FUNCTIONS_GLSL
+
+//==============================================================================
+vec3 dither(in vec3 col, in float C)
+{
+	vec3 vDither = vec3(dot(vec2(171.0, 231.0), gl_FragCoord.xy));
+	vDither.rgb = fract(vDither.rgb / vec3(103.0, 71.0, 97.0));
+
+	col = col * (255.0 / C) + vDither.rgb;
+	col = floor(col) / 255.0;
+	col *= C;
+
+	return col;
+}
+
+//==============================================================================
+float dither(in float col, in float C)
+{
+	float vDither = dot(vec2(171.0, 231.0), gl_FragCoord.xy);
+	vDither = fract(vDither / 103.0);
+
+	col = col * (255.0 / C) + vDither;
+	col = floor(col) / 255.0;
+	col *= C;
+
+	return col;
+}
+
+#endif

+ 5 - 0
shaders/IsLp.frag.glsl → shaders/Is.frag.glsl

@@ -5,6 +5,7 @@
 
 
 #include "shaders/Pack.glsl"
 #include "shaders/Pack.glsl"
 #include "shaders/Clusterer.glsl"
 #include "shaders/Clusterer.glsl"
+#include "shaders/Functions.glsl"
 
 
 #define LIGHT_SET 0
 #define LIGHT_SET 0
 #define LIGHT_SS_BINDING 0
 #define LIGHT_SS_BINDING 0
@@ -133,6 +134,8 @@ void main()
 		{
 		{
 			shadow = computeShadowFactorOmni(
 			shadow = computeShadowFactorOmni(
 				frag2Light, shadowmapLayerIdx, 1.0 / sqrt(light.posRadius.w));
 				frag2Light, shadowmapLayerIdx, 1.0 / sqrt(light.posRadius.w));
+
+			shadow = dither(shadow, 64.0);
 		}
 		}
 
 
 		out_color +=
 		out_color +=
@@ -160,6 +163,8 @@ void main()
 				fragPos,
 				fragPos,
 				shadowmapLayerIdx,
 				shadowmapLayerIdx,
 				shadowSampleCount);
 				shadowSampleCount);
+
+			shadow = dither(shadow, 64.0);
 		}
 		}
 
 
 		out_color +=
 		out_color +=

+ 0 - 0
shaders/IsLp.vert.glsl → shaders/Is.vert.glsl


+ 0 - 15
shaders/Pps.frag.glsl

@@ -134,21 +134,6 @@ vec3 fog(vec3 colorIn, vec2 uv)
 	return colorIn * (1.0 - t) + u_uniforms.fogColorFogFactor.rgb * t;
 	return colorIn * (1.0 - t) + u_uniforms.fogColorFogFactor.rgb * t;
 }
 }
 
 
-//==============================================================================
-vec3 dither(in vec3 col)
-{
-	const float c0 = 16.0;
-
-	vec3 vDither = vec3(dot(vec2(171.0, 231.0), gl_FragCoord.xy));
-	vDither.rgb = fract(vDither.rgb / vec3(103.0, 71.0, 97.0));
-
-	col = col * (255.0 / c0) + vDither.rgb;
-	col = floor(col) / 255.0;
-	col *= c0;
-
-	return col;
-}
-
 //==============================================================================
 //==============================================================================
 void main()
 void main()
 {
 {

+ 1 - 1
src/gr/CMakeLists.txt

@@ -1,4 +1,4 @@
-file(GLOB ANKI_GR_SOURCES *.cpp)
+file(GLOB ANKI_GR_SOURCES *.cpp common/*.cpp)
 
 
 if(GL)
 if(GL)
 	file(GLOB ANKI_GR_BACKEND_SOURCES gl/*.cpp)
 	file(GLOB ANKI_GR_BACKEND_SOURCES gl/*.cpp)

+ 21 - 11
src/renderer/Is.cpp

@@ -73,8 +73,8 @@ struct ShaderCommonUniforms
 	UVec4 m_tileCount;
 	UVec4 m_tileCount;
 };
 };
 
 
-static const U MAX_TYPED_LIGHTS_PER_CLUSTER = 8;
-static const U MAX_PROBES_PER_CLUSTER = 4;
+static const U MAX_TYPED_LIGHTS_PER_CLUSTER = 16;
+static const U MAX_PROBES_PER_CLUSTER = 8;
 static const F32 INVALID_TEXTURE_INDEX = 128.0;
 static const F32 INVALID_TEXTURE_INDEX = 128.0;
 
 
 class ClusterLightIndex
 class ClusterLightIndex
@@ -146,7 +146,7 @@ static_assert(
 	sizeof(ClusterProbeIndex) == sizeof(U16) * 2, "Because we memcmp");
 	sizeof(ClusterProbeIndex) == sizeof(U16) * 2, "Because we memcmp");
 
 
 /// WARNING: Keep it as small as possible. The number of clusters is huge
 /// WARNING: Keep it as small as possible. The number of clusters is huge
-class ClusterData
+class alignas(U32) ClusterData
 {
 {
 public:
 public:
 	Atomic<U8> m_pointCount;
 	Atomic<U8> m_pointCount;
@@ -164,16 +164,15 @@ public:
 
 
 	void reset()
 	void reset()
 	{
 	{
-		m_pointCount.set(0);
-		m_spotCount.set(0);
-		m_probeCount.set(0);
+		// Set the counts to zero and try to be faster
+		*reinterpret_cast<U32*>(&m_pointCount) = 0;
 	}
 	}
 
 
 	void normalizeCounts()
 	void normalizeCounts()
 	{
 	{
-		m_pointCount.set(m_pointCount.get() % MAX_TYPED_LIGHTS_PER_CLUSTER);
-		m_spotCount.set(m_spotCount.get() % MAX_TYPED_LIGHTS_PER_CLUSTER);
-		m_probeCount.set(m_probeCount.get() % MAX_PROBES_PER_CLUSTER);
+		normalize(m_pointCount, MAX_TYPED_LIGHTS_PER_CLUSTER, "point lights");
+		normalize(m_spotCount, MAX_TYPED_LIGHTS_PER_CLUSTER, "spot lights");
+		normalize(m_probeCount, MAX_PROBES_PER_CLUSTER, "probes");
 	}
 	}
 
 
 	void sortLightIds()
 	void sortLightIds()
@@ -253,6 +252,17 @@ public:
 
 
 		return true;
 		return true;
 	}
 	}
+
+private:
+	static void normalize(Atomic<U8>& count, const U maxCount, CString what)
+	{
+		U8 a = count.get();
+		count.set(a % maxCount);
+		if(a > maxCount)
+		{
+			ANKI_LOGW("Increase cluster limit: %s", &what[0]);
+		}
+	}
 };
 };
 
 
 /// Common data for all tasks.
 /// Common data for all tasks.
@@ -384,10 +394,10 @@ Error Is::initInternal(const ConfigSet& config)
 
 
 	// point light
 	// point light
 	ANKI_CHECK(getResourceManager().loadResourceToCache(
 	ANKI_CHECK(getResourceManager().loadResourceToCache(
-		m_lightVert, "shaders/IsLp.vert.glsl", pps.toCString(), "r_"));
+		m_lightVert, "shaders/Is.vert.glsl", pps.toCString(), "r_"));
 
 
 	ANKI_CHECK(getResourceManager().loadResourceToCache(
 	ANKI_CHECK(getResourceManager().loadResourceToCache(
-		m_lightFrag, "shaders/IsLp.frag.glsl", pps.toCString(), "r_"));
+		m_lightFrag, "shaders/Is.frag.glsl", pps.toCString(), "r_"));
 
 
 	PipelineInitInfo init;
 	PipelineInitInfo init;
 
 

+ 2 - 2
testapp/Main.cpp

@@ -504,8 +504,8 @@ Error initSubsystems(int argc, char* argv[])
 	config.set("is.groundLightEnabled", false);
 	config.set("is.groundLightEnabled", false);
 	config.set("sm.enabled", true);
 	config.set("sm.enabled", true);
 	config.set("sm.maxLights", 16);
 	config.set("sm.maxLights", 16);
-	config.set("sm.poissonEnabled", true);
-	config.set("sm.resolution", 1024);
+	config.set("sm.poissonEnabled", false);
+	config.set("sm.resolution", 512);
 	config.set("lf.maxFlares", 32);
 	config.set("lf.maxFlares", 32);
 	config.set("pps.enabled", true);
 	config.set("pps.enabled", true);
 	config.set("bloom.enabled", true);
 	config.set("bloom.enabled", true);