Browse Source

Having working tessellation. Need to fix some small bugs and optimize

Panagiotis Christopoulos Charitos 11 years ago
parent
commit
f858a05e9c

+ 3 - 0
include/anki/gl/GlCommandBufferHandle.h

@@ -127,6 +127,9 @@ public:
 	/// Enable/disable polygon offset
 	/// Enable/disable polygon offset
 	void enablePolygonOffset(Bool enable);
 	void enablePolygonOffset(Bool enable);
 
 
+	/// Set polygon mode
+	void setPolygonMode(GLenum face, GLenum mode);
+
 	/// Bind many textures
 	/// Bind many textures
 	/// @param first The unit where the first texture will be bound
 	/// @param first The unit where the first texture will be bound
 	/// @param textures A list of textures to bind
 	/// @param textures A list of textures to bind

+ 1 - 1
include/anki/resource/Material.h

@@ -201,7 +201,7 @@ public:
 		return m_depthTesting;
 		return m_depthTesting;
 	}
 	}
 
 
-	Bool getWireframe() const
+	Bool getWireframeEnabled() const
 	{
 	{
 		return m_wireframe;
 		return m_wireframe;
 	}
 	}

+ 16 - 16
shaders/MsCommonTessc.glsl

@@ -172,6 +172,21 @@ bool isFaceOutsideClipSpace(in vec2 posNdc[3])
 		posOutsideClipSpace(posNdc[2])));
 		posOutsideClipSpace(posNdc[2])));
 }
 }
 
 
+// Check if a face is visible
+bool isFaceVisible(in mat4 mvp)
+{
+	// Calculate clip positions
+	vec2 clip[3];
+	for(int i = 0 ; i < 3 ; i++) 
+	{
+		vec4 v = mvp * IN_POS4(i);
+		clip[i] = v.xy / (v.w * 0.5 + 0.5);
+	}
+
+	// Check the face orientation and clipping
+	return isFaceFrontFacing(clip) && !isFaceOutsideClipSpace(clip);
+}
+
 void setSilhouetteTessLevels(in mat3 normalMat, in float maxTessLevel)
 void setSilhouetteTessLevels(in mat3 normalMat, in float maxTessLevel)
 {
 {
 	// Calculate the normals in view space
 	// Calculate the normals in view space
@@ -204,21 +219,6 @@ void discardPatch()
 	gl_TessLevelInner[0] = 0.0;
 	gl_TessLevelInner[0] = 0.0;
 }
 }
 
 
-// Check if a face is visible
-bool isFaceVisible(in mat4 mvp)
-{
-	// Calculate clip positions
-	vec2 clip[3];
-	for(int i = 0 ; i < 3 ; i++) 
-	{
-		vec4 v = mvp * IN_POS4(i);
-		clip[i] = v.xy / abs(v.w);
-	}
-
-	// Check the face orientation and clipping
-	return isFaceFrontFacing(clip) && !isFaceOutsideClipSpace(clip);
-}
-
 // Used in phong method
 // Used in phong method
 float calcPhongTerm(int ivId, int i, vec3 q)
 float calcPhongTerm(int ivId, int i, vec3 q)
 {
 {
@@ -315,7 +315,7 @@ void tessellateDispMapPositionNormalTangentTexCoord(
 	{
 	{
 		if(isFaceVisible(mvp))
 		if(isFaceVisible(mvp))
 		{
 		{
-			setSilhouetteTessLevels(normalMat, maxTessLevel);
+			setConstantTessLevels(maxTessLevel);
 
 
 #if INSTANCE_ID_FRAGMENT_SHADER
 #if INSTANCE_ID_FRAGMENT_SHADER
 			commonPatch.instanceId = inInstanceId[0];
 			commonPatch.instanceId = inInstanceId[0];

+ 6 - 0
src/gl/GlCommandBufferHandle.cpp

@@ -393,6 +393,12 @@ void GlCommandBufferHandle::enablePolygonOffset(Bool enable)
 	ANKI_STATE_CMD_ENABLE(GL_POLYGON_OFFSET_FILL, enable);
 	ANKI_STATE_CMD_ENABLE(GL_POLYGON_OFFSET_FILL, enable);
 }
 }
 
 
+//==============================================================================
+void GlCommandBufferHandle::setPolygonMode(GLenum face, GLenum mode)
+{
+	ANKI_STATE_CMD_2(GLenum, glPolygonMode, face, mode);
+}
+
 //==============================================================================
 //==============================================================================
 void GlCommandBufferHandle::bindTextures(U32 first, 
 void GlCommandBufferHandle::bindTextures(U32 first, 
 	const std::initializer_list<GlTextureHandle>& textures)
 	const std::initializer_list<GlTextureHandle>& textures)

+ 0 - 2
src/gl/GlState.cpp

@@ -129,8 +129,6 @@ void GlState::init()
 	}
 	}
 #endif
 #endif
 
 
-	glEnable(GL_PROGRAM_POINT_SIZE);
-
 	// Buffer offset alignment
 	// Buffer offset alignment
 	GLint64 alignment;
 	GLint64 alignment;
 	glGetInteger64v(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &alignment);
 	glGetInteger64v(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &alignment);

+ 12 - 3
src/renderer/Drawer.cpp

@@ -355,9 +355,12 @@ void RenderableDrawer::render(SceneNode& frsn, VisibleNode& visibleNode)
 			mtl.getBlendingSfactor(), mtl.getBlendingDfactor());
 			mtl.getBlendingSfactor(), mtl.getBlendingDfactor());
 	}
 	}
 
 
