Browse Source

WIP: Tranform feedback HW skinning

Panagiotis Christopoulos Charitos 15 years ago
parent
commit
6535fc6e50

BIN
docs/resources.odg


+ 27 - 7
shaders/TfHwSkinningGeneric.glsl

@@ -3,24 +3,42 @@
 /// Switches: NORMAL_ENABLED, TANGENT_ENABLED
 #pragma anki vertShaderBegins
 
-in vec3 position;
-in vec3 normal;
-in vec4 tangent;
+
+//
+// Attributes
+//
+layout(location = 0) in vec3 position;
+
+#if defined(NORMAL_ENABLED)
+	layout(location = 1) in vec3 normal;
+#endif
+
+#if defined(TANGENT_ENABLED)
+	layout(location = 2) in vec4 tangent;
+#endif
 in float vertWeightBonesNum;
 in vec4 vertWeightBoneIds;
 in vec4 vertWeightWeights;
 
+
+//
+// Uniforms
+// 
 const int MAX_BONES_PER_MESH = 60;
 uniform mat3 skinningRotations[MAX_BONES_PER_MESH];
 uniform vec3 skinningTranslations[MAX_BONES_PER_MESH];
 
-//#pragma anki transformFeedbackVarying vPosition
+
+//
+// Varyings
+//
+
 out vec3 vPosition;
-//#pragma anki transformFeedbackVarying vNormal
+
 #if defined(NORMAL_ENABLED)
 	out vec3 vNormal;
 #endif
-//#pragma anki transformFeedbackVarying vTangent
+
 #if defined(TANGENT_ENABLED)
 	out vec4 vTangent;
 #endif
@@ -54,5 +72,7 @@ void main()
 #pragma anki fragShaderBegins
 
 void main()
-{}
+{
+	// Do nothing
+}
 

+ 8 - 8
src/Resources/ModelPatch.cpp

@@ -6,7 +6,7 @@
 //======================================================================================================================
 // supportsHardwareSkinning                                                                                            =
 //======================================================================================================================
-bool ModelPatch::supportsHardwareSkinning() const
+bool ModelPatch::supportsHwSkinning() const
 {
 	return mesh->hasVertWeights();
 }
@@ -15,14 +15,14 @@ bool ModelPatch::supportsHardwareSkinning() const
 //======================================================================================================================
 // load                                                                                                                =
 //======================================================================================================================
-void ModelPatch::load(const char* meshFName, const char* mtlFName, const char* dpMtlFName)
+void ModelPatch::load(const char* meshFName, const char* cpMtlFName, const char* dpMtlFName)
 {
 	//
 	// Load
 	//
 	mesh.loadRsrc(meshFName);
-	material.loadRsrc(mtlFName);
-	dpMaterial.loadRsrc(dpMtlFName);
+	cpMtl.loadRsrc(cpMtlFName);
+	dpMtl.loadRsrc(dpMtlFName);
 
 	//
 	// Sanity checks
@@ -31,13 +31,13 @@ void ModelPatch::load(const char* meshFName, const char* mtlFName, const char* d
 		EXCEPTION("Resource \"" + x->getRsrcName() + "\" and \"" + y->getRsrcName() + "\" are incompatible")
 
 	// if mtl needs tex coords then mesh should have
-	if(material->hasTexCoords() && !mesh->hasTexCoords())
+	if(cpMtl->hasTexCoords() && !mesh->hasTexCoords())
 	{
-		throw EXCEPTION_INCOMPATIBLE_RSRCS(material, mesh);
+		throw EXCEPTION_INCOMPATIBLE_RSRCS(cpMtl, mesh);
 	}
 
-	if(dpMaterial->hasTexCoords() && !mesh->hasTexCoords())
+	if(dpMtl->hasTexCoords() && !mesh->hasTexCoords())
 	{
-		throw EXCEPTION_INCOMPATIBLE_RSRCS(dpMaterial, mesh);
+		throw EXCEPTION_INCOMPATIBLE_RSRCS(dpMtl, mesh);
 	}
 }

+ 5 - 5
src/Resources/ModelPatch.h

@@ -18,17 +18,17 @@ class ModelPatch
 		/// @name Accessors
 		/// @{
 		const Mesh& getMesh() const {return *mesh;}
-		const Material& getMaterial() const {return *material;}
-		const Material& getDpMaterial() const {return *dpMaterial;}
+		const Material& getCpMtl() const {return *cpMtl;}
+		const Material& getDpMtl() const {return *dpMtl;}
 		/// @}
 
 		/// This only checks the mesh for vertex weights
-		bool supportsHardwareSkinning() const;
+		bool supportsHwSkinning() const;
 
 	private:
 		RsrcPtr<Mesh> mesh; ///< The geometry
-		RsrcPtr<Material> material; ///< Material for MS and BS
-		RsrcPtr<Material> dpMaterial; ///< Material for depth passes
+		RsrcPtr<Material> cpMtl; ///< Material for MS and BS
+		RsrcPtr<Material> dpMtl; ///< Material for depth passes
 };
 
 

+ 18 - 14
src/Scene/ModelNodePatch.cpp

@@ -11,17 +11,16 @@
 // Constructor                                                                                                         =
 //======================================================================================================================
 ModelNodePatch::ModelNodePatch(const ModelPatch& modelPatch_, bool isSkinPatch):
-	modelPatch(modelPatch_)
+	modelPatchRsrc(modelPatch_)
 {
+	RASSERT_THROW_EXCEPTION(isSkinPatch && !modelPatchRsrc.supportsHwSkinning());
+
 	if(!isSkinPatch)
 	{
 		for(uint i = 0; i < Mesh::VBOS_NUM; i++)
 		{
-			vbos[i] = &modelPatch.getMesh().getVbo((Mesh::Vbos)i);
+			vbos[i] = &modelPatchRsrc.getMesh().getVbo((Mesh::Vbos)i);
 		}
-
-		createVao(modelPatch.getMaterial(), vbos, mainVao);
-		createVao(modelPatch.getDpMaterial(), vbos, dpVao);
 	}
 	else
 	{
@@ -29,30 +28,35 @@ ModelNodePatch::ModelNodePatch(const ModelPatch& modelPatch_, bool isSkinPatch):
 		// Create the TF VBOs
 		//
 		tfVbos[TF_VBO_POSITIONS].create(GL_ARRAY_BUFFER,
-		                                modelPatch.getMesh().getVbo(Mesh::VBO_VERT_POSITIONS).getSizeInBytes(),
+		                                modelPatchRsrc.getMesh().getVbo(Mesh::VBO_VERT_POSITIONS).getSizeInBytes(),
 		                                NULL,
 		                                GL_STATIC_DRAW);
 
 		tfVbos[TF_VBO_NORMALS].create(GL_ARRAY_BUFFER,
-		                              modelPatch.getMesh().getVbo(Mesh::VBO_VERT_NORMALS).getSizeInBytes(),
+		                              modelPatchRsrc.getMesh().getVbo(Mesh::VBO_VERT_NORMALS).getSizeInBytes(),
 		                              NULL,
 		                              GL_STATIC_DRAW);
 
 		tfVbos[TF_VBO_TANGENTS].create(GL_ARRAY_BUFFER,
-		                               modelPatch.getMesh().getVbo(Mesh::VBO_VERT_TANGENTS).getSizeInBytes(),
+		                               modelPatchRsrc.getMesh().getVbo(Mesh::VBO_VERT_TANGENTS).getSizeInBytes(),
 		                               NULL,
 		                               GL_STATIC_DRAW);
 
 		//
-		// Load TF material and to TF stuff
+		// Set the new VBOs array
 		//
-		tfMtl.loadRsrc("material/TfHwSkinning.mtl");
+		for(uint i = 0; i < Mesh::VBOS_NUM; i++)
+		{
+			vbos[i] = &modelPatchRsrc.getMesh().getVbo((Mesh::Vbos)i);
+		}
 
-		int id = tfMtl->getShaderProg().getGlId();
-		const char* tfVaryings[] = {"vPosition", "vNormal", "vTangent"};
-		glTransformFeedbackVaryings(id, 3, tfVaryings, GL_SEPARATE_ATTRIBS);
-		tfMtl->getShaderProg().relink();
+		vbos[Mesh::VBO_VERT_POSITIONS] = &tfVbos[TF_VBO_POSITIONS];
+		vbos[Mesh::VBO_VERT_NORMALS] = &tfVbos[TF_VBO_NORMALS];
+		vbos[Mesh::VBO_VERT_TANGENTS] = &tfVbos[TF_VBO_TANGENTS];
 	}
+
+	createVao(modelPatchRsrc.getCpMtl(), vbos, cpVao);
+	createVao(modelPatchRsrc.getDpMtl(), vbos, dpVao);
 }
 
 

+ 4 - 3
src/Scene/ModelNodePatch.h

@@ -28,16 +28,17 @@ class ModelNodePatch
 			TF_VBOS_NUM
 		};
 
+		const Material& getCpMtl() const {return modelPatchRsrc.getCpMtl();}
+		const Material& getDpMtl() const {return modelPatchRsrc.getDpMtl();}
 		const Vbo& getTfVbo(TfVbos i) const {return tfVbos[i];}
 
 	private:
-		const ModelPatch& modelPatch;
+		const ModelPatch& modelPatchRsrc;
 		boost::array<Vbo, TF_VBOS_NUM> tfVbos;
 		boost::array<const Vbo*, Mesh::VBOS_NUM> vbos;
-		Vao mainVao; ///< VAO for MS and BS
+		Vao cpVao; ///< VAO for MS and BS
 		Vao dpVao; ///< VAO for depth passes
 		Vao tfVao; ///< VAO for transform feedback
-		RsrcPtr<Material> tfMtl;
 
 		static void createVao(const Material& material, const boost::array<const Vbo*, Mesh::VBOS_NUM>& vbos, Vao& vao);
 };