2
0
Panagiotis Christopoulos Charitos 2 жил өмнө
parent
commit
0ef16195e6

+ 7 - 4
AnKi/Renderer/Utils/HzbGenerator.cpp

@@ -25,10 +25,13 @@
 
 namespace anki {
 
-//   3 +----+ 2
-//    /    /
+//   7 +----+ 6
+//    /|   /|
+// 3 +----+2|
+//   | *--| + 5
+//   |/4  |/
 // 0 +----+  1
-static constexpr U16 kBoxIndices[] = {0, 1, 3, 3, 1, 2};
+static constexpr U16 kBoxIndices[] = {1, 2, 5, 2, 6, 5, 0, 4, 3, 4, 7, 3, 3, 7, 2, 7, 6, 2, 0, 1, 4, 1, 5, 4, 0, 3, 1, 3, 2, 1, 4, 5, 7, 5, 6, 7};
 
 Error HzbGenerator::init()
 {
@@ -271,7 +274,7 @@ void HzbGenerator::populateRenderGraphDirectionalLight(RenderTargetHandle srcDep
 
 			cmdb.bindIndexBuffer(m_boxIndexBuffer.get(), 0, IndexType::kU16);
 
-			cmdb.drawIndexed(PrimitiveTopology::kTriangles, 3 * 2, maxDepthRtSize.x() * maxDepthRtSize.y());
+			cmdb.drawIndexed(PrimitiveTopology::kTriangles, sizeof(kBoxIndices) / sizeof(kBoxIndices[0]), maxDepthRtSize.x() * maxDepthRtSize.y());
 
 			// Restore state
 			cmdb.setDepthCompareOperation(CompareOperation::kLess);

+ 9 - 4
AnKi/Shaders/HzbMaxDepthProject.ankiprog

@@ -30,20 +30,25 @@ Vec4 main(U32 svVertexId : SV_VERTEXID, U32 svInstanceId : SV_INSTANCEID) : SV_P
 
 	// Z
 	Vec3 ndc;
-	ndc.z = (svVertexId <= 1) ? 0.0 : maxDepth;
+	ndc.z = (svVertexId <= 3) ? 0.0 : maxDepth;
 
 	// X
 	ndc.x = F32(tileX);
-	if(svVertexId == 1 || svVertexId == 2)
+	if(svVertexId == 1 || svVertexId == 2 || svVertexId == 5 || svVertexId == 6)
 	{
 		// Right side, move the point
 		ndc.x += 1.0f;
 	}
-	ndc.x /= F32(maxDepthRtSize.x);
 
 	// Y
-	ndc.y = F32(tileY) / F32(maxDepthRtSize.y);
+	ndc.y = F32(tileY);
+	if(svVertexId == 3 || svVertexId == 2 || svVertexId == 7 || svVertexId == 6)
+	{
+		// Top side, move the point
+		ndc.y += 1.0f;
+	}
 
+	ndc.xy /= Vec2(maxDepthRtSize);
 	ndc.xy = uvToNdc(saturate(ndc.xy));
 
 	// Unproject and project