Преглед на файлове

Updated morph shape rendering so it uses a proper vertex declaration

BearishSun преди 9 години
родител
ревизия
d86bc7b768

+ 3 - 1
Source/BansheeEditor/Source/BsSelectionRenderer.cpp

@@ -173,6 +173,7 @@ namespace BansheeEngine
 
 			SPtr<GpuBufferCore> boneMatrixBuffer = renderable->getBoneMatrixBuffer();
 			SPtr<VertexBufferCore> morphShapeBuffer = renderable->getMorphShapeBuffer();
+			SPtr<VertexDeclarationCore> morphVertexDeclaration = renderable->getMorphVertexDeclaration();
 
 			Matrix4 worldViewProjMat = viewProjMat * renderable->getTransform();
 			UINT32 techniqueIdx = mTechniqueIndices[(int)renderable->getAnimType()];
@@ -188,7 +189,8 @@ namespace BansheeEngine
 			UINT32 renderableId = renderable->getRendererId();
 
 			for(UINT32 i = 0; i < numSubmeshes; i++)
-				gRendererUtility().drawMorph(mesh, mesh->getProperties().getSubMesh(i), morphShapeBuffer);
+				gRendererUtility().drawMorph(mesh, mesh->getProperties().getSubMesh(i), morphShapeBuffer, 
+					morphVertexDeclaration);
 		}
 	}
 }

+ 4 - 0
Source/BansheeEngine/Include/BsRenderable.h

@@ -205,6 +205,9 @@ namespace BansheeEngine
 		/** Returns the vertex buffer containing element's morph shape vertices, if it has any. */
 		const SPtr<VertexBufferCore>& getMorphShapeBuffer() const { return mMorphShapeBuffer; }
 
+		/** Returns vertex declaration used for rendering meshes containing morph shape information. */
+		const SPtr<VertexDeclarationCore>& getMorphVertexDeclaration() const { return mMorphVertexDeclaration; }
+
 	protected:
 		friend class Renderable;
 
@@ -225,6 +228,7 @@ namespace BansheeEngine
 
 		SPtr<GpuBufferCore> mBoneMatrixBuffer;
 		SPtr<VertexBufferCore> mMorphShapeBuffer;
+		SPtr<VertexDeclarationCore> mMorphVertexDeclaration;
 	};
 
 	/** @copydoc TRenderable */

+ 8 - 5
Source/BansheeEngine/Include/BsRendererUtility.h

@@ -83,14 +83,17 @@ namespace BansheeEngine
 		/**
 		 * Draws the specified mesh with an additional vertex buffer containing morph shape vertices.
 		 *
-		 * @param[in]	mesh			Mesh to draw.
-		 * @param[in]	subMesh			Portion of the mesh to draw.
-		 * @param[in]	morphVertices	Buffer containing the morph shape vertices. Will be bound to stream 1. Expected
-		 *								to contain the same number of vertices as the source mesh.
+		 * @param[in]	mesh					Mesh to draw.
+		 * @param[in]	subMesh					Portion of the mesh to draw.
+		 * @param[in]	morphVertices			Buffer containing the morph shape vertices. Will be bound to stream 1. 
+		 *										Expected to contain the same number of vertices as the source mesh.
+		 * @param[in]	morphVertexDeclaration	Vertex declaration describing vertices of the provided mesh and the vertices
+		 *										provided in the morph vertex buffer.
 		 *
 		 * @note	Core thread.
 		 */
-		void drawMorph(const SPtr<MeshCoreBase>& mesh, const SubMesh& subMesh, const SPtr<VertexBufferCore>& morphVertices);
+		void drawMorph(const SPtr<MeshCoreBase>& mesh, const SubMesh& subMesh, const SPtr<VertexBufferCore>& morphVertices, 
+			const SPtr<VertexDeclarationCore>& morphVertexDeclaration);
 
 		/**
 		 * Blits contents of the provided texture into the currently bound render target. If the provided texture contains

+ 14 - 0
Source/BansheeEngine/Source/BsRenderable.cpp

@@ -339,6 +339,20 @@ namespace BansheeEngine
 		{
 			createAnimationBuffers();
 
+			// Create special vertex declaration if using morph shapes
+			if (mAnimType == RenderableAnimType::Morph || mAnimType == RenderableAnimType::SkinnedMorph)
+			{
+				SPtr<VertexDataDesc> vertexDesc = VertexDataDesc::create();
+				*vertexDesc = * mMesh->getVertexDesc();
+
+				vertexDesc->addVertElem(VET_FLOAT3, VES_POSITION, 1, 1);
+				vertexDesc->addVertElem(VET_UBYTE4_NORM, VES_NORMAL, 1, 1);
+
+				mMorphVertexDeclaration = VertexDeclarationCore::create(vertexDesc);
+			}
+			else
+				mMorphVertexDeclaration = nullptr;
+
 			if (oldIsActive != mIsActive)
 			{
 				if (mIsActive)

+ 2 - 2
Source/BansheeEngine/Source/BsRendererUtility.cpp

@@ -297,13 +297,13 @@ namespace BansheeEngine
 	}
 
 	void RendererUtility::drawMorph(const SPtr<MeshCoreBase>& mesh, const SubMesh& subMesh, 
-		const SPtr<VertexBufferCore>& morphVertices)
+		const SPtr<VertexBufferCore>& morphVertices, const SPtr<VertexDeclarationCore>& morphVertexDeclaration)
 	{
 		// Bind buffers and draw
 		RenderAPICore& rapi = RenderAPICore::instance();
 
 		SPtr<VertexData> vertexData = mesh->getVertexData();
-		rapi.setVertexDeclaration(mesh->getVertexData()->vertexDeclaration); // TODO - Set valid declaration
+		rapi.setVertexDeclaration(morphVertexDeclaration);
 
 		auto& meshBuffers = vertexData->getBuffers();
 		SPtr<VertexBufferCore> allBuffers[MAX_BOUND_VERTEX_BUFFERS];

+ 3 - 0
Source/RenderBeast/Include/BsRendererObject.h

@@ -54,6 +54,9 @@ namespace BansheeEngine
 		/** Vertex buffer containing element's morph shape vertices, if it has any. */
 		SPtr<VertexBufferCore> morphShapeBuffer;
 
+		/** Vertex declaration used for rendering meshes containing morph shape information. */
+		SPtr<VertexDeclarationCore> morphVertexDeclaration;
+
 		/** Version of the morph shape vertices in the buffer. */
 		mutable UINT32 morphShapeVersion;
 	};

+ 2 - 1
Source/RenderBeast/Source/BsRenderBeast.cpp

@@ -144,6 +144,7 @@ namespace BansheeEngine
 				renElement.morphShapeVersion = 0;
 				renElement.morphShapeBuffer = renderable->getMorphShapeBuffer();
 				renElement.boneMatrixBuffer = renderable->getBoneMatrixBuffer();
+				renElement.morphVertexDeclaration = renderable->getMorphVertexDeclaration();
 
 				renElement.material = renderable->getMaterial(i);
 				if (renElement.material == nullptr)
@@ -835,7 +836,7 @@ namespace BansheeEngine
 		else
 			setPassParams(element.params, nullptr, passIdx);
 
-		gRendererUtility().drawMorph(element.mesh, element.subMesh, element.morphShapeBuffer);
+		gRendererUtility().drawMorph(element.mesh, element.subMesh, element.morphShapeBuffer, element.morphVertexDeclaration);
 	}
 
 	void RenderBeast::refreshSamplerOverrides(bool force)