Ver Fonte

Small optimizations

Panagiotis Christopoulos Charitos há 10 anos atrás
pai
commit
53f38024c1
4 ficheiros alterados com 40 adições e 23 exclusões
  1. 4 4
      shaders/ImageReflections.glsl
  2. 28 12
      shaders/LightFunctions.glsl
  3. 7 6
      src/renderer/Ir.cpp
  4. 1 1
      testapp/Main.cpp

+ 4 - 4
shaders/ImageReflections.glsl

@@ -36,7 +36,7 @@ layout(std430, row_major, SS_BINDING(IMAGE_REFLECTIONS_SET,
 layout(std430, row_major, SS_BINDING(IMAGE_REFLECTIONS_SET,
 	IMAGE_REFLECTIONS_FIRST_SS_BINDING + 2)) readonly buffer _irs3
 {
-	uint u_reflectionClusters[];
+	uvec2 u_reflectionClusters[];
 };
 
 layout(TEX_BINDING(IMAGE_REFLECTIONS_SET, IMAGE_REFLECTIONS_TEX_BINDING))
@@ -80,9 +80,9 @@ vec3 readReflection(in uint clusterIndex, in vec3 posVSpace,
 	vec3 r = reflect(eye, normalVSpace);
 
 	// Check proxy
-	uint cluster = u_reflectionClusters[clusterIndex];
-	uint indexOffset = cluster >> 16u;
-	uint indexCount = cluster & 0xFFFFu;
+	uvec2 cluster = u_reflectionClusters[clusterIndex];
+	uint indexOffset = cluster[0];
+	uint indexCount = cluster[1];
 	for(uint i = 0; i < indexCount; ++i)
 	{
 		uint probeIndex = u_reflectionProbeIndices[indexOffset++];

+ 28 - 12
shaders/LightFunctions.glsl

@@ -49,23 +49,39 @@ vec3 computeSpecularColorBrdf(
 {
 	vec3 h = normalize(l + v);
 
-	// Fresnel (Schlick)
-	float loh = max(EPSILON, dot(l, h));
-	vec3 f = specCol + (1.0 - specCol) * pow((1.0 + EPSILON - loh), 5.0);
-	//float f = specColor + (1.0 - specColor)
-	//	* pow(2.0, (-5.55473 * loh - 6.98316) * loh);
+	// Fresnel
+	float voh = max(EPSILON, dot(v, h));
+#if 0
+	// Schlick
+	vec3 F = specCol + (1.0 - specCol) * pow((1.0 + EPSILON - loh), 5.0);
+#else
+	// Unreal
+	vec3 F = specCol + (1.0 - specCol)
+		* pow(2.0, (-5.55473 * voh - 6.98316) * voh);
+#endif
 
-	// NDF: GGX Trowbridge-Reitz
+	// D(n,h) aka NDF: GGX Trowbridge-Reitz
 	float noh = max(EPSILON, dot(n, h));
-	float d = a2 / (PI * pow(noh * noh * (a2 - 1.0) + 1.0, 2.0));
+	float D = noh * noh * (a2 - 1.0) + 1.0;
+	D = a2 / (PI * D * D);
 
-	// Visibility term: Geometric shadowing devided by BRDF denominator
+	// G(l,v,h)/(4*dot(n,h)*dot(n,v)) aka Visibility term: Geometric shadowing
+	// divided by BRDF denominator
+#if 0
 	float nov = max(EPSILON, dot(n, v));
-	float vv = nov + sqrt((nov - nov * a2) * nov + a2);
-	float vl = nol + sqrt((nol - nol * a2) * nol + a2);
-	float vis = 1.0 / (vv * vl);
+	float V_v = nov + sqrt((nov - nov * a2) * nov + a2);
+	float V_l = nol + sqrt((nol - nol * a2) * nol + a2);
+	float V = 1.0 / (V_l * V_v);
+#else
+	float k = (a2 + 1.0);
+	k = k * k / 8.0;
+	float nov = max(EPSILON, dot(n, v));
+	float V_v = nov * (1.0 - k) + k;
+	float V_l = nol * (1.0 - k) + k;
+	float V = 1.0 / (4.0 * V_l * V_v);
+#endif
 
-	return f * (vis * d) * lightSpecCol;
+	return F * (V * D) * lightSpecCol;
 }
 
 //==============================================================================

+ 7 - 6
src/renderer/Ir.cpp

@@ -30,9 +30,8 @@ struct ShaderReflectionProbe
 
 struct ShaderCluster
 {
-	/// If m_combo = 0xFFFFAAAA then FFFF is the probe index offset, AAAA the
-	/// number of probes
-	U32 m_combo;
+	U32 m_indexOffset;
+	U32 m_probeCount;
 };
 
 static const U MAX_PROBES_PER_CLUSTER = 16;
@@ -283,12 +282,13 @@ void Ir::populateIndexAndClusterBuffers(IrBuildContext& ctx)
 			if(i > 0 && cdata == ctx.m_clusterData[i - 1])
 			{
 				// Same data
-				cluster.m_combo = clusters[i - 1].m_combo;
+				cluster = clusters[i - 1];
 			}
 			else
 			{
 				// Have to store the indices
-				cluster.m_combo = (indexCount << 16) | cdata.m_probeCount;
+				cluster.m_indexOffset = indexCount;
+				cluster.m_probeCount = cdata.m_probeCount;
 				for(U j = 0; j < cdata.m_probeCount; ++j)
 				{
 					indices[indexCount] = cdata.m_probeIds[j].m_index;
@@ -298,7 +298,8 @@ void Ir::populateIndexAndClusterBuffers(IrBuildContext& ctx)
 		}
 		else
 		{
-			cluster.m_combo = 0;
+			cluster.m_indexOffset = 0;
+			cluster.m_probeCount = 0;
 		}
 	}
 }

+ 1 - 1
testapp/Main.cpp

@@ -486,7 +486,7 @@ Error initSubsystems(int argc, char* argv[])
 	config.set("is.sm.poissonEnabled", true);
 	config.set("is.sm.resolution", 1024);
 	config.set("lf.maxFlares", 32);
-	config.set("pps.enabled", true);
+	config.set("pps.enabled", false);
 	config.set("pps.bloom.enabled", true);
 	config.set("pps.bloom.renderingQuality", 0.5);
 	config.set("pps.bloom.blurringDist", 1.0);