Przeglądaj źródła

Bug fixes & exporter additions

Panagiotis Christopoulos Charitos 11 lat temu
rodzic
commit
e821dd168f

+ 1 - 2
shaders/Pps.frag.glsl

@@ -106,8 +106,7 @@ void main()
 	outColor += hdr;
 #endif
 
-//#if GAMMA_CORRECTION_ENABLED
-#if 0
+#if GAMMA_CORRECTION_ENABLED
 	//outColor = BlendHardLight(vec3(0.7, 0.72, 0.4), outColor);
 	outColor = gammaCorrectionRgb(vec3(0.9, 0.92, 0.75), outColor);
 #endif

+ 1 - 1
shaders/PpsSsao.frag.glsl

@@ -15,7 +15,7 @@ layout(location = 0) in vec2 inTexCoords;
 
 layout(location = 0) out float outColor;
 
-layout(std140, row_major, binding = 0) readonly buffer bCommon
+layout(std140, binding = 0) readonly buffer bCommon
 {
 	vec4 uProjectionParams;
 

+ 1 - 1
testapp/Main.cpp

@@ -70,7 +70,7 @@ Error init()
 	const F32 ang = 55.0;
 	cam->setAll(
 		renderer.getAspectRatio() * toRad(ang),
-		toRad(ang), 0.5, 500.0);
+		toRad(ang), 0.2, 500.0);
 	cam->getComponent<MoveComponent>().
 		setLocalTransform(Transform(Vec4(0.0),
 		Mat3x4(Euler(toRad(0.0), toRad(180.0), toRad(0.0))),

+ 62 - 9
tools/scene/Exporter.cpp

@@ -11,6 +11,18 @@
 
 static const char* XML_HEADER = R"(<?xml version="1.0" encoding="UTF-8" ?>)";
 
+//==============================================================================
+static aiColor3D srgbToLinear(const aiColor3D& in)
+{
+	const float p = 1.0 / 2.4;
+	aiColor3D out;
+	out[0] = pow(in[0], p);
+	out[1] = pow(in[1], p);
+	out[2] = pow(in[2], p);
+	out[3] = in[3];
+	return out;
+}
+
 //==============================================================================
 static std::string getMaterialName(const aiMaterial& mtl, bool instanced)
 {
@@ -569,7 +581,7 @@ void Exporter::exportModel(const Model& model) const
 	file << "<model>\n";
 	file << "\t<modelPatches>\n";
 	
-	// start
+	// Start patches
 	file << "\t\t<modelPatch>\n";
 
 	// Write mesh
@@ -583,10 +595,19 @@ void Exporter::exportModel(const Model& model) const
 			model.m_instanced) 
 		<< ".ankimtl</material>\n";
 
-	// end
+	// End patches
 	file << "\t\t</modelPatch>\n";
-
 	file << "\t</modelPatches>\n";
+
+	// Write collision mesh
+	if(model.m_collisionMeshIndex != INVALID_INDEX)
+	{
+		file << "\t<collisionShape><type>staticMesh</type><value>" 
+			<< m_rpath 
+			<< getMeshName(getMeshAt(model.m_collisionMeshIndex))
+			<< ".ankimesh</value></collisionShape>\n";
+	}
+
 	file << "</model>\n";
 }
 
@@ -618,16 +639,18 @@ void Exporter::exportLight(const aiLight& light)
 	file << "lcomp = node:getSceneNodeBase():getLightComponent()\n";
 
 	// Colors
+	aiColor3D linear = srgbToLinear(light.mColorDiffuse);
 	file << "lcomp:setDiffuseColor(Vec4.new("
-		<< light.mColorDiffuse[0] << ", " 
-		<< light.mColorDiffuse[1] << ", " 
-		<< light.mColorDiffuse[2] << ", " 
+		<< linear[0] << ", " 
+		<< linear[1] << ", " 
+		<< linear[2] << ", "
 		<< "1))\n";
 
+	linear = srgbToLinear(light.mColorSpecular);
 	file << "lcomp:setSpecularColor(Vec4.new("
-		<< light.mColorSpecular[0] << ", " 
-		<< light.mColorSpecular[1] << ", " 
-		<< light.mColorSpecular[2] << ", " 
+		<< linear[0] << ", " 
+		<< linear[1] << ", " 
+		<< linear[2] << ", "
 		<< "1))\n";
 
 	// Geometry
@@ -873,6 +896,15 @@ void Exporter::visitNode(const aiNode* ainode)
 		unsigned meshIndex = ainode->mMeshes[i];
 		unsigned mtlIndex =  m_scene->mMeshes[meshIndex]->mMaterialIndex;
 
+		// Check if it's a collsion mesh
+		std::string name = m_scene->mMeshes[meshIndex]->mName.C_Str();
+		if(name.find("ak_collision") == 0)
+		{
+			// Ignore collision meshes
+			m_collisionMeshIds.push_back(meshIndex);
+			continue;
+		}
+
 		// Find if there is another node with the same mesh-material pair
 		std::vector<Node>::iterator it;
 		for(it = m_nodes.begin(); it != m_nodes.end(); ++it)
@@ -943,6 +975,14 @@ void Exporter::exportAll()
 	//
 	visitNode(m_scene->mRootNode);
 
+	//
+	// Export collision meshes
+	//
+	for(auto idx : m_collisionMeshIds)
+	{
+		exportMesh(*m_scene->mMeshes[idx], nullptr);
+	}
+
 	//
 	// Export nodes and models.
 	//
@@ -951,6 +991,19 @@ void Exporter::exportAll()
 		Node& node = m_nodes[i];
 		Model& model = m_models[node.m_modelIndex];
 
+		// Check if it has a collision mesh
+		std::string collisionMeshName = std::string("ak_collision_")
+			+ m_scene->mMeshes[model.m_meshIndex]->mName.C_Str();
+		for(unsigned i = 0; i < m_collisionMeshIds.size(); ++i)
+		{
+			if(m_scene->mMeshes[m_collisionMeshIds[i]]->mName.C_Str() 
+				== collisionMeshName)
+			{
+				model.m_collisionMeshIndex = m_collisionMeshIds[i];
+				break;
+			}
+		}
+
 		// TODO If not instanced bake transform
 		exportMesh(*m_scene->mMeshes[model.m_meshIndex], nullptr);
 

+ 3 - 0
tools/scene/Exporter.h

@@ -26,6 +26,7 @@ struct Model
 	uint32_t m_meshIndex = INVALID_INDEX; ///< Mesh index in the scene
 	uint32_t m_materialIndex = INVALID_INDEX;
 	bool m_instanced = false;
+	uint32_t m_collisionMeshIndex = INVALID_INDEX;
 };
 
 /// Scene node.
@@ -64,6 +65,8 @@ public:
 
 	std::ofstream m_sceneFile;
 
+	std::vector<uint32_t> m_collisionMeshIds;
+
 	/// Load the scene.
 	void load();