Browse Source

More position decompression fixes

Panagiotis Christopoulos Charitos 3 years ago
parent
commit
20abb4a206

+ 2 - 1
AnKi/Scene/Components/RenderComponent.cpp

@@ -16,7 +16,7 @@ ANKI_SCENE_COMPONENT_STATICS(RenderComponent)
 
 void RenderComponent::allocateAndSetupUniforms(const MaterialResourcePtr& mtl, const RenderQueueDrawContext& ctx,
 											   ConstWeakArray<Mat3x4> transforms, ConstWeakArray<Mat3x4> prevTransforms,
-											   StagingGpuMemoryPool& alloc)
+											   StagingGpuMemoryPool& alloc, const Vec4& positionScaleAndTranslation)
 {
 	ANKI_ASSERT(transforms.getSize() <= kMaxInstanceCount);
 	ANKI_ASSERT(prevTransforms.getSize() == transforms.getSize());
@@ -41,6 +41,7 @@ void RenderComponent::allocateAndSetupUniforms(const MaterialResourcePtr& mtl, c
 			memcpy(&renderableGpuViews->m_worldTransform, &transforms[i], sizeof(renderableGpuViews->m_worldTransform));
 			memcpy(&renderableGpuViews->m_previousWorldTransform, &prevTransforms[i],
 				   sizeof(renderableGpuViews->m_previousWorldTransform));
+			renderableGpuViews->m_positionScaleF32AndTranslationVec3 = positionScaleAndTranslation;
 
 			++renderableGpuViews;
 		}

+ 2 - 1
AnKi/Scene/Components/RenderComponent.h

@@ -104,7 +104,8 @@ public:
 	/// Helper function.
 	static void allocateAndSetupUniforms(const MaterialResourcePtr& mtl, const RenderQueueDrawContext& ctx,
 										 ConstWeakArray<Mat3x4> transforms, ConstWeakArray<Mat3x4> prevTransforms,
-										 StagingGpuMemoryPool& alloc);
+										 StagingGpuMemoryPool& alloc,
+										 const Vec4& positionScaleAndTranslation = Vec4(1.0f, 0.0f, 0.0f, 0.0f));
 
 private:
 	RenderQueueDrawCallback m_callback = nullptr;

+ 15 - 4
AnKi/Scene/ModelNode.cpp

@@ -220,9 +220,17 @@ void ModelNode::draw(RenderQueueDrawContext& ctx, ConstWeakArray<void*> userData
 
 		// Transforms
 		auto computeTranform = [&](const Transform& trf) -> Mat3x4 {
-			const Mat4 m4 = Mat4(trf) * m_renderProxies[modelPatchIdx].m_compressedToModelTransform;
-			const Mat3x4 out(m4);
-			return out;
+			if(skinc.isEnabled())
+			{
+				return Mat3x4(trf);
+			}
+			else
+			{
+				// Bake the decompression in the model matrix
+				const Mat4 m4 = Mat4(trf) * m_renderProxies[modelPatchIdx].m_compressedToModelTransform;
+				const Mat3x4 out(m4);
+				return out;
+			}
 		};
 		Array<Mat3x4, kMaxInstanceCount> trfs;
 		Array<Mat3x4, kMaxInstanceCount> prevTrfs;
@@ -274,10 +282,13 @@ void ModelNode::draw(RenderQueueDrawContext& ctx, ConstWeakArray<void*> userData
 		cmdb->bindShaderProgram(modelInf.m_program);
 
 		// Uniforms
+		const Vec4 positionScaleAndTransform(
+			m_renderProxies[modelPatchIdx].m_compressedToModelTransform(0, 0),
+			m_renderProxies[modelPatchIdx].m_compressedToModelTransform.getTranslationPart().xyz());
 		RenderComponent::allocateAndSetupUniforms(
 			modelc.getModelResource()->getModelPatches()[modelPatchIdx].getMaterial(), ctx,
 			ConstWeakArray<Mat3x4>(&trfs[0], instanceCount), ConstWeakArray<Mat3x4>(&prevTrfs[0], instanceCount),
-			*ctx.m_stagingGpuAllocator);
+			*ctx.m_stagingGpuAllocator, positionScaleAndTransform);
 
 		// Bind attributes & vertex buffers
 		for(VertexStreamId streamId :

+ 2 - 1
AnKi/Shaders/ForwardShadingFog.ankiprog

@@ -43,7 +43,8 @@ layout(location = 0) out F32 out_zVSpace;
 
 void main()
 {
-	const Vec3 worldPos = u_renderableGpuViews[0].m_worldTransform * Vec4(in_position, 1.0);
+	const RenderableGpuView renderable = u_renderableGpuViews[0];
+	const Vec3 worldPos = renderable.m_worldTransform * Vec4(in_position, 1.0);
 
 	gl_Position = u_global.m_viewProjectionMatrix * Vec4(worldPos, 1.0);
 

+ 13 - 0
AnKi/Shaders/GBufferGeneric.ankiprog

@@ -89,9 +89,22 @@ layout(set = kMaterialSetLocal, binding = kMaterialBindingPreviousBoneTransforms
 #pragma anki start vert
 
 // Globals (always in local space)
+#if ANKI_BONES
+Vec3 g_position = in_position * u_renderableGpuViews[gl_InstanceIndex].m_positionScaleF32AndTranslationVec3.x
+				  + u_renderableGpuViews[gl_InstanceIndex].m_positionScaleF32AndTranslationVec3.yzw;
+#else
 Vec3 g_position = in_position;
+#endif
+
 #if ANKI_TECHNIQUE == RENDERING_TECHNIQUE_GBUFFER
+
+#	if ANKI_BONES
+Vec3 g_prevPosition = in_position * u_renderableGpuViews[gl_InstanceIndex].m_positionScaleF32AndTranslationVec3.x
+					  + u_renderableGpuViews[gl_InstanceIndex].m_positionScaleF32AndTranslationVec3.yzw;
+#	else
 Vec3 g_prevPosition = in_position;
+#	endif
+
 ANKI_RP Vec3 g_normal = in_normal;
 ANKI_RP Vec4 g_tangent = in_tangent;
 #endif

+ 1 - 0
AnKi/Shaders/Include/GpuSceneTypes.h

@@ -13,6 +13,7 @@ struct RenderableGpuView
 {
 	Mat3x4 m_worldTransform;
 	Mat3x4 m_previousWorldTransform;
+	Vec4 m_positionScaleF32AndTranslationVec3; ///< The scale and translation that uncompress positions.
 };
 
 struct SkinGpuView

BIN
Samples/SkeletalAnimation/Assets/Mesh_e891faf0733c881d.ankimesh


BIN
Samples/SkeletalAnimation/Assets/room.001_82c13d2071184ecf.ankimesh


BIN
Samples/SkeletalAnimation/Assets/room.002_9aeac5bb7f16c0a7.ankimesh


BIN
Samples/SkeletalAnimation/Assets/room.003_225a06b3faa52c4c.ankimesh


BIN
Samples/SkeletalAnimation/Assets/room_bb0180d3054a4db3.ankimesh