Ver código fonte

Adding sharpen filter in PPS

Panagiotis Christopoulos Charitos 12 anos atrás
pai
commit
93ca54d4b0

+ 18 - 13
include/anki/Config.h.cmake

@@ -14,13 +14,16 @@
 #define ANKI_WINDOW_BACKEND_EGLX11 2
 #define ANKI_WINDOW_BACKEND_EGLFBDEV 3
 #define ANKI_WINDOW_BACKEND ANKI_WINDOW_BACKEND_${ANKI_WINDOW_BACKEND}
+#define ANKI_WINDOW_BACKEND_STR "ANKI_WINDOW_BACKEND_${ANKI_WINDOW_BACKEND}"
 
 #define ANKI_GL_DESKTOP 1
 #define ANKI_GL_ES 2
 #if ANKI_WINDOW_BACKEND == ANKI_WINDOW_BACKEND_GLXX11
 #	define ANKI_GL ANKI_GL_DESKTOP
+#	define ANKI_GL_STR "ANKI_GL_DESKTOP"
 #else
 #	define ANKI_GL ANKI_GL_ES
+#	define ANKI_GL_STR "ANKI_GL_ES"
 #endif
 
 #if defined(NDEBUG)
@@ -29,27 +32,16 @@
 #	define ANKI_DEBUG 1
 #endif
 
-#define ANKI_FILE __FILE__
-#define ANKI_FUNC __func__
-
-#if defined(__GNUC__)
-#	define ANKI_LIKELY(x) __builtin_expect((x), 1)
-#	define ANKI_UNLIKELY(x) __builtin_expect((x), 0)
-#	define ANKI_RESTRICT __restrict
-#else
-#	define ANKI_LIKELY(x) ((x) == 1)
-#	define ANKI_UNLIKELY(x) ((x) == 1)
-#	define ANKI_RESTRICT
-#endif
-
 #define ANKI_CPU_ARCH_INTEL 1
 #define ANKI_CPU_ARCH_ARM 2
 
 #if defined(__GNUC__)
 #	if defined(__arm__)
 #		define ANKI_CPU_ARCH ANKI_CPU_ARCH_ARM
+#		define ANKI_CPU_ARCH_STR "ANKI_CPU_ARCH_ARM"
 #	elif defined(__i386__) || defined(__amd64__)
 #		define ANKI_CPU_ARCH ANKI_CPU_ARCH_INTEL
+#		define ANKI_CPU_ARCH_STR "ANKI_CPU_ARCH_INTEL"
 #	else
 #		error "Unknown CPU arch"
 #	endif
@@ -57,4 +49,17 @@
 #	error "Unsupported compiler"
 #endif
 
+#define ANKI_FILE __FILE__
+#define ANKI_FUNC __func__
+
+#if defined(__GNUC__)
+#	define ANKI_LIKELY(x) __builtin_expect((x), 1)
+#	define ANKI_UNLIKELY(x) __builtin_expect((x), 0)
+#	define ANKI_RESTRICT __restrict
+#else
+#	define ANKI_LIKELY(x) ((x) == 1)
+#	define ANKI_UNLIKELY(x) ((x) == 1)
+#	define ANKI_RESTRICT
+#endif
+
 #endif

+ 7 - 1
include/anki/util/Allocator.h

@@ -193,7 +193,13 @@ inline bool operator!=(const Allocator<T1>&, const AnotherAllocator&)
 ///
 /// @note Don't ever EVER remove the double copy constructor and the double
 ///       operator=. The compiler will create defaults
-template<typename T, Bool deallocationFlag = false, U32 alignmentBits = 16>
+template<typename T, Bool deallocationFlag = false,
+#if ANKI_CPU_ARCH == ANKI_CPU_ARCH_INTEL
+	U32 alignmentBits = 16
+#elif ANKI_CPU_ARCH == ANKI_CPU_ARCH_ARM
+	U32 alignmentBits = 32
+#endif
+	>
 class StackAllocator
 {
 	template<typename U, Bool deallocationFlag_, U32 alignmentBits_>

+ 48 - 6
shaders/Pps.glsl

@@ -16,6 +16,18 @@ in vec2 vTexCoords;
 
 layout(location = 0) out vec3 fColor;
 
+const vec2 TEX_OFFSET = vec2(1.0 / FBO_WIDTH, 1.0 / FBO_HEIGHT);
+
+vec2 KERNEL[8] = vec2[](
+	vec2(TEX_OFFSET.x, TEX_OFFSET.y),
+	vec2(0.0, TEX_OFFSET.y),
+	vec2(-TEX_OFFSET.x, TEX_OFFSET.y),
+	vec2(-TEX_OFFSET.x, 0.0),
+	vec2(-TEX_OFFSET.x, -TEX_OFFSET.y),
+	vec2(0.0, -TEX_OFFSET.y),
+	vec2(TEX_OFFSET.x, -TEX_OFFSET.y),
+	vec2(TEX_OFFSET.x, 0.0));
+
 //==============================================================================
 vec3 grayScale(in vec3 col)
 {
@@ -44,10 +56,45 @@ vec3 gammaCorrectionRgb(in vec3 gamma, in vec3 col)
 	return pow(col, 1.0 / gamma);
 }
 
+//==============================================================================
+vec3 sharpen(in sampler2D tex, in vec2 texCoords)
+{
+	const vec2 TEX_OFFSET = vec2(1.0 / FBO_WIDTH, 1.0 / FBO_HEIGHT);
+
+	const float sharpenFactor = 0.25;
+
+	vec3 col = texture(tex, texCoords).rgb;
+
+	vec3 col2 = texture(tex, texCoords + KERNEL[0]).rgb;
+	for(int i = 1; i < 8; i++)
+	{
+		col2 += texture(tex, texCoords + KERNEL[i]).rgb;
+	}
+
+	return col * (9.0 * sharpenFactor + 1.0 - sharpenFactor) 
+		- sharpenFactor * col2;
+}
+
+//==============================================================================
+vec3 erosion(in sampler2D tex, in vec2 texCoords)
+{
+    vec3 minValue = texture(tex, texCoords).rgb;
+
+    for (int i = 0; i < 8; i++)
+    {
+        vec3 tmpCol = texture(tex, texCoords + KERNEL[i]).rgb;
+        minValue = min(tmpCol, minValue);
+    }
+
+    return minValue;
+}
+
 //==============================================================================
 void main(void)
 {
-	fColor = texture(isFai, vTexCoords).rgb;
+	fColor = sharpen(isFai, vTexCoords);
+	//fColor = erosion(isFai, vTexCoords);
+	//fColor = texture(isFai, vTexCoords).rgb;
 
 #if defined(HDR_ENABLED)
 	vec3 hdr = texture(ppsHdrFai, vTexCoords).rgb;
@@ -59,11 +106,6 @@ void main(void)
 	fColor *= ssao;
 #endif
 
-	/*float fog = 1.0 - readFromTextureAndLinearizeDepth(msDepthFai, 
-		vTexCoords, 0.1, 10.0);
-	fColor *= ;*/
-
-	//fColor = BlendHardLight(vec3(0.6, 0.62, 0.4), fColor);
 	fColor = gammaCorrectionRgb(vec3(0.9, 0.92, 0.75), fColor);
 
 #if 0

+ 6 - 2
src/core/App.cpp

@@ -144,9 +144,13 @@ void App::printAppInfo()
 #else
 	msg << "Debug";
 #endif
-	msg << " build, ";
+	msg << " build,";
 
-	msg << "build date " __DATE__ ", " << "rev " << ANKI_REVISION;
+	msg << " " << ANKI_CPU_ARCH_STR;
+	msg << " " << ANKI_GL_STR;
+	msg << " " << ANKI_WINDOW_BACKEND_STR;
+
+	msg << " build date " __DATE__ ", " << "rev " << ANKI_REVISION;
 
 	ANKI_LOGI(msg.str());
 }

+ 3 - 0
src/renderer/Pps.cpp

@@ -47,6 +47,9 @@ void Pps::initInternal(const RendererInitializer& initializer)
 		pps += "#define HDR_ENABLED\n";
 	}
 
+	pps += "#define FBO_WIDTH " + std::to_string(r->getWidth()) + "\n";
+	pps += "#define FBO_HEIGHT " + std::to_string(r->getHeight()) + "\n";
+
 	prog.load(ShaderProgramResource::createSrcCodeToCache(
 		"shaders/Pps.glsl", pps.c_str()).c_str());
 }

+ 65 - 16
src/resource/MeshLoader.cpp

@@ -2,16 +2,42 @@
 #include "anki/util/BinaryStream.h"
 #include <fstream>
 #include <cstring>
+#include <unordered_map>
 
 namespace anki {
 
-std::string lala;
+//==============================================================================
+// Misc                                                                        =
+//==============================================================================
+
+/// The hash functor
+struct Hasher
+{
+	size_t operator()(const Vec3& pos) const
+	{
+		F32 sum = pos.x() * 100.0 + pos.y() * 10.0 + pos.z();
+		size_t hash = 0;
+		memcpy(&hash, &sum, sizeof(F32));
+		return hash;
+	}
+};
+
+/// The value of the hash map
+struct MapValue
+{
+	U8 indicesCount = 0;
+	Array<U32, 16> indices;
+};
+
+typedef std::unordered_map<Vec3, MapValue, Hasher> FixNormalsMap;
+
+//==============================================================================
+// MeshLoader                                                                  =
+//==============================================================================
 
 //==============================================================================
 void MeshLoader::load(const char* filename)
 {
-	lala = filename;
-
 	// Try
 	try
 	{
@@ -274,35 +300,58 @@ void MeshLoader::createVertTangents()
 //==============================================================================
 void MeshLoader::fixNormals()
 {
-	const F32 positionsDistanceThresh = getEpsilon<F32>() * getEpsilon<F32>();
+	FixNormalsMap map;
 
+	// For all verts
 	for(U i = 1; i < vertCoords.size(); i++)
 	{
-		const Vec3& crntPos = vertCoords[i];
-		Vec3& crntNormal = vertNormals[i];
+		const Vec3& pos = vertCoords[i];
+		Vec3& norm = vertNormals[i];
+
+		// Find pos
+		FixNormalsMap::iterator it = map.find(pos);
+
+		// Check if found
+		if(it == map.end())
+		{
+			// Not found
 
-		// Check the previous
-		for(U j = 0; j < i; j++)
+			MapValue val;
+			val.indices[0] = i;
+			val.indicesCount = 1;
+			map[pos] = val;
+		}
+		else
 		{
-			const Vec3& otherPos = vertCoords[j];
-			Vec3& otherNormal = vertNormals[j];
+			// Found
 
-			F32 distanceSq = crntPos.getDistanceSquared(otherPos);
+			MapValue& mapVal = it->second;
+			ANKI_ASSERT(mapVal.indicesCount > 0);
 
-			if(distanceSq <= positionsDistanceThresh)
+			// Search the verts with the same position
+			for(U j = 0; j < mapVal.indicesCount; j++)
 			{
-				F32 dot = crntNormal.dot(otherNormal);
+				const Vec3& posB = vertCoords[mapVal.indices[j]];
+				Vec3& normB = vertNormals[mapVal.indices[j]];
+
+				ANKI_ASSERT(posB == pos);
+				(void)posB;
+
+				F32 dot = norm.dot(normB);
 				F32 ang = acos(dot);
 
 				if(ang <= NORMALS_ANGLE_MERGE)
 				{
-					Vec3 newNormal = (crntNormal + otherNormal) * 0.5;
+					Vec3 newNormal = (norm + normB) * 0.5;
 					newNormal.normalize();
 
-					crntNormal = newNormal;
-					otherNormal = newNormal;
+					norm = newNormal;
+					normB = newNormal;
 				}
 			}
+
+			// Update the map
+			mapVal.indices[mapVal.indicesCount++] = i;
 		}
 	}
 }

+ 1 - 3
testapp/Main.cpp

@@ -466,7 +466,7 @@ void mainLoop()
 
 		// Sleep
 		//
-#if 0
+#if 1
 		timer.stop();
 		if(timer.getElapsedTime() < AppSingleton::get().getTimerTick())
 		{
@@ -480,8 +480,6 @@ void mainLoop()
 		}
 #endif
 		Timestamp::increaseTimestamp();
-
-		std::cout << "frame ends" << std::endl;
 	}
 
 #if 0