-#if ANKI_GL == ANKI_GL_DESKTOP
-	// TODO Set wireframe
-#endif
+	// Wireframe
+	Bool wireframeOn = mtl.getWireframeEnabled();
+	if(wireframeOn)
+	{
+		m_cmdBuff.setPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+	}
 
 
 	// Enqueue uniform state updates
 	// Enqueue uniform state updates
 	setupUniforms(visibleNode, renderable, fr, flod);
 	setupUniforms(visibleNode, renderable, fr, flod);
@@ -368,6 +371,12 @@ void RenderableDrawer::render(SceneNode& frsn, VisibleNode& visibleNode)
 	build.m_jobs = m_cmdBuff;
 	build.m_jobs = m_cmdBuff;
 
 
 	renderable.buildRendering(build);
 	renderable.buildRendering(build);
+
+	// Wireframe back to what it was
+	if(wireframeOn)
+	{
+		m_cmdBuff.setPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+	}
 }
 }
 
 
 //==============================================================================
 //==============================================================================

+ 1 - 1
thirdparty

@@ -1 +1 @@
-Subproject commit f81dba85720a5b409bcb403d6430cc078f819208
+Subproject commit 00c2e2af187b5f2ead3c6c829a495d72d65acce5

+ 31 - 3
tools/scene/Model.cpp

@@ -267,6 +267,7 @@ void exportMaterial(
 {
 {
 	std::string diffTex;
 	std::string diffTex;
 	std::string normTex;
 	std::string normTex;
+	std::string dispTex;
 
 
 	std::string name = getMaterialName(mtl, instanced);
 	std::string name = getMaterialName(mtl, instanced);
 	LOGI("Exporting material %s\n", name.c_str());
 	LOGI("Exporting material %s\n", name.c_str());
@@ -300,6 +301,19 @@ void exportMaterial(
 		}
 		}
 	}
 	}
 
 
+	// Height texture
+	if(mtl.GetTextureCount(aiTextureType_EMISSIVE) > 0)
+	{	
+		if(mtl.GetTexture(aiTextureType_EMISSIVE, 0, &path) == AI_SUCCESS)
+		{
+			dispTex = getFilename(path.C_Str());
+		}
+		else
+		{
+			ERROR("Failed to retrieve texture\n");
+		}
+	}
+
 	// Write file
 	// Write file
 	static const char* diffMtlStr = 
 	static const char* diffMtlStr = 
 #include "diffTemplateMtl.h"
 #include "diffTemplateMtl.h"
