Browse Source

Some fixes

Panagiotis Christopoulos Charitos 3 months ago
parent
commit
7b222af46d

+ 21 - 12
AnKi/Shaders/GpuVisibilityStage2And3.ankiprog

@@ -20,6 +20,9 @@
 
 #define NUMTHREADS 64u
 
+// ===========================================================================
+// Legacy                                                                    =
+// ===========================================================================
 #if ANKI_TECHNIQUE_Legacy
 struct DrawIndirectArgsWithPadding
 {
@@ -126,6 +129,9 @@ RWStructuredBuffer<U32> g_outOfMemoryBuffer : register(u4);
 
 #endif // ANKI_TECHNIQUE_Legacy
 
+// ===========================================================================
+// Meshlets                                                                  =
+// ===========================================================================
 #if ANKI_TECHNIQUE_Meshlets
 
 #	define MESHLET_BACKFACE_CULLING 0 // Doesn't work correctly for some reason
@@ -173,16 +179,21 @@ Bool cullMeshlet(GpuSceneRenderable renderable, const MeshletBoundingVolume mesh
 {
 	meshletCulledByHzb = false;
 
-#	if !PASSTHROUGH
+	const Bool bSkin = renderable.m_boneTransformsOffset != 0u;
+	if(PASSTHROUGH || bSkin)
+	{
+		return false;
+	}
+
 	const Mat3x4 worldTransform = SBUFF(g_transforms, renderable.m_worldTransformsIndex);
 
-#		if MESHLET_BACKFACE_CULLING
+#	if MESHLET_BACKFACE_CULLING
 	const Vec4 coneDirAndAng = unpackSnorm4x8(meshletBoundingVol.m_coneDirection_R8G8B8_Snorm_cosHalfAngle_R8_Snorm);
 	if(cullBackfaceMeshlet(coneDirAndAng.xyz, coneDirAndAng.w, meshletBoundingVol.m_coneApex, worldTransform, g_consts.m_cameraPos))
 	{
 		return true;
 	}
-#		endif
+#	endif
 
 	const Mat4 wordTransform4 = {worldTransform.m_row0, worldTransform.m_row1, worldTransform.m_row2, Vec4(0.0f, 0.0f, 0.0f, 1.0f)};
 	const Mat4 mvp = mul(g_consts.m_viewProjectionMatrix, wordTransform4);
@@ -191,15 +202,15 @@ Bool cullMeshlet(GpuSceneRenderable renderable, const MeshletBoundingVolume mesh
 	F32 aabbMinDepth;
 	projectAabb(meshletBoundingVol.m_aabbMin, meshletBoundingVol.m_aabbMax, mvp, minNdc, maxNdc, aabbMinDepth);
 
-#		if MESHLET_OUTSIDE_OF_SCREEN_CULLING
+#	if MESHLET_OUTSIDE_OF_SCREEN_CULLING
 	// Outside of the screen
 	if(any(minNdc > 1.0f) || any(maxNdc < -1.0f))
 	{
 		return true;
 	}
-#		endif
+#	endif
 
-#		if MESHLET_NO_SAMPLING_POINT_CULLING
+#	if MESHLET_NO_SAMPLING_POINT_CULLING
 	// Sampling points test
 	const Vec2 windowCoordsMin = ndcToUv(minNdc) * g_consts.m_viewportSizef;
 	const Vec2 windowCoordsMax = ndcToUv(maxNdc) * g_consts.m_viewportSizef;
@@ -207,14 +218,12 @@ Bool cullMeshlet(GpuSceneRenderable renderable, const MeshletBoundingVolume mesh
 	{
 		return true;
 	}
-#		endif
+#	endif
 
-#		if MESHLET_HZB_CULLING
-	meshletCulledByHzb = (renderable.m_boneTransformsOffset == 0u && cullHzb(minNdc, maxNdc, aabbMinDepth, g_hzbTexture, g_nearestClampSampler));
+#	if MESHLET_HZB_CULLING
+	meshletCulledByHzb = cullHzb(minNdc, maxNdc, aabbMinDepth, g_hzbTexture, g_nearestClampSampler);
 	return meshletCulledByHzb;
-#		endif
-
-#	endif // !PASSTHROUGH
+#	endif
 
 	return false;
 }

+ 3 - 2
AnKi/Shaders/IndirectDiffuseClipmaps.ankiprog

@@ -38,6 +38,7 @@
 
 constexpr F32 kGaussianSigma = 0.55;
 constexpr F32 kMaxBilateralSamplesPerDirection = 5.0;
+constexpr Bool kLocalLightShadow = false;
 
 // ===========================================================================
 // RtMaterialFetch                                                           =
@@ -95,7 +96,7 @@ ANKI_FAST_CONSTANTS(Consts, g_consts)
 	else
 	{
 		const Vec3 hitPos = probeWorldPos + dir * (rayT - 0.01);
-		radiance = directLighting<F16>(gbuffer, hitPos, !hit, true, tMax, traceFlags | RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCH);
+		radiance = directLighting<F16>(gbuffer, hitPos, !hit, true, tMax, kLocalLightShadow, traceFlags | RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCH);
 
 		// Apply indirect
 		constexpr SampleClipmapFlag flags =
@@ -165,7 +166,7 @@ ANKI_FAST_CONSTANTS(Consts, g_consts)
 	if(hit)
 	{
 		hitPos = biasedWorldPos + rayDir * (rayT - 0.01);
-		radiance = directLighting<F16>(gbuffer, hitPos, !hit, true, 1000.0, traceFlags | RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCH);
+		radiance = directLighting<F16>(gbuffer, hitPos, !hit, true, 1000.0, kLocalLightShadow, traceFlags | RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCH);
 	}
 
 	Vec3 rayOrigin;

+ 1 - 1
AnKi/Shaders/Reflections.ankiprog

@@ -739,7 +739,7 @@ vector<T, 3> getDiffuseIndirect(Vec3 worldPos, Vec3 worldNormal)
 	const Vec3 hitPos = worldPos + reflDir * rayT;
 
 	// Do simple light shading
-	HVec3 radiance = directLighting(gbuffer, hitPos, hasHitSky, kTryShadowmapFirst, g_consts.m_maxRayT);
+	HVec3 radiance = directLighting(gbuffer, hitPos, hasHitSky, kTryShadowmapFirst, g_consts.m_maxRayT, false);
 
 	if(!hasHitSky)
 	{

+ 24 - 11
AnKi/Shaders/RtMaterialFetch.hlsl

@@ -121,8 +121,24 @@ Bool materialRayTrace(Vec3 rayOrigin, Vec3 rayDir, F32 tMin, F32 tMax, T texture
 	return !hasHitSky;
 }
 
+Bool rayVisibility(Vec3 rayOrigin, Vec3 rayDir, F32 tMax, U32 traceFlags)
+{
+	RayQuery<RAY_FLAG_NONE> q;
+	const U32 cullMask = 0xFFu;
+	RayDesc ray;
+	ray.Origin = rayOrigin;
+	ray.TMin = 0.01;
+	ray.Direction = rayDir;
+	ray.TMax = tMax;
+	q.TraceRayInline(g_tlas, traceFlags, cullMask, ray);
+	q.Proceed();
+	const Bool hit = q.CommittedStatus() == COMMITTED_TRIANGLE_HIT;
+
+	return hit;
+}
+
 template<typename T>
-vector<T, 3> directLighting(GBufferLight<T> gbuffer, Vec3 hitPos, Bool isSky, Bool tryShadowmapFirst, F32 shadowTMax,
+vector<T, 3> directLighting(GBufferLight<T> gbuffer, Vec3 hitPos, Bool isSky, Bool tryShadowmapFirst, F32 shadowTMax, Bool doLocalLightShadow,
 							U32 traceFlags = RAY_FLAG_FORCE_OPAQUE | RAY_FLAG_SKIP_PROCEDURAL_PRIMITIVES | RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCH)
 {
 	vector<T, 3> color = gbuffer.m_emission;
@@ -155,16 +171,7 @@ vector<T, 3> directLighting(GBufferLight<T> gbuffer, Vec3 hitPos, Bool isSky, Bo
 			}
 			else
 			{
-				RayQuery<RAY_FLAG_NONE> q;
-				const U32 cullMask = 0xFFu;
-				RayDesc ray;
-				ray.Origin = hitPos;
-				ray.TMin = 0.01;
-				ray.Direction = -dirLight.m_direction;
-				ray.TMax = shadowTMax;
-				q.TraceRayInline(g_tlas, traceFlags, cullMask, ray);
-				q.Proceed();
-				shadow = (q.CommittedStatus() == COMMITTED_TRIANGLE_HIT) ? 0.0 : 1.0;
+				shadow = rayVisibility(hitPos, -dirLight.m_direction, shadowTMax, traceFlags) ? 0.0 : 1.0;
 			}
 		}
 
@@ -206,6 +213,12 @@ vector<T, 3> directLighting(GBufferLight<T> gbuffer, Vec3 hitPos, Bool isSky, Bo
 				attenuation *= computeSpotFactor(nFrag2Light, light.m_outerCos, light.m_innerCos, light.m_direction);
 			}
 
+			if(attenuation > kEpsilonF32 && doLocalLightShadow)
+			{
+				const F32 shadowFactor = rayVisibility(hitPos, nFrag2Light, length(frag2Light) - 0.1, traceFlags) ? 0.0 : 1.0;
+				attenuation *= shadowFactor;
+			}
+
 			const T lambert = max(T(0), dot(nFrag2Light, gbuffer.m_worldNormal));
 			const vector<T, 3> diffC = diffuseLobe(gbuffer.m_diffuse);
 			color += diffC * light.m_diffuseColor * lambert * attenuation * gridEdgesAttenuation;

+ 1 - 1
AnKi/Shaders/RtMaterialFetchDbg.ankiprog

@@ -44,7 +44,7 @@
 	else
 	{
 		// col = gbuffer.m_diffuse * 1.0 + (gbuffer.m_worldNormal / 2.0 + 0.5) * 0.0 + rayT * 0.0 + gbuffer.m_emission * 0.0;
-		col = directLighting(gbuffer, rayOrigin + rayDir * rayT, false, true, 100.0);
+		col = directLighting(gbuffer, rayOrigin + rayDir * rayT, false, true, 100.0, true);
 		col += gbuffer.m_diffuse * 0.3;
 	}