Browse Source

Improve SS raymarching. Optimize

Panagiotis Christopoulos Charitos 5 years ago
parent
commit
1367b85d6f
2 changed files with 18 additions and 15 deletions
  1. 3 1
      shaders/LightFunctions.glsl
  2. 15 14
      shaders/SsRaymarching.glsl

+ 3 - 1
shaders/LightFunctions.glsl

@@ -218,7 +218,9 @@ F32 computeShadowFactorPointLight(PointLight light, Vec3 frag2Light, texture2D s
 F32 computeShadowFactorDirLight(
 F32 computeShadowFactorDirLight(
 	DirectionalLight light, U32 cascadeIdx, Vec3 worldPos, texture2D shadowMap, sampler shadowMapSampler)
 	DirectionalLight light, U32 cascadeIdx, Vec3 worldPos, texture2D shadowMap, sampler shadowMapSampler)
 {
 {
-#if defined(ANKI_VENDOR_NVIDIA)
+#define ANKI_FAST_CASCADES_WORKAROUND 1 // Doesn't make sense but it's super fast
+
+#if ANKI_FAST_CASCADES_WORKAROUND
 	// Assumes MAX_SHADOW_CASCADES is 4
 	// Assumes MAX_SHADOW_CASCADES is 4
 	Mat4 lightProjectionMat;
 	Mat4 lightProjectionMat;
 	switch(cascadeIdx)
 	switch(cascadeIdx)

+ 15 - 14
shaders/SsRaymarching.glsl

@@ -190,8 +190,8 @@ void raymarchGroundTruth(Vec3 rayOrigin, // Ray origin in view space
 	dir = normalize(dir);
 	dir = normalize(dir);
 
 
 	// Compute step
 	// Compute step
-	U32 stepSkip = bigStep;
-	U32 step = randInitialStep;
+	I32 stepSkip = I32(bigStep);
+	I32 step = I32(randInitialStep);
 
 
 	// Iterate
 	// Iterate
 	Vec3 origin;
 	Vec3 origin;
@@ -213,23 +213,24 @@ void raymarchGroundTruth(Vec3 rayOrigin, // Ray origin in view space
 		}
 		}
 		else if(stepSkip > 1)
 		else if(stepSkip > 1)
 		{
 		{
-			step -= bigStep - 1u;
-			stepSkip = 1u;
+			step = max(1, step - stepSkip + 1);
+			stepSkip = stepSkip / 2;
 		}
 		}
 		else
 		else
 		{
 		{
 			// Found it
 			// Found it
+
+			// Compute attenuation
+			const F32 blackMargin = 0.05 / 4.0;
+			const F32 whiteMargin = 0.1 / 2.0;
+			const Vec2 marginAttenuation2d = smoothstep(blackMargin, whiteMargin, origin.xy)
+											* (1.0 - smoothstep(1.0 - whiteMargin, 1.0 - blackMargin, origin.xy));
+			const F32 marginAttenuation = marginAttenuation2d.x * marginAttenuation2d.y;
+			attenuation = marginAttenuation * cameraContribution;
+
+			// ...and hit point
+			hitPoint = origin;
 			break;
 			break;
 		}
 		}
 	}
 	}
-
-	// Write the values
-	const F32 blackMargin = 0.05 / 4.0;
-	const F32 whiteMargin = 0.1 / 2.0;
-	const Vec2 marginAttenuation2d = smoothstep(blackMargin, whiteMargin, origin.xy)
-									 * (1.0 - smoothstep(1.0 - whiteMargin, 1.0 - blackMargin, origin.xy));
-	const F32 marginAttenuation = marginAttenuation2d.x * marginAttenuation2d.y;
-	attenuation = marginAttenuation * cameraContribution;
-
-	hitPoint = origin;
 }
 }