@@ -307,20 +321,34 @@ void exportMaterial(
 	static const char* diffNormMtlStr = 
 	static const char* diffNormMtlStr = 
 #include "diffNormTemplateMtl.h"
 #include "diffNormTemplateMtl.h"
 		;
 		;
+	static const char* tessDispMtlStr = 
+#include "tessDispTemplateMtl.h"
+		;
 
 
 	std::fstream file;
 	std::fstream file;
 	file.open(exporter.outDir + name + ".ankimtl", std::ios::out);
 	file.open(exporter.outDir + name + ".ankimtl", std::ios::out);
 
 
 	// Chose the correct template
 	// Chose the correct template
 	std::string str;
 	std::string str;
-	if(normTex.size() == 0)
+	if(normTex.empty())
 	{
 	{
 		str = diffMtlStr;
 		str = diffMtlStr;
 	}
 	}
 	else
 	else
 	{
 	{
-		str = replaceAllString(diffNormMtlStr, "%normalMap%", 
-			exporter.texrpath + normTex);
+		if(dispTex.empty())
+		{
+			str = replaceAllString(diffNormMtlStr, "%normalMap%", 
+				exporter.texrpath + normTex);
+		}
+		else
+		{
+			str = replaceAllString(tessDispMtlStr, "%normalMap%", 
+				exporter.texrpath + normTex);
+
+			str = replaceAllString(str, "%dispMap%", 
+				exporter.texrpath + dispTex);
+		}
 	}
 	}
 
 
 	aiColor3D specCol = {0.0, 0.0, 0.0};
 	aiColor3D specCol = {0.0, 0.0, 0.0};

+ 140 - 0
tools/scene/tessDispTemplateMtl.h

@@ -0,0 +1,140 @@
+R"(<?xml version="1.0" encoding="UTF-8" ?>
+
+<material>
+	<programs>
+		<program>
+			<type>vert</type>
+			<includes>
+				<include>shaders/MsCommonVert.glsl</include>
+			</includes>
+
+			<inputs>
+				<input><type>mat4</type><name>uMvp</name><value></value><instanced>%instanced%</instanced></input>
+				<input><type>mat3</type><name>uN</name><value></value><instanced>%instanced%</instanced></input>
+			</inputs>
+
+			<operations>
+				<operation>
+					<id>1</id>
+					<returnType>void</returnType>
+					<function>writePositionNormalTangentTexCoord</function>
+					<arguments><argument>uMvp</argument><argument>uN</argument></arguments>
+				</operation>
+			</operations>
+		</program>
+
+		<program>
+			<type>tesc</type>
+			<includes><include>shaders/MsCommonTessc.glsl</include></includes>
+
+			<inputs>
+				<input><type>float</type><name>uMaxTessLevel</name><value>12.0</value></input>
+				<input><type>mat4</type><name>uMvp</name><value></value></input>
+				<input><type>mat3</type><name>uN</name><value></value></input>
+			</inputs>
+
+			<operations>
+				<operation>
+					<id>0</id>
+					<returnType>void</returnType>
+					<function>tessellateDispMapPositionNormalTangentTexCoord</function>
+					<arguments>
+						<argument>uMaxTessLevel</argument>
+						<argument>uMvp</argument>
+						<argument>uN</argument>
+					</arguments>
+				</operation>
+			</operations>
+		</program>
+
+		<program>
+			<type>tese</type>
+			<includes><include>shaders/MsCommonTesse.glsl</include></includes>
+
+			<inputs>
+				<input><type>mat4</type><name>uMvp</name><value></value></input>
+				<input><type>mat3</type><name>uN</name><value></value></input>
+				<input><type>sampler2D</type><name>dispMap</name><value>%dispMap%</value></input>
+			</inputs>
+
+			<operations>
+				<operation>
+					<id>0</id>
+					<returnType>void</returnType>
+					<function>tessellateDispMapPositionNormalTangentTexCoord</function>
+					<arguments>
+						<argument>uMvp</argument>
+						<argument>uN</argument>
+						<argument>dispMap</argument>
+					</arguments>
+				</operation>
+			</operations>
+		</program>
+
+		<program>
+			<type>frag</type>
+
+			<includes>
+				<include>shaders/MsCommonFrag.glsl</include>
+			</includes>
+
+			<inputs>
+				<input><type>vec2</type><name>uSpecular</name><value>%specularColor% %specularPower%</value></input>
+				<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>
+			</inputs>
+			
+			<operations>
+				<operation>
+					<id>0</id>
+					<returnType>vec3</returnType>
+					<function>getNormal</function>
+				</operation>
+				<operation>
+					<id>1</id>
+					<returnType>vec4</returnType>
+					<function>getTangent</function>
+				</operation>
+				<operation>
+					<id>2</id>
+					<returnType>vec2</returnType>
+					<function>getTextureCoord</function>
+				</operation>
+
+				<operation>
+					<id>10</id>
+					<returnType>vec3</returnType>
+					<function>readRgbFromTexture</function>
+					<arguments>
+						<argument>uDiffuseMap</argument>
+						<argument>out2</argument>
+					</arguments>
+				</operation>
+				<operation>
+					<id>20</id>
+					<returnType>vec3</returnType>
+					<function>readNormalFromTexture</function>
+					<arguments>
+						<argument>out0</argument>
+						<argument>out1</argument>
+						<argument>uNormalMap</argument>
+						<argument>out2</argument>
+					</arguments>
+				</operation>
+				<operation>
+					<id>30</id>
+					<returnType>void</returnType>
+					<function>writeRts</function>
+					<arguments>
+						<argument>out10</argument>
+						<argument>out20</argument>
+						<argument>uSpecular</argument>
+						<argument>uBlurring</argument>
+					</arguments>
+				</operation>
+			</operations>
+		</program>
+	</programs>
+</material>)"
+