|
|
@@ -24,7 +24,11 @@
|
|
|
#define REALLY_VELOCITY ((ANKI_VELOCITY || ANKI_BONES) && ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER)
|
|
|
#define REALLY_USING_PARALLAX (PARALLAX == 1 && ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER && ALPHA_TEST == 0)
|
|
|
|
|
|
-#define MESHLET_BACKFACE_CULLING 1
|
|
|
+#define VISUALIZE_MESHLETS (0 && ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER)
|
|
|
+#define MESHLET_BACKFACE_CULLING 0
|
|
|
+#define MESHLET_OUTSIDE_OF_SCREEN_CULLING 1
|
|
|
+#define MESHLET_NO_SAMPLING_POINT_CULLING 1
|
|
|
+#define MESHLET_HZB_CULLING 1
|
|
|
|
|
|
#include <AnKi/Shaders/Include/MaterialTypes.h>
|
|
|
#include <AnKi/Shaders/Include/GpuSceneFunctions.h>
|
|
|
@@ -84,6 +88,10 @@ struct VertOut
|
|
|
#endif
|
|
|
|
|
|
nointerpolation U32 m_constantsOffset : UNIS_OFFSET;
|
|
|
+
|
|
|
+#if VISUALIZE_MESHLETS
|
|
|
+ nointerpolation U32 m_meshletIndex : MESHLET_INDEX;
|
|
|
+#endif
|
|
|
};
|
|
|
|
|
|
#if ANKI_TECHNIQUE == ANKI_RENDERING_TECHNIQUE_GBUFFER
|
|
|
@@ -262,11 +270,34 @@ struct FirstPayload
|
|
|
{
|
|
|
Bool cull = false;
|
|
|
|
|
|
-#if MESHLET_BACKFACE_CULLING
|
|
|
const Meshlet meshlet = g_meshlets[firstMeshlet + svGroupIndex];
|
|
|
const Mat3x4 worldTransform = g_gpuScene.Load<Mat3x4>(renderable.m_worldTransformsOffset);
|
|
|
|
|
|
- cull = cull || cullBackfaceMeshlet(meshlet, worldTransform, g_globalConstants.m_cameraTransform.getTranslationPart());
|
|
|
+#if MESHLET_BACKFACE_CULLING
|
|
|
+ cull = cullBackfaceMeshlet(meshlet, worldTransform, g_globalConstants.m_cameraTransform.getTranslationPart());
|
|
|
+#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_globalConstants.m_viewProjectionMatrix, wordTransform4);
|
|
|
+
|
|
|
+ Vec2 minNdc, maxNdc;
|
|
|
+ F32 aabbMinDepth;
|
|
|
+ projectAabb(meshlet.m_aabbMin, meshlet.m_aabbMax, mvp, minNdc, maxNdc, aabbMinDepth);
|
|
|
+
|
|
|
+#if MESHLET_OUTSIDE_OF_SCREEN_CULLING
|
|
|
+ // Outside of the screen
|
|
|
+ cull = !cull && (any(minNdc > 1.0f) || any(maxNdc < -1.0f));
|
|
|
+#endif
|
|
|
+
|
|
|
+#if MESHLET_NO_SAMPLING_POINT_CULLING
|
|
|
+ // Sampling points test
|
|
|
+ const Vec2 windowCoordsMin = ndcToUv(minNdc) * g_globalConstants.m_viewport.zw;
|
|
|
+ const Vec2 windowCoordsMax = ndcToUv(maxNdc) * g_globalConstants.m_viewport.zw;
|
|
|
+ cull = !cull && any(round(windowCoordsMin) == round(windowCoordsMax));
|
|
|
+#endif
|
|
|
+
|
|
|
+#if MESHLET_HZB_CULLING
|
|
|
+ cull = !cull && g_globalConstants.m_enableHzbTesting == 1u && cullHzb(minNdc, maxNdc, aabbMinDepth, g_hzbTexture, g_nearestClampSampler);
|
|
|
#endif
|
|
|
|
|
|
if(!cull)
|
|
|
@@ -345,6 +376,10 @@ main(in payload MeshShaderPayload payload, out vertices VertOut verts[kMaxVertic
|
|
|
velocity(worldTransform, prevWorldTransform, prevPos, output);
|
|
|
#endif
|
|
|
|
|
|
+#if VISUALIZE_MESHLETS
|
|
|
+ output.m_meshletIndex = relativeMeshletIdx;
|
|
|
+#endif
|
|
|
+
|
|
|
verts[idx] = output;
|
|
|
}
|
|
|
}
|
|
|
@@ -463,6 +498,31 @@ FragOut main(VertOut input)
|
|
|
g.m_metallic = metallic;
|
|
|
g.m_velocity = velocity;
|
|
|
|
|
|
+# if VISUALIZE_MESHLETS
|
|
|
+ const U32 meshletIdx = input.m_meshletIndex % 6u;
|
|
|
+ switch(meshletIdx)
|
|
|
+ {
|
|
|
+ case 0:
|
|
|
+ g.m_diffuse = Vec3(1.0f, 0.0f, 0.0f);
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ g.m_diffuse = Vec3(0.0f, 1.0f, 0.0f);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ g.m_diffuse = Vec3(0.0f, 0.0f, 1.0f);
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ g.m_diffuse = Vec3(1.0f, 1.0f, 0.0f);
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ g.m_diffuse = Vec3(1.0f, 0.0f, 1.0f);
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ g.m_diffuse = Vec3(0.0f, 1.0f, 1.0f);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+# endif
|
|
|
+
|
|
|
FragOut output;
|
|
|
packGBuffer(g, output.m_color0, output.m_color1, output.m_color2, output.m_color3);
|
|
|
return output;
|