Browse Source

Exporter work

Panagiotis Christopoulos Charitos 11 years ago
parent
commit
1b7a68e4f5

+ 1 - 6
include/anki/resource/RenderingKey.h

@@ -19,9 +19,6 @@ enum class Pass: U8
 	COUNT
 };
 
-/// Max level of detail
-const U MAX_LOD = 3;
-
 /// A key that consistst of the rendering pass and the level of detail
 class RenderingKey
 {
@@ -34,9 +31,7 @@ public:
 	:	m_pass(pass), 
 		m_lod(lod), 
 		m_tessellation(tessellation)
-	{
-		ANKI_ASSERT(lod <= MAX_LOD);
-	}
+	{}
 
 	RenderingKey()
 	:	RenderingKey(Pass::COLOR, 0, false)

+ 1 - 1
shaders/IsLp.frag.glsl

@@ -252,7 +252,7 @@ void main()
 #if 0
 	if(inInstanceId != 99999)
 	{
-		outColor = vec3(specColor);
+		outColor = vec3(specPower / 120.0);
 	}
 #endif
 

+ 2 - 2
testapp/Main.cpp

@@ -229,7 +229,7 @@ Error init()
 	{
 		ScriptResourcePointer script;
 
-		err = script.load("maps/sponza/scene.lua", &resources);
+		err = script.load("maps/adis/scene.lua", &resources);
 		if(err) return err;
 
 		err = app->getScriptManager().evalString(script->getSource());
@@ -499,7 +499,7 @@ Error initSubsystems(int argc, char* argv[])
 	config.set("is.sm.enabled", true);
 	config.set("is.sm.poissonEnabled", true);
 	config.set("is.sm.resolution", 1024);
-	config.set("pps.enabled", false);
+	config.set("pps.enabled", true);
 	config.set("pps.hdr.enabled", true);
 	config.set("pps.hdr.renderingQuality", 0.5);
 	config.set("pps.hdr.blurringDist", 1.0);

+ 112 - 16
tools/scene/Model.cpp

@@ -268,6 +268,7 @@ void exportMaterial(
 	std::string diffTex;
 	std::string normTex;
 	std::string specColTex;
+	std::string shininessTex;
 	std::string dispTex;
 
 	std::string name = getMaterialName(mtl, instanced);
@@ -315,6 +316,19 @@ void exportMaterial(
 		}
 	}
 
+	// Shininess color
+	if(mtl.GetTextureCount(aiTextureType_SHININESS) > 0)
+	{
+		if(mtl.GetTexture(aiTextureType_SHININESS, 0, &path) == AI_SUCCESS)
+		{
+			shininessTex = getFilename(path.C_Str());
+		}
+		else
+		{
+			ERROR("Failed to retrieve texture\n");
+		}
+	}
+
 	// Height texture
 	if(mtl.GetTextureCount(aiTextureType_EMISSIVE) > 0)
 	{	
@@ -344,11 +358,22 @@ void exportMaterial(
 	static const char* tessVertTemplate = 
 #include "templates/tessVert.h"
 		;
+	static const char* readRFromTextureTemplate = R"(
+				<operation>
+					<id>%id%</id>
+					<returnType>float</returnType>
+					<function>readRFromTexture</function>
+					<arguments>
+						<argument>%map%</argument>
+						<argument>out2</argument>
+					</arguments>
+				</operation>)";
 
 	// Compose full template
 	// First geometry part
 	std::string materialStr;
-	materialStr = "<material>\n\t<programs>\n";
+	materialStr = R"(<?xml version="1.0" encoding="UTF-8" ?>)";
+	materialStr += "\n<material>\n\t<programs>\n";
 	if(dispTex.empty())
 	{
 		materialStr += simpleVertTemplate;
@@ -365,13 +390,9 @@ void exportMaterial(
 	{
 		materialStr += diffFragTemplate;
 	}
-	else if(!specColTex.empty())
-	{
-		materialStr += diffNormSpecFragTemplate;
-	}
 	else
 	{
-		materialStr += diffNormFragTemplate;
+		materialStr += diffNormSpecFragTemplate;
 	}
 
 	materialStr += "\n\t</programs>\t</material>";
@@ -391,20 +412,95 @@ void exportMaterial(
 
 	if(!specColTex.empty())
 	{
-		materialStr = replaceAllString(materialStr, "%specularColorMap%", 
-			exporter.texrpath + specColTex);
+		materialStr = replaceAllString(materialStr, "%specularColorInput%", 
+			R"(<input><type>sampler2D</type><name>uSpecularColor</name><value>)"
+			+ exporter.texrpath + specColTex
+			+ R"(</value></input>)");
+
+		materialStr = replaceAllString(materialStr, "%specularColorFunc%", 
+			readRFromTextureTemplate);
+
+		materialStr = replaceAllString(materialStr, "%id%", 
+			"50");
+
+		materialStr = replaceAllString(materialStr, "%map%", 
+			"uSpecularColor");
+
+		materialStr = replaceAllString(materialStr, "%specularColorArg%", 
+			"out50");
 	}
+	else
+	{
+		aiColor3D specCol = {0.0, 0.0, 0.0};
+		mtl.Get(AI_MATKEY_COLOR_SPECULAR, specCol);
+
+		materialStr = replaceAllString(materialStr, "%specularColorInput%", 
+			R"(<input><type>float</type><name>uSpecularColor</name><value>)"
+			+ std::to_string((specCol[0] + specCol[1] + specCol[2]) / 3.0)
+			+ R"(</value></input>)");
 
-	aiColor3D specCol = {0.0, 0.0, 0.0};
-	mtl.Get(AI_MATKEY_COLOR_SPECULAR, specCol);
+		materialStr = replaceAllString(materialStr, "%specularColorFunc%", 
+			"");
 
-	float shininess = 0.0;
-	mtl.Get(AI_MATKEY_SHININESS, shininess);
+		materialStr = replaceAllString(materialStr, "%specularColorArg%", 
+			"uSpecularColor");
+	}
+
+	if(!shininessTex.empty())
+	{
+		materialStr = replaceAllString(materialStr, "%specularPowerInput%", 
+			R"(<input><type>sampler2D</type><name>uSpecularPower</name><value>)"
+			+ exporter.texrpath + shininessTex
+			+ R"(</value></input>)" + "\n"
+			+ "\t\t\t\t" 
+			+ R"(<input><type>float</type><name>MAX_SPECULAR_POWER</name>)"
+			+ R"(<value>120.0</value><const>1</const></input>)");
+
+		materialStr = replaceAllString(materialStr, "%specularPowerValue%", 
+			exporter.texrpath + shininessTex);
+
+			static const char* multiply = R"(
+				<operation>
+					<id>61</id>
+					<returnType>float</returnType>
+					<function>mul</function>
+					<arguments>
+						<argument>MAX_SPECULAR_POWER</argument>
+						<argument>out60</argument>
+					</arguments>
+				</operation>)";
+
+		std::string func = std::string(readRFromTextureTemplate) + multiply;
+
+		materialStr = replaceAllString(materialStr, "%specularPowerFunc%", 
+			func);
+
+		materialStr = replaceAllString(materialStr, "%id%", 
+			"60");
+
+		materialStr = replaceAllString(materialStr, "%map%", 
+			"uSpecularPower");
+
+		materialStr = replaceAllString(materialStr, "%specularPowerArg%", 
+			"out61");
+	}
+	else
+	{
+		float shininess = 0.0;
+		mtl.Get(AI_MATKEY_SHININESS, shininess);
+		materialStr = replaceAllString(materialStr, "%specularPowerInput%", 
+			R"(<input><type>float</type><name>uSpecularPower</name><value>)"
+			+ std::to_string(shininess)
+			+ R"(</value></input>)");
+
+		materialStr = replaceAllString(materialStr, "%specularPowerFunc%", 
+			"");
+
+		materialStr = replaceAllString(materialStr, "%specularPowerArg%", 
+			"uSpecularPower");
+	}
 
-	materialStr = replaceAllString(materialStr, "%specularColor%", 
-		std::to_string((specCol[0] + specCol[1] + specCol[2]) / 3.0));
-	materialStr = replaceAllString(materialStr, "%specularPower%", 
-		std::to_string(shininess));
+	materialStr = replaceAllString(materialStr, "%maxSpecularPower%", " ");
 
 	materialStr = replaceAllString(materialStr, "%instanced%", 
 		(instanced) ? "1" : "0");

+ 8 - 14
tools/scene/templates/diffNormSpecFrag.h

@@ -6,11 +6,11 @@ R"(		<program>
 			</includes>
 
 			<inputs>
-				<input><type>float</type><name>uSpecularPower</name><value>%specularPower%</value></input>
+				%specularColorInput%
+				%specularPowerInput%
 				<input><type>float</type><name>uBlurring</name><value>0.0</value><const>1</const></input>
 				<input><type>sampler2D</type><name>uDiffuseMap</name><value>%diffuseMap%</value></input>
 				<input><type>sampler2D</type><name>uNormalMap</name><value>%normalMap%</value></input>
-				<input><type>sampler2D</type><name>uSpecularColorMap</name><value>%specularColorMap%</value></input>
 			</inputs>
 			
 			<operations>
@@ -50,25 +50,19 @@ R"(		<program>
 						<argument>out2</argument>
 					</arguments>
 				</operation>
-				<operation>
-					<id>30</id>
-					<returnType>float</returnType>
-					<function>readRFromTexture</function>
-					<arguments>
-						<argument>uSpecularColorMap</argument>
-						<argument>out2</argument>
-					</arguments>
-				</operation>
+
+				%specularColorFunc%
+				%specularPowerFunc%
 				
 				<operation>
-					<id>40</id>
+					<id>100</id>
 					<returnType>void</returnType>
 					<function>writeRts</function>
 					<arguments>
 						<argument>out10</argument>
 						<argument>out20</argument>
-						<argument>out30</argument>
-						<argument>uSpecularPower</argument>
+						<argument>%specularColorArg%</argument>
+						<argument>%specularPowerArg%</argument>
 						<argument>uBlurring</argument>
 					</arguments>
 				</operation>