Browse Source

Optimizing irradiance generation

Panagiotis Christopoulos Charitos 10 years ago
parent
commit
e766fc5a5c

+ 2 - 0
include/anki/renderer/Ir.h

@@ -89,6 +89,8 @@ private:
 		Timestamp m_timestamp = 0; ///< When last rendered.
 	};
 
+	static const U IRRADIANCE_SIZE = 32;
+
 	Renderer m_nestedR;
 	TexturePtr m_envCubemapArr;
 	U16 m_cubemapArrMipCount = 0;

+ 1 - 1
shaders/ImageReflections.glsl

@@ -10,7 +10,7 @@
 
 #include "shaders/Clusterer.glsl"
 
-#define ACCURATE_RAYS 0
+#define ACCURATE_RAYS 1
 
 // Representation of a reflection probe
 struct ReflectionProbe

+ 4 - 0
shaders/NearDepthUpscale.frag.glsl

@@ -68,10 +68,14 @@ void main()
 	// Check for depth discontinuites. Use textureLod because it's undefined
 	// if you are sampling mipmaped in a conditional branch. See
 	// http://teknicool.tumblr.com/post/77263472964/glsl-dynamic-branching-and-texture-samplers
+#if 0
 	float a = u_linearizePad2.x;
 	float b = u_linearizePad2.y;
 	float maxDiffLinear = abs(linearizeDepthOptimal(depth + maxDiff, a, b)
 		- linearizeDepthOptimal(depth, a, b));
+#else
+	float maxDiffLinear = abs(maxDiff);
+#endif
 	if(maxDiffLinear < DEPTH_THRESHOLD)
 	{
 		// No major discontinuites, sample with bilinear

+ 13 - 10
src/renderer/Ir.cpp

@@ -222,6 +222,8 @@ Error Ir::init(const ConfigSet& config)
 
 	m_envCubemapArr = getGrManager().newInstance<Texture>(texinit);
 
+	texinit.m_width = IRRADIANCE_SIZE;
+	texinit.m_height = IRRADIANCE_SIZE;	
 	m_irradianceCubemapArr = getGrManager().newInstance<Texture>(texinit);
 
 	m_cubemapArrMipCount = computeMaxMipmapCount(m_fbSize, m_fbSize);
@@ -263,7 +265,7 @@ Error Ir::initIrradiance()
 {
 	// Create the shader
 	StringAuto pps(getFrameAllocator());
-	pps.sprintf("#define CUBEMAP_SIZE %u\n", m_fbSize);
+	pps.sprintf("#define CUBEMAP_SIZE %u\n", IRRADIANCE_SIZE);
 
 	ANKI_CHECK(getResourceManager().loadResourceToCache(m_computeIrradianceFrag,
 		"shaders/Irradiance.frag.glsl",
@@ -272,11 +274,8 @@ Error Ir::initIrradiance()
 
 	// Create the ppline
 	ColorStateInfo colorInf;
-	colorInf.m_attachmentCount = 3;
-	PixelFormat pfs(ComponentFormat::R8G8B8, TransformFormat::UNORM);
-	colorInf.m_attachments[0].m_format = pfs;
-	colorInf.m_attachments[2].m_format = pfs;
-	colorInf.m_attachments[3].m_format = pfs;
+	colorInf.m_attachmentCount = 1;
+	colorInf.m_attachments[0].m_format = Is::RT_PIXEL_FORMAT;
 
 	m_r->createDrawQuadPipeline(m_computeIrradianceFrag->getGrShader(),
 		colorInf,
@@ -605,8 +604,12 @@ Error Ir::renderReflection(SceneNode& node,
 
 		// Gen mips of env tex
 		cmdb->generateMipmaps(m_envCubemapArr, 6 * cubemapIdx + i);
+	}
 
-		// Compute irradiance
+	// Compute irradiance
+	cmdb->setViewport(0, 0, IRRADIANCE_SIZE, IRRADIANCE_SIZE);
+	for(U i = 0; i < 6; ++i)
+	{
 		DynamicBufferInfo dinf;
 		UVec4* faceIdxArrayIdx =
 			static_cast<UVec4*>(getGrManager().allocateFrameHostVisibleMemory(
@@ -614,6 +617,8 @@ Error Ir::renderReflection(SceneNode& node,
 		faceIdxArrayIdx->x() = i;
 		faceIdxArrayIdx->y() = cubemapIdx;
 
+		cmdb->bindResourceGroup(m_computeIrradianceResources, 0, &dinf);
+
 		FramebufferInitializer fbinit;
 		fbinit.m_colorAttachmentsCount = 1;
 		fbinit.m_colorAttachments[0].m_texture = m_irradianceCubemapArr;
@@ -623,10 +628,8 @@ Error Ir::renderReflection(SceneNode& node,
 		fbinit.m_colorAttachments[0].m_loadOperation =
 			AttachmentLoadOperation::DONT_CARE;
 		FramebufferPtr fb = getGrManager().newInstance<Framebuffer>(fbinit);
-
 		cmdb->bindFramebuffer(fb);
-		cmdb->setViewport(0, 0, m_fbSize, m_fbSize);
-		cmdb->bindResourceGroup(m_computeIrradianceResources, 0, &dinf);
+
 		cmdb->bindPipeline(m_computeIrradiancePpline);
 		m_r->drawQuad(cmdb);
 		cmdb->generateMipmaps(m_irradianceCubemapArr, 6 * cubemapIdx + i);

+ 4 - 0
src/scene/Sector.cpp

@@ -614,7 +614,11 @@ void SectorGroup::findVisibleSectorsInternal(const FrustumComponent& frc,
 		p.getBoundingShape().computeAabb(box);
 
 		if(frc.insideFrustum(p.getBoundingShape())
+#if 0
 			&& r.doGpuVisibilityTest(p.getBoundingShape(), box))
+#else
+			)
+#endif
 		{
 			it = p.m_sectors.getBegin();
 			end = p.m_sectors.getEnd();