Browse Source

Fix a bug

Panagiotis Christopoulos Charitos 2 years ago
parent
commit
4cbd23db2c

+ 1 - 0
AnKi/Importer/GltfImporterMesh.cpp

@@ -211,6 +211,7 @@ static void decimateSubmesh(F32 factor, SubMesh& submesh, BaseMemoryPool* pool)
 
 	// Decimate
 	ImporterDynamicArray<U32> newIndices(pool);
+	newIndices.resize(submesh.m_indices.getSize());
 	newIndices.resize(U32(meshopt_simplify(&newIndices[0], &submesh.m_indices[0], submesh.m_indices.getSize(), &submesh.m_verts[0].m_position.x(),
 										   submesh.m_verts.getSize(), sizeof(TempVertex), targetIndexCount, 1e-2f)));
 

+ 2 - 2
AnKi/Renderer/Dbg.cpp

@@ -127,7 +127,7 @@ void Dbg::drawNonRenderable(GpuSceneNonRenderableObjectType type, U32 objCount,
 							CommandBuffer& cmdb)
 {
 	ShaderProgramResourceVariantInitInfo variantInitInfo(m_nonRenderablesProg);
-	variantInitInfo.addMutation("DITHERED_DEPTH_TEST", U32(m_ditheredDepthTestOn != 0));
+	variantInitInfo.addMutation("DEPTH_FAIL_VISUALIZATION", U32(m_ditheredDepthTestOn != 0));
 	variantInitInfo.addMutation("OBJECT_TYPE", U32(type));
 	const ShaderProgramResourceVariant* variant;
 	m_nonRenderablesProg->getOrCreateVariant(variantInitInfo, variant);
@@ -176,7 +176,7 @@ void Dbg::run(RenderPassWorkContext& rgraphCtx, const RenderingContext& ctx)
 		const U32 allAabbCount = GpuSceneArrays::RenderableBoundingVolumeGBuffer::getSingleton().getElementCount();
 
 		ShaderProgramResourceVariantInitInfo variantInitInfo(m_renderablesProg);
-		variantInitInfo.addMutation("DITHERED_DEPTH_TEST", U32(m_ditheredDepthTestOn != 0));
+		variantInitInfo.addMutation("DEPTH_FAIL_VISUALIZATION", U32(m_ditheredDepthTestOn != 0));
 		const ShaderProgramResourceVariant* variant;
 		m_renderablesProg->getOrCreateVariant(variantInitInfo, variant);
 		cmdb.bindShaderProgram(&variant->getProgram());

+ 1 - 1
AnKi/Resource/MeshBinaryLoader.cpp

@@ -164,7 +164,7 @@ Error MeshBinaryLoader::checkHeader() const
 	}
 
 	// LOD
-	if(h.m_lodCount == 0 || h.m_lodCount >= kMaxLodCount)
+	if(h.m_lodCount == 0 || h.m_lodCount > kMaxLodCount)
 	{
 		ANKI_RESOURCE_LOGE("Wrong LOD count");
 		return Error::kUserData;

+ 11 - 13
AnKi/Shaders/DbgBillboard.ankiprog

@@ -3,14 +3,14 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
-#pragma anki mutator DITHERED_DEPTH_TEST 0 1
+#pragma anki mutator DEPTH_FAIL_VISUALIZATION 0 1
 #pragma anki mutator OBJECT_TYPE 0 1 2 3 4 // Same as GpuSceneNonRenderableObjectType
 
 #include <AnKi/Shaders/Common.hlsl>
 #include <AnKi/Shaders/ClusteredShadingFunctions.hlsl>
 #include <AnKi/Shaders/TonemappingFunctions.hlsl>
 
-constexpr F32 kAlpha = 0.95f;
+constexpr F32 kAlpha = 1.0f;
 constexpr F32 kBillboardScale = 0.25f;
 
 struct Constants
@@ -103,11 +103,11 @@ VertOut main(VertIn input)
 #include <AnKi/Shaders/ImportanceSampling.hlsl>
 
 [[vk::binding(4)]] SamplerState g_trilinearRepeatSampler;
-[[vk::binding(5)]] Texture2D g_tex;
-[[vk::binding(6)]] Texture2D g_tex2;
+[[vk::binding(5)]] Texture2D<Vec4> g_tex;
+[[vk::binding(6)]] Texture2D<Vec4> g_tex2;
 
 // NOTE: Don't eliminate the binding because it confuses the descriptor set creation
-#if DITHERED_DEPTH_TEST == 1
+#if DEPTH_FAIL_VISUALIZATION == 1
 [[vk::binding(0)]] SamplerState g_nearestAnyClampSampler;
 [[vk::binding(1)]] Texture2D g_depthRt;
 #endif
@@ -117,29 +117,27 @@ Vec4 main(VertOut input) : SV_TARGET0
 	ANKI_MAYBE_UNUSED(input);
 
 	// Check if we should skip the frag
-#if DITHERED_DEPTH_TEST == 1
-	const UVec2 random = rand3DPCG16(UVec3(UVec2(input.m_svPosition.xy), 1)).xy;
-	const Vec2 noise = Vec2(random) / 65536.0;
-	const F32 factor = noise.x * noise.y;
+	F32 colorFactor = 1.0f;
+#if DEPTH_FAIL_VISUALIZATION == 1
 	Vec2 texSize;
 	g_depthRt.GetDimensions(texSize.x, texSize.y);
 	const Vec2 uv = input.m_svPosition.xy / texSize;
 	const F32 depthRef = g_depthRt.SampleLevel(g_nearestAnyClampSampler, uv, 0.0).r;
 	const Bool depthTestFailed = input.m_svPosition.z >= depthRef;
-	if(depthTestFailed && factor < 0.5)
+	if(depthTestFailed)
 	{
-		discard;
+		colorFactor = 0.6;
 	}
 #endif
 
 	// Write the color
 	if(input.m_textureIndex == 0)
 	{
-		return g_tex.Sample(g_trilinearRepeatSampler, input.m_uv) * input.m_colorScale;
+		return g_tex.Sample(g_trilinearRepeatSampler, input.m_uv) * input.m_colorScale * colorFactor;
 	}
 	else
 	{
-		return g_tex2.Sample(g_trilinearRepeatSampler, input.m_uv) * input.m_colorScale;
+		return g_tex2.Sample(g_trilinearRepeatSampler, input.m_uv) * input.m_colorScale * colorFactor;
 	}
 }
 #pragma anki end

+ 5 - 8
AnKi/Shaders/DbgRenderables.ankiprog

@@ -3,7 +3,7 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
-#pragma anki mutator DITHERED_DEPTH_TEST 0 1
+#pragma anki mutator DEPTH_FAIL_VISUALIZATION 0 1
 
 #include <AnKi/Shaders/Common.hlsl>
 #include <AnKi/Shaders/Include/GpuSceneTypes.h>
@@ -57,7 +57,7 @@ VertOut main(VertIn input)
 #include <AnKi/Shaders/ImportanceSampling.hlsl>
 
 // NOTE: Don't eliminate the binding because it confuses the descriptor set creation
-#if DITHERED_DEPTH_TEST == 1
+#if DEPTH_FAIL_VISUALIZATION == 1
 [[vk::binding(0)]] SamplerState g_nearestAnyClampSampler;
 [[vk::binding(1)]] Texture2D g_depthRt;
 #endif
@@ -67,18 +67,15 @@ Vec4 main(VertOut input) : SV_TARGET0
 	ANKI_MAYBE_UNUSED(input);
 
 	// Check if we should skip the frag
-#if DITHERED_DEPTH_TEST == 1
-	const UVec2 random = rand3DPCG16(UVec3(UVec2(input.m_svPosition.xy), 1)).xy;
-	const Vec2 noise = Vec2(random) / 65536.0;
-	const F32 factor = noise.x * noise.y;
+#if DEPTH_FAIL_VISUALIZATION == 1
 	Vec2 texSize;
 	g_depthRt.GetDimensions(texSize.x, texSize.y);
 	const Vec2 uv = input.m_svPosition.xy / texSize;
 	const F32 depthRef = g_depthRt.SampleLevel(g_nearestAnyClampSampler, uv, 0.0).r;
 	const Bool depthTestFailed = input.m_svPosition.z >= depthRef;
-	if(depthTestFailed && factor < 0.5)
+	if(depthTestFailed)
 	{
-		discard;
+		return g_consts.m_color * 0.5;
 	}
 #endif