Quellcode durchsuchen

Making HDR more beautifull. Need to test speed

Panagiotis Christopoulos Charitos vor 13 Jahren
Ursprung
Commit
cd967d6e04

+ 3 - 0
include/anki/renderer/Renderer.h

@@ -244,6 +244,9 @@ public:
 
 	void drawQuadInstanced(U32 primitiveCount);
 
+	/// Used by blurring where we draw the same quad many times
+	void drawQuadMultiple(U times);
+
 	/// Create FAI texture
 	static void createFai(U32 width, U32 height, int internalFormat,
 		int format, int type, Texture& fai);

+ 7 - 0
shaders/Pps.glsl

@@ -65,5 +65,12 @@ void main(void)
 
 	//fColor = BlendHardLight(vec3(0.6, 0.62, 0.4), fColor);
 	fColor = gammaCorrectionRgb(vec3(0.9, 0.92, 0.75), fColor);
+
+#if 0
+	if(fColor.r != 0.00000001)
+	{
+		fColor = hdr;
+	}
+#endif
 }
 

+ 6 - 2
shaders/PpsHdr.glsl

@@ -4,7 +4,9 @@
 
 #pragma anki start fragmentShader
 
-uniform sampler2D fai; ///< Its the IS FAI
+precision mediump float;
+
+uniform sampler2D mediump fai; ///< Its the IS FAI
 
 layout(std140, binding = 0) uniform commonBlock
 {
@@ -17,11 +19,13 @@ in vec2 vTexCoords;
 
 layout(location = 0) out vec3 fColor;
 
+const float brightMax = 4.0;
+
 void main()
 {
 	vec3 color = texture2D(fai, vTexCoords).rgb;
+
 	float luminance = dot(vec3(0.30, 0.59, 0.11), color);
-	const float brightMax = 4.0;
 	float yd = exposure * (exposure / brightMax + 1.0) /
 		(exposure + 1.0) * luminance;
 	color *= yd;

+ 1 - 11
src/renderer/Ez.cpp

@@ -2,6 +2,7 @@
 #include "anki/renderer/Renderer.h"
 #include "anki/core/App.h"
 #include "anki/scene/Scene.h"
+#include "anki/scene/Camera.h"
 
 namespace anki {
 
@@ -16,17 +17,6 @@ void Ez::init(const RendererInitializer& initializer)
 	}
 
 	maxObjectsToDraw = initializer.ms.ez.maxObjectsToDraw;
-
-	// init FBO
-	try
-	{
-		fbo.create();
-		fbo.setOtherAttachment(GL_DEPTH_ATTACHMENT, r->getMs().getDepthFai());
-	}
-	catch(std::exception& e)
-	{
-		throw ANKI_EXCEPTION("Cannot create EarlyZ FBO");
-	}
 }
 
 //==============================================================================

+ 18 - 3
src/renderer/Hdr.cpp

@@ -11,6 +11,7 @@ Hdr::~Hdr()
 void Hdr::initFbo(Fbo& fbo, Texture& fai)
 {
 	Renderer::createFai(width, height, GL_RGB8, GL_RGB, GL_FLOAT, fai);
+	fai.setFiltering(Texture::TFT_LINEAR);
 
 	// create FBO
 	fbo.create();
@@ -91,7 +92,7 @@ void Hdr::init(const RendererInitializer& initializer)
 void Hdr::run()
 {
 	ANKI_ASSERT(enabled);
-	/*if(r.getFramesNum() % 2 == 0)
+	/*if(r->getFramesCount() % 2 == 0)
 	{
 		return;
 	}*/
@@ -102,7 +103,7 @@ void Hdr::run()
 	GlStateSingleton::get().disable(GL_DEPTH_TEST);
 
 	// For the passes it should be NEAREST
-	vblurFai.setFiltering(Texture::TFT_NEAREST);
+	//vblurFai.setFiltering(Texture::TFT_NEAREST);
 
 	// pass 0
 	vblurFbo.bind();
@@ -118,6 +119,7 @@ void Hdr::run()
 	toneSProg->findUniformVariable("fai").set(r->getIs().getFai());
 	r->drawQuad();
 
+#if 1
 	// blurring passes
 	for(U32 i = 0; i < blurringIterationsCount; i++)
 	{
@@ -139,9 +141,22 @@ void Hdr::run()
 		}
 		r->drawQuad();
 	}
+#else
+	hblurFbo.bind();
+	hblurSProg->bind();
+	hblurSProg->findUniformVariable("img").set(vblurFai);
+
+	r->drawQuadMultiple(blurringIterationsCount);
+
+	vblurFbo.bind();
+	vblurSProg->bind();
+	vblurSProg->findUniformVariable("img").set(hblurFai);
+
+	r->drawQuadMultiple(blurringIterationsCount);
+#endif
 
 	// For the next stage it should be LINEAR though
-	vblurFai.setFiltering(Texture::TFT_LINEAR);
+	//vblurFai.setFiltering(Texture::TFT_LINEAR);
 }
 
 } // end namespace anki

+ 9 - 8
src/renderer/MainRenderer.cpp

@@ -158,22 +158,23 @@ void MainRenderer::takeScreenshotTga(const char* filename)
 	fs.write((char*)&header[0], sizeof(header));
 
 	// get the buffer
-	U8* buffer = new U8[getWidth() * getHeight() * 3];
+	Vector<U8> buffer;
+	buffer.resize(getWidth() * getHeight() * 3);
 
-	for(U i = 0; i < getWidth() * getHeight(); i += 3)
+	glReadPixels(0, 0, getWidth(), getHeight(), GL_RGB, GL_UNSIGNED_BYTE,
+		&buffer[0]);
+
+	for(U i = 0; i < getWidth() * getHeight() * 3; i += 3)
 	{
 		U8 temp = buffer[i];
 		buffer[i] = buffer[i + 2];
 		buffer[i + 2] = temp;
 	}
 
-	glReadPixels(0, 0, getWidth(), getHeight(), GL_RGB, GL_UNSIGNED_BYTE,
-		buffer);
-	fs.write((char*)buffer, getWidth() * getHeight() * 3);
+	fs.write((char*)&buffer[0], getWidth() * getHeight() * 3);
 
 	// end
 	fs.close();
-	delete[] buffer;
 }
 
 //==============================================================================
@@ -233,11 +234,11 @@ void MainRenderer::takeScreenshot(const char* filename)
 	std::string ext = getFileExtension(filename);
 
 	// exec from this extension
-	if(ext == ".tga")
+	if(ext == "tga")
 	{
 		takeScreenshotTga(filename);
 	}
-	else if(ext == ".jpg" || ext == ".jpeg")
+	else if(ext == "jpg" || ext == "jpeg")
 	{
 		takeScreenshotJpeg(filename);
 	}

+ 25 - 0
src/renderer/Renderer.cpp

@@ -108,6 +108,31 @@ void Renderer::drawQuadInstanced(U32 primitiveCount)
 		primitiveCount);
 }
 
+//==============================================================================
+void Renderer::drawQuadMultiple(U times)
+{
+	quadVao.bind();
+#if ANKI_GL == ANKI_GL_DESKTOP
+	const U max_times = 8;
+	Array<GLsizei, max_times> count;
+	Array<const GLvoid*, max_times> indices;
+
+	for(U i = 0; i < times; i++)
+	{
+		count[i] = 2 * 3;
+		indices[i] = nullptr;
+	}
+
+	glMultiDrawElements(
+		GL_TRIANGLES, &count[0], GL_UNSIGNED_SHORT, &indices[0], times);
+#else
+	for(U i = 0; i < times; i++)
+	{
+		glDrawElements(GL_TRIANGLES, 2 * 3, GL_UNSIGNED_SHORT, 0);
+	}
+#endif
+}
+
 //==============================================================================
 Vec3 Renderer::unproject(const Vec3& windowCoords, const Mat4& modelViewMat,
 	const Mat4& projectionMat, const int view[4])

+ 5 - 1
testapp/Main.cpp

@@ -331,6 +331,10 @@ void mainLoop()
 		Timestamp::increaseTimestamp();
 	}
 
+#if 1
+	MainRendererSingleton::get().takeScreenshot("screenshot.tga");
+#endif
+
 	ANKI_LOGI("Exiting main loop (" << mainLoopTimer.getElapsedTime()
 		<< " sec)");
 }
@@ -379,7 +383,7 @@ void initSubsystems(int argc, char* argv[])
 	initializer.is.sm.resolution = 512;
 	initializer.pps.hdr.enabled = true;
 	initializer.pps.hdr.renderingQuality = 0.25;
-	initializer.pps.hdr.blurringDist = 0.0;
+	initializer.pps.hdr.blurringDist = 2.0;
 	initializer.pps.hdr.blurringIterationsCount = 2;
 	initializer.pps.hdr.exposure = 8.0;
 	initializer.pps.ssao.blurringIterationsNum = 4;