Browse Source

Tiler changes

Panagiotis Christopoulos Charitos 10 years ago
parent
commit
8c92105d39

+ 9 - 0
include/anki/renderer/Tiler.h

@@ -84,6 +84,14 @@ public:
 	/// @param[in, out] params The collision parameters.
 	/// @param[in, out] params The collision parameters.
 	Bool test(TestParameters& params) const;
 	Bool test(TestParameters& params) const;
 
 
+	/// @privatesection
+	/// @{
+	GlTextureHandle& getRt()
+	{
+		return m_rt;
+	}
+	/// @}
+
 private:
 private:
 	/// Tile planes
 	/// Tile planes
 	DArray<Plane> m_allPlanes;
 	DArray<Plane> m_allPlanes;
@@ -104,6 +112,7 @@ private:
 	/// PBO buffer that is used to read the data of fai asynchronously
 	/// PBO buffer that is used to read the data of fai asynchronously
 	Array<GlBufferHandle, 2> m_pbos;
 	Array<GlBufferHandle, 2> m_pbos;
 	Array<Vec2*, 2> m_pbosAddress;
 	Array<Vec2*, 2> m_pbosAddress;
+	DArray<Vec2> m_prevMinMaxDepth;
 
 
 	/// Main shader program
 	/// Main shader program
 	ProgramResourcePointer m_frag;
 	ProgramResourcePointer m_frag;

+ 7 - 1
shaders/Final.frag.glsl

@@ -19,6 +19,12 @@ layout(location = 0) out vec3 outFragColor;
 void main()
 void main()
 {
 {
 	vec3 col = textureRt(uRasterImage, inTexCoords).rgb;
 	vec3 col = textureRt(uRasterImage, inTexCoords).rgb;
-	//vec3 col = vec3(textureRt(uRasterImage, inTexCoords).r);
+	
+	/*vec2 depth = textureRt(uRasterImage, inTexCoords).rg;
+	float zNear = 0.2;
+	float zFar = 200.0;
+	depth = (2.0 * zNear) / (zFar + zNear - depth * (zFar - zNear));
+	vec3 col = vec3(depth.rg, 0.0);*/
+
 	outFragColor = col;
 	outFragColor = col;
 }
 }

+ 1 - 1
shaders/IsLp.frag.glsl

@@ -348,7 +348,7 @@ void main()
 #if 0
 #if 0
 	if(pointLightsCount != 0)
 	if(pointLightsCount != 0)
 	{
 	{
-		out_color = vec3(0.5 / float(pointLightsCount));
+		out_color += vec3(float(pointLightsCount) * 0.05);
 	}
 	}
 
 
 	/*uint x = in_instanceId % 60;
 	/*uint x = in_instanceId % 60;

+ 1 - 1
src/renderer/MainRenderer.cpp

@@ -96,7 +96,7 @@ Error MainRenderer::render(SceneGraph& scene)
 			rt = &getIs()._getRt();
 			rt = &getIs()._getRt();
 		}
 		}
 
 
-		//rt = &getDp().getSmallDepthRt();
+		//rt = &getTiler().getRt();
 		//rt = &getIs()._getRt();
 		//rt = &getIs()._getRt();
 
 
 		rt->setFilter(lastJobs, GlTextureHandle::Filter::LINEAR);
 		rt->setFilter(lastJobs, GlTextureHandle::Filter::LINEAR);

+ 0 - 2
src/renderer/Renderer.cpp

@@ -62,9 +62,7 @@ Error Renderer::initInternal(const ConfigSet& config)
 	m_defaultFbWidth = config.get("width");
 	m_defaultFbWidth = config.get("width");
 	m_defaultFbHeight = config.get("height");
 	m_defaultFbHeight = config.get("height");
 	m_width = m_defaultFbWidth * m_renderingQuality;
 	m_width = m_defaultFbWidth * m_renderingQuality;
-	alignRoundDown(16, m_width);
 	m_height = m_defaultFbHeight * m_renderingQuality;
 	m_height = m_defaultFbHeight * m_renderingQuality;
-	alignRoundDown(16, m_height);
 	m_lodDistance = config.get("lodDistance");
 	m_lodDistance = config.get("lodDistance");
 	m_framesNum = 0;
 	m_framesNum = 0;
 	m_samples = config.get("samples");
 	m_samples = config.get("samples");

+ 32 - 6
src/renderer/Tiler.cpp

@@ -59,6 +59,7 @@ Tiler::Tiler(Renderer* r)
 Tiler::~Tiler()
 Tiler::~Tiler()
 {
 {
 	m_allPlanes.destroy(getAllocator());
 	m_allPlanes.destroy(getAllocator());
+	m_prevMinMaxDepth.destroy(getAllocator());
 }
 }
 
 
 //==============================================================================
 //==============================================================================
@@ -153,6 +154,13 @@ Error Tiler::initInternal()
 	cmdBuff.flush();
 	cmdBuff.flush();
 
 
 	err = initPbos();
 	err = initPbos();
+	if(err)
+	{
+		return err;
+	}
+
+	err = m_prevMinMaxDepth.create(getAllocator(),
+		m_r->getTilesCount().x() * m_r->getTilesCount().y(), Vec2(0.0, 1.0));
 
 
 	return err;
 	return err;
 }
 }
@@ -695,14 +703,32 @@ void Tiler::update(U32 threadId, PtrSize threadsCount,
 
 
 		for(U k = start; k < end; ++k)
 		for(U k = start; k < end; ++k)
 		{
 		{
-			// Calculate depth as you do it for the vertex position inside
-			// the shaders
-			F32 minZ = projParams.z() / (projParams.w() + pixels[k][0]);
-			F32 maxZ = projParams.z() / (projParams.w() + pixels[k][1]);
+			Vec2 minMax = pixels[k];
+
+			// Adjust min max on extreme cases
+			Vec2& prevMinMax = m_prevMinMaxDepth[k];
+			const F32 fact = 0.035;
+
+			if(minMax[0] > prevMinMax[0])
+			{
+				// New depths is closer to the eye. Need to adjust it
+				minMax[0] = minMax[0] * fact + prevMinMax[0] * (1.0 - fact);
+			}
+
+			if(minMax[1] < prevMinMax[1])
+			{
+				// New depths is closer to the eye. Need to adjust it
+				minMax[1] = minMax[1] * fact + prevMinMax[1] * (1.0 - fact);
+			}
+
+			prevMinMax = minMax;
+
+			// Calculate the viewspace Z
+			minMax = projParams.z() / (projParams.w() + minMax);
 
 
 			// Calc the planes
 			// Calc the planes
-			Plane nearPlane = Plane(Vec4(0.0, 0.0, -1.0, 0.0), -minZ);
-			Plane farPlane = Plane(Vec4(0.0, 0.0, 1.0, 0.0), maxZ);
+			Plane nearPlane = Plane(Vec4(0.0, 0.0, -1.0, 0.0), -minMax.x());
+			Plane farPlane = Plane(Vec4(0.0, 0.0, 1.0, 0.0), minMax.y());
 
 
 			// Tranform them
 			// Tranform them
 			m_nearPlanesW[k] = nearPlane.getTransformed(trf);
 			m_nearPlanesW[k] = nearPlane.getTransformed(trf);

+ 2 - 2
testapp/Main.cpp

@@ -493,7 +493,7 @@ Error initSubsystems(int argc, char* argv[])
 	config.set("is.sm.enabled", true);
 	config.set("is.sm.enabled", true);
 	config.set("is.sm.poissonEnabled", false);
 	config.set("is.sm.poissonEnabled", false);
 	config.set("is.sm.resolution", 1024);
 	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.enabled", true);
 	config.set("pps.hdr.renderingQuality", 0.5);
 	config.set("pps.hdr.renderingQuality", 0.5);
 	config.set("pps.hdr.blurringDist", 1.0);
 	config.set("pps.hdr.blurringDist", 1.0);
@@ -522,7 +522,7 @@ Error initSubsystems(int argc, char* argv[])
 
 
 	//config.set("maxTextureSize", 256);
 	//config.set("maxTextureSize", 256);
 
 
-	Bool fullscreen = false;
+	Bool fullscreen = true;
 
 
 	config.set("fullscreenDesktopResolution", fullscreen);
 	config.set("fullscreenDesktopResolution", fullscreen);
 	if(!fullscreen)
 	if(!fullscreen)