Panagiotis Christopoulos Charitos 14 years ago
parent
commit
8ba5afc36f

+ 3 - 2
anki/CMakeLists.txt

@@ -6,8 +6,9 @@ SUBDIRS(${ANKI_LIBS})
 ADD_LIBRARY(anki ${ANKI_LIBS})
 
 TARGET_LINK_LIBRARIES(anki ${ANKI_LIBS} BulletSoftBody BulletDynamics 
-	BulletCollision LinearMath GLEWmx GLU GL jpeg SDL png python2.6
-	boost_system boost_python boost_filesystem boost_thread freetype)
+	BulletCollision LinearMath GLEWmx GLU GL jpeg SDL png python${PYTHON_VER}
+	boost_system boost_python boost_filesystem boost_thread boost_regex 
+	freetype)
 
 SET_TARGET_PROPERTIES(anki PROPERTIES LINKER_LANGUAGE CXX)
 

+ 1 - 1
anki/renderer/Renderer.cpp

@@ -13,7 +13,7 @@ Renderer::Renderer()
 		sceneDrawer(*this)
 {
 	enableStagesProfilingFlag = false;
-	lodDistance = 3.0;
+	lodDistance = 10.0;
 }
 
 

+ 1 - 0
anki/renderer/SceneDrawer.cpp

@@ -278,6 +278,7 @@ void SceneDrawer::renderRenderableNode(const Camera& cam,
 	float dist = (node.getWorldTransform().getOrigin() -
 		cam.getWorldTransform().getOrigin()).getLength();
 	uint lod = std::min(r.calculateLod(dist), mtl.getLevelsOfDetail() - 1);
+
 	PassLevelKey key(pass, lod);
 
 	// Setup shader

+ 4 - 3
anki/resource/Material.h

@@ -208,7 +208,7 @@ protected:
 ///
 /// 	[<passes>COLOR DEPTH</passes>] (2)
 ///
-/// 	[<levelsOfDetail>0 to N</levelsOfDetail>]
+/// 	[<levelsOfDetail>N</levelsOfDetail>]
 ///
 /// 	[<shadow>0 | 1</shadow>]
 ///
@@ -349,10 +349,11 @@ private:
 	/// Parse what is within the @code <material></material> @endcode
 	void parseMaterialTag(const boost::property_tree::ptree& pt);
 
-	/// XXX
+	/// Create a unique shader source in chache. If already exists do nothing
 	std::string createShaderProgSourceToCache(const std::string& source);
 
-	/// XXX
+	/// Read all shader programs and pupulate the @a vars and @a nameToVar
+	/// containers
 	void populateVariables(const boost::property_tree::ptree& pt);
 
 	/// Parses something like this: "0.0 0.01 -1.2" and returns a valid

+ 34 - 12
anki/resource/MaterialShaderProgramCreator.cpp

@@ -4,6 +4,7 @@
 #include <boost/foreach.hpp>
 #include <boost/property_tree/ptree.hpp>
 #include <boost/lexical_cast.hpp>
+#include <boost/regex.hpp>
 
 
 namespace anki {
@@ -148,8 +149,6 @@ void MaterialShaderProgramCreator::parseOperationTag(
 	const boost::property_tree::ptree& pt)
 {
 	using namespace boost::property_tree;
-	
-	std::stringstream line;
 
 	// <id></id>
 	int id = pt.get<int>("id");
@@ -157,24 +156,23 @@ void MaterialShaderProgramCreator::parseOperationTag(
 	// <returnType></returnType>
 	boost::optional<std::string> retTypeOpt =
 		pt.get_optional<std::string>("returnType");
-		
+
+	std::string operationOut;
 	if(retTypeOpt)
 	{
-		line << retTypeOpt.get() << " operationOut" << id << " = ";
+		operationOut = "operationOut" + boost::lexical_cast<std::string>(id);
 	}
 	
 	// <function>functionName</function>
 	const std::string& funcName = pt.get<std::string>("function");
 	
-	line << funcName << "(";
-	
 	// <arguments></arguments>
 	boost::optional<const ptree&> argsPt = pt.get_child_optional("arguments");
 	StringList argsList;
 	
 	if(argsPt)
 	{
-		// Write all arguments
+		// Get all arguments
 		ptree::const_iterator it = argsPt.get().begin();
 		for(; it != argsPt.get().end(); ++it)
 		{
@@ -190,15 +188,39 @@ void MaterialShaderProgramCreator::parseOperationTag(
 			const std::string& argName = v.second.data();
 			argsList.push_back(argName);
 		}
+	}
 
-		line << argsList.join(", ");
+	// Now write everything
+	std::stringstream line;
+	line << "#if defined(" << funcName << "_DEFINED)";
+
+	boost::regex expr("^operationOut[0-9]*$");
+	BOOST_FOREACH(const std::string& arg, argsList)
+	{
+		if(boost::regex_match(arg, expr))
+		{
+			line << " && defined(" << arg << "_DEFINED)";
+		}
+	}
+	line << "\n";
+
+	if(retTypeOpt)
+	{
+		line << "#\tdefine " << operationOut << "_DEFINED\n";
+		line << '\t' << retTypeOpt.get() << " " << operationOut << " = ";
+	}
+	else
+	{
+		line << '\t';
 	}
 	
-	line << ");";
+	line << funcName << "(";
+	line << argsList.join(", ");
+	line << ");\n";
+	line << "#endif";
 
-	srcLines.push_back("#if defined(" + funcName + "_DEFINED)");
-	srcLines.push_back("\t" + line.str());
-	srcLines.push_back("#endif");
+	// Done
+	srcLines.push_back(line.str());
 }
 
 

+ 0 - 4
shaders/MaterialFragmentFunctions.glsl

@@ -56,9 +56,6 @@ vec3 getNormalSimple(in vec3 normal)
 vec3 getEnvironmentColor(in vec3 vertPosViewSpace, in vec3 normal,
 	in sampler2D map)
 {
-#	if LOD > 0
-	return vec3(0.0);
-#	else
 	// In case of normal mapping I could play with vertex's normal but this 
 	// gives better results and its allready computed
 	
@@ -70,7 +67,6 @@ vec3 getEnvironmentColor(in vec3 vertPosViewSpace, in vec3 normal,
 
 	vec3 semCol = texture(map, semTexCoords).rgb;
 	return semCol;
-#	endif
 }
 #endif