Browse Source

Improve debug drawing

Panagiotis Christopoulos Charitos 5 years ago
parent
commit
ffcda272d1
2 changed files with 33 additions and 9 deletions
  1. 5 2
      shaders/SceneDebug.ankiprog
  2. 28 7
      src/anki/scene/ModelNode.cpp

+ 5 - 2
shaders/SceneDebug.ankiprog

@@ -39,6 +39,7 @@ void main()
 
 #pragma anki start frag
 #include <shaders/Common.glsl>
+#include <shaders/ImportanceSampling.glsl>
 
 #if COLOR_TEXTURE == 1
 layout(location = 0) in Vec2 in_uv;
@@ -58,11 +59,13 @@ void main()
 {
 	// Check if we should skip the frag
 #if DITHERED_DEPTH_TEST == 1
+	const UVec2 random = rand3DPCG16(UVec3(UVec2(gl_FragCoord.xy), 1)).xy;
+	const Vec2 noise = Vec2(random) / 65536.0;
+	const F32 factor = noise.x * noise.y;
 	const Vec2 uv = gl_FragCoord.xy / Vec2(textureSize(u_depthRt, 0));
 	const F32 depthRef = textureLod(u_depthRt, u_nearestAnyClampSampler, uv, 0.0).r;
 	const Bool depthTestFailed = gl_FragCoord.z >= depthRef;
-	const IVec2 fragCoordi = IVec2(gl_FragCoord.xy);
-	if(depthTestFailed && ((fragCoordi.x + fragCoordi.y) % 8) != 0)
+	if(depthTestFailed && factor < 0.5)
 	{
 		discard;
 	}

+ 28 - 7
src/anki/scene/ModelNode.cpp

@@ -254,7 +254,9 @@ void ModelNode::draw(RenderQueueDrawContext& ctx, ConstWeakArray<void*> userData
 			SkeletonResourcePtr skeleton = skinc.getSkeleronResource();
 			const U32 boneCount = skinc.getBoneTransforms().getSize();
 
-			Vec3* lines = ctx.m_frameAllocator.newArray<Vec3>(boneCount * 2);
+			DynamicArrayAuto<Vec3> lines(ctx.m_frameAllocator);
+			lines.resizeStorage(boneCount * 2);
+			DynamicArrayAuto<Vec3> chidlessLines(ctx.m_frameAllocator);
 			for(U32 i = 0; i < boneCount; ++i)
 			{
 				const Bone& bone = skeleton->getBones()[i];
@@ -264,21 +266,40 @@ void ModelNode::draw(RenderQueueDrawContext& ctx, ConstWeakArray<void*> userData
 				Mat4 m = (parent)
 							 ? skinc.getBoneTransforms()[parent->getIndex()] * parent->getVertexTransform().getInverse()
 							 : Mat4::getIdentity();
-				lines[i * 2] = (m * point).xyz();
+				const Vec3 a = (m * point).xyz();
+
 				m = skinc.getBoneTransforms()[i] * bone.getVertexTransform().getInverse();
-				lines[i * 2 + 1] = (m * point).xyz();
+				const Vec3 b = (m * point).xyz();
+
+				lines.emplaceBack(a);
+				lines.emplaceBack(b);
+
+				if(bone.getChildren().getSize() == 0)
+				{
+					// If there are not children try to draw something for that bone as well
+					chidlessLines.emplaceBack(b);
+					const F32 len = (b - a).getLength();
+					const Vec3 c = b + (b - a).getNormalized() * len;
+					chidlessLines.emplaceBack(c);
+				}
 			}
 
 			const Mat4 mvp = ctx.m_viewProjectionMatrix * Mat4(getComponent<MoveComponent>().getWorldTransform());
 			m_dbgDrawer.drawLines(ConstWeakArray<Mat4>(&mvp, 1),
-				Vec4(1, 1, 1, 1),
-				10.0f,
+				Vec4(1.0f),
+				20.0f,
 				ctx.m_debugDrawFlags.get(RenderQueueDebugDrawFlag::DITHERED_DEPTH_TEST_ON),
-				ConstWeakArray<Vec3>(lines, boneCount * 2),
+				lines,
 				*ctx.m_stagingGpuAllocator,
 				cmdb);
 
-			ctx.m_frameAllocator.deleteArray(lines, boneCount * 2);
+			m_dbgDrawer.drawLines(ConstWeakArray<Mat4>(&mvp, 1),
+				Vec4(0.7f, 0.7f, 0.7f, 1.0f),
+				5.0f,
+				ctx.m_debugDrawFlags.get(RenderQueueDebugDrawFlag::DITHERED_DEPTH_TEST_ON),
+				chidlessLines,
+				*ctx.m_stagingGpuAllocator,
+				cmdb);
 		}
 
 		// Restore state