Browse Source

Fix a bug in chebyshev occlusion

Panagiotis Christopoulos Charitos 7 months ago
parent
commit
7c136222d6

+ 15 - 0
AnKi/Shaders/Functions.hlsl

@@ -892,3 +892,18 @@ vector<T, kComp> linearTextureSampling(Texture3D<Vec4> sam, Vec3 uv)
 
 
 	return o;
 	return o;
 }
 }
+
+/// Generate a 16x MSAA pattern. Returns the numbers in
+/// https://learn.microsoft.com/en-us/windows/win32/api/d3d11/ne-d3d11-d3d11_standard_multisample_quality_levels
+IVec2 generateMsaa16x(U32 sample)
+{
+	const IVec2 packed[2] = {IVec2(0xBDA3C579, 0x3BD67A59), IVec2(0x1EF02486, 0xF48C21E)};
+	const U32 bit = (sample % 8u) * 4u;
+
+	IVec2 pattern = (sample < 8) ? packed[0] : packed[1];
+	pattern >>= bit;
+	pattern &= 0xF;
+	pattern -= 8;
+
+	return pattern;
+}

+ 1 - 1
AnKi/Shaders/ImportanceSampling.hlsl

@@ -145,5 +145,5 @@ vector<T, 3> generateUniformPointOnSphere(TInt sampleIndex, TInt sampleCount, U3
 	const T y = fastSin(theta) * fastSin(phi);
 	const T y = fastSin(theta) * fastSin(phi);
 	const T z = fastCos(theta);
 	const T z = fastCos(theta);
 
 
-	return vector<T, 3>(x, y, z);
+	return normalize(vector<T, 3>(x, y, z));
 }
 }

+ 3 - 3
AnKi/Shaders/IndirectDiffuseClipmaps.ankiprog

@@ -108,7 +108,7 @@ U16 findClipmapOnPosition(Clipmap clipmaps[kIndirectDiffuseClipmapCount], Vec3 c
 
 
 Vec2 generateRandomUv(U32 sampleIdx, U32 sampleCount, U32 frame)
 Vec2 generateRandomUv(U32 sampleIdx, U32 sampleCount, U32 frame)
 {
 {
-	const UVec3 r = rand3DPCG16(UVec3(frame % 16u, frame % 4u, frame % 32u));
+	const UVec3 r = rand3DPCG16(UVec3(frame % 8u, frame % 4u, frame % 16u));
 	return hammersleyRandom16(sampleIdx, sampleCount, r);
 	return hammersleyRandom16(sampleIdx, sampleCount, r);
 }
 }
 
 
@@ -557,7 +557,7 @@ SamplerState g_linearAnyRepeatSampler : register(s0);
 			Vec3 uvw = coords.xzy;
 			Vec3 uvw = coords.xzy;
 			uvw.xy *= distMomentsOctSize + 2.0;
 			uvw.xy *= distMomentsOctSize + 2.0;
 			uvw.xy += 1.0;
 			uvw.xy += 1.0;
-			uvw.xy += octahedronEncode(normal) * distMomentsOctSize;
+			uvw.xy += octahedronEncode(normalize(worldPos - probePosition)) * distMomentsOctSize;
 			uvw.z += 0.5;
 			uvw.z += 0.5;
 			uvw /= distMomentsRealVolumeSize;
 			uvw /= distMomentsRealVolumeSize;
 			const HVec2 distMoments = g_distanceMomentsVolumes[NonUniformResourceIndex(clipmapIdx)].SampleLevel(g_linearAnyRepeatSampler, uvw, 0.0);
 			const HVec2 distMoments = g_distanceMomentsVolumes[NonUniformResourceIndex(clipmapIdx)].SampleLevel(g_linearAnyRepeatSampler, uvw, 0.0);
@@ -576,7 +576,7 @@ SamplerState g_linearAnyRepeatSampler : register(s0);
 				chebyshevWeight = max((chebyshevWeight * chebyshevWeight * chebyshevWeight), 0.0);
 				chebyshevWeight = max((chebyshevWeight * chebyshevWeight * chebyshevWeight), 0.0);
 			}
 			}
 
 
-			w *= chebyshevWeight;
+			w *= max(0.05, chebyshevWeight);
 		}
 		}
 
 
 		// Compute the actual coords
 		// Compute the actual coords