Przeglądaj źródła

Adding framebuffer blit support

Panagiotis Christopoulos Charitos 11 lat temu
rodzic
commit
79a3e18d9f

+ 4 - 0
include/anki/gl/GlFramebuffer.h

@@ -63,6 +63,10 @@ public:
 	/// @param invalidate If true invalidate the FB after binding it
 	void bind(Bool invalidate);
 
+	/// Blit another framebuffer to this
+	void blit(const GlFramebuffer& fb, const Array<F32, 4>& sourceRect,
+		const Array<F32, 4>& destRect, Bool linear);
+
 private:
 	Array<GlTextureHandle, MAX_COLOR_ATTACHMENTS + 1> m_attachments;
 	Bool8 m_bindDefault = false;

+ 11 - 0
include/anki/gl/GlFramebufferHandle.h

@@ -35,6 +35,17 @@ public:
 	/// @param jobs The job chain
 	/// @param invalidate If true invalidate the FB after binding it
 	void bind(GlJobChainHandle& jobs, Bool invalidate);
+
+	/// Blit another framebuffer to this
+	/// @param[in, out] jobs The job chain
+	/// @param[in] b The sorce framebuffer
+	/// @param[in] sourceRect The source rectangle
+	/// @param[in] destRect The destination rectangle
+	/// @param linear Perform linean filtering
+	void blit(GlJobChainHandle& jobs,
+		const GlFramebufferHandle& b, 
+		const Array<F32, 4>& sourceRect,
+		const Array<F32, 4>& destRect, Bool linear);
 };
 
 } // end namespace anki

+ 1 - 1
include/anki/renderer/Ms.h

@@ -48,7 +48,7 @@ private:
 		GlTextureHandle m_rt1;
 
 		/// Depth stencil
-		GlTextureHandle m_depthRt; 
+		GlTextureHandle m_depthRt;
 	};
 
 	Ez m_ez; /// EarlyZ pass

+ 3 - 3
shaders/PpsSslr.frag.glsl

@@ -122,16 +122,16 @@ void main()
 
 		if(diffDepth > 0.0)
 		{
-			if(diffDepth > 0.3)
+			if(diffDepth > 0.7)
 			{
-				outColor = vec3(0.01);
 				return;
 			}
 
 			float factor = 1.0 - length(ndc.xy);
 			factor *= 1.0 - length(pp0.xy);
+			factor *= specColor;
 
-			outColor = textureRt(uIsRt, texCoord).rgb * (factor * 1.1 /* specColor*/);
+			outColor = textureRt(uIsRt, texCoord).rgb * factor;
 
 			//outColor = vec3(1.0 - abs(pp0.xy), 0.0);
 			return;

+ 14 - 0
src/gl/GlFramebuffer.cpp

@@ -192,5 +192,19 @@ void GlFramebuffer::bind(Bool invalidate)
 	}
 }
 
+//==============================================================================
+void GlFramebuffer::blit(const GlFramebuffer& b, 
+	const Array<F32, 4>& sourceRect,
+	const Array<F32, 4>& destRect, Bool linear)
+{
+	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_glName);
+	glBindFramebuffer(GL_READ_FRAMEBUFFER, b.m_glName);
+	glBlitFramebuffer(
+		sourceRect[0], sourceRect[1], sourceRect[2], sourceRect[3],
+		destRect[0], destRect[1], destRect[2], destRect[3], 
+		GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
+		linear ? GL_LINEAR : GL_NEAREST);
+}
+
 } // end namespace anki
 

+ 33 - 0
src/gl/GlFramebufferHandle.cpp

@@ -95,5 +95,38 @@ void GlFramebufferHandle::bind(GlJobChainHandle& jobs, Bool invalidate)
 	jobs._pushBackNewJob<Job>(*this, invalidate);
 }
 
+//==============================================================================
+void GlFramebufferHandle::blit(GlJobChainHandle& jobs,
+	const GlFramebufferHandle& b, 
+	const Array<F32, 4>& sourceRect,
+	const Array<F32, 4>& destRect, Bool linear)
+{
+	class Job: public GlJob
+	{
+	public:
+		GlFramebufferHandle m_fbDest;
+		GlFramebufferHandle m_fbSrc;
+		Array<F32, 4> m_sourceRect;
+		Array<F32, 4> m_destRect;
+		Bool m_linear;
+
+		Job(GlFramebufferHandle& fbDest, const GlFramebufferHandle& fbSrc,
+			const Array<F32, 4>& sourceRect,
+			const Array<F32, 4>& destRect,
+			Bool linear)
+			:	m_fbDest(fbDest), m_fbSrc(fbSrc), m_sourceRect(sourceRect),
+				m_destRect(destRect), m_linear(linear)
+		{}
+
+		void operator()(GlJobChain*)
+		{
+			m_fbSrc._get().blit(m_fbDest._get(), m_sourceRect, m_destRect, 
+				m_linear);
+		}
+	};
+
+	jobs._pushBackNewJob<Job>(*this, b, sourceRect, destRect, linear);
+}
+
 } // end namespace anki
 

+ 2 - 2
src/renderer/MainRenderer.cpp

@@ -76,8 +76,8 @@ void MainRenderer::render(SceneGraph& scene)
 			rt = &getIs()._getRt();
 		}
 
-		rt = &getPps().getSslr()._getRt();
-		rt = &getMs()._getRt0();
+		//rt = &getPps().getSslr()._getRt();
+		//rt = &getMs()._getRt0();
 
 		rt->setFilter(lastJobs, GlTextureHandle::Filter::LINEAR);
 		rt->bind(lastJobs, 0);

+ 1 - 1
src/renderer/Sslr.cpp

@@ -45,7 +45,7 @@ void Sslr::init(const RendererInitializer& initializer)
 	// Init FBOs and RTs and blurring
 	if(m_blurringIterationsCount > 0)
 	{
-		initBlurring(*m_r, m_width, m_height, 7, 0.5);
+		initBlurring(*m_r, m_width, m_height, 9, 0.0);
 	}
 	else
 	{