Browse Source

Bug fixes

Panagiotis Christopoulos Charitos 10 years ago
parent
commit
ed1c96873b

+ 14 - 0
include/anki/gr/Common.h

@@ -70,6 +70,20 @@ const U MAX_UNIFORM_BUFFER_BINDINGS = 1;
 const U MAX_STORAGE_BUFFER_BINDINGS = 8;
 const U MAX_FRAMES_IN_FLIGHT = 3;
 const U MAX_RESOURCE_GROUPS = 2;
+
+/// Compute max number of mipmaps for a 2D surface.
+inline U32 computeMaxMipmapCount(U32 w, U32 h)
+{
+	U32 s = (w < h) ? w : h;
+	U count = 0;
+	while(s)
+	{
+		s /= 2;
+		++count;
+	}
+
+	return count;
+}
 /// @}
 
 } // end namespace anki

+ 1 - 0
include/anki/gr/gl/RenderingThread.h

@@ -90,6 +90,7 @@ private:
 	/// the server
 	CommandBufferPtr m_syncCommands;
 	Barrier m_syncBarrier{2};
+	SpinLock m_syncLock;
 
 	/// Command buffer with an empty command.
 	CommandBufferPtr m_emptyCmdb;

+ 0 - 3
include/anki/gr/gl/TextureImpl.h

@@ -49,9 +49,6 @@ public:
 		const TextureImpl& dest, U destSlice, U destLevel);
 
 	void bind();
-
-private:
-	static U32 computeMaxMipmapCount(U32 w, U32 h);
 };
 /// @}
 

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

@@ -45,6 +45,11 @@ anki_internal:
 		return m_proxiesToken;
 	}
 
+	U getCubemapArrayMipmapCount() const
+	{
+		return m_cubemapArrMipCount;
+	}
+
 private:
 	class CacheEntry
 	{
@@ -55,6 +60,7 @@ private:
 
 	Renderer m_nestedR;
 	TexturePtr m_cubemapArr;
+	U m_cubemapArrMipCount = 0;
 	U16 m_cubemapArrSize = 0;
 	U16 m_fbSize = 0;
 	DynamicBufferToken m_probesToken;

+ 9 - 7
shaders/ImageReflections.glsl

@@ -84,7 +84,7 @@ bool testReflectionProxy(in uint proxyIdx, in vec3 p, in vec3 r, out vec3 c,
 				dot(c - proxy.quadPoints[i].xyz, proxy.edgeCrossProd[i].xyz);
 		}
 
-		intersect = all(greaterThan(tests, vec4(0.0)));
+		intersect = all(greaterThanEqual(tests, vec4(0.0)));
 	}
 	else
 	{
@@ -120,7 +120,7 @@ bool findCloseProxyIntersection(in vec3 p, in vec3 r, out vec3 c)
 }
 
 //==============================================================================
-void readFromProbes(in vec3 intersection, out vec3 color)
+void readFromProbes(in vec3 intersection, in float lod, out vec3 color)
 {
 	// Iterate probes to find the cubemap
 	uint count = u_proxyCountReflectionProbeCountPad3.y;
@@ -145,17 +145,19 @@ void readFromProbes(in vec3 intersection, out vec3 color)
 			uv = u_invViewRotation * uv;
 
 			// Read!
-			vec3 c = texture(u_reflectionsTex, vec4(uv, cubemapIndex)).rgb;
+			vec3 c =
+				textureLod(u_reflectionsTex, vec4(uv, cubemapIndex), lod).rgb;
 
-			// Combine with previous color
+			// Combine (lerp) with previous color
 			float factor = d / R2;
-			color = color * factor + c * (1.0 - factor);
+			color = mix(c, color, factor);
+			//Equivelent: color = c * (1.0 - factor) + color * factor;
 		}
 	}
 }
 
 //==============================================================================
-vec3 readReflection(in vec3 posVSpace, in vec3 normalVSpace)
+vec3 readReflection(in vec3 posVSpace, in vec3 normalVSpace, in float lod)
 {
 	vec3 color = IMAGE_REFLECTIONS_DEFAULT_COLOR;
 
@@ -167,7 +169,7 @@ vec3 readReflection(in vec3 posVSpace, in vec3 normalVSpace)
 	vec3 intersection;
 	if(findCloseProxyIntersection(posVSpace, r, intersection))
 	{
-		readFromProbes(intersection, color);
+		readFromProbes(intersection, lod, color);
 	}
 
 	return color;

+ 4 - 3
shaders/IsLp.frag.glsl

@@ -102,7 +102,8 @@ void main()
 	float a2 = pow(max(EPSILON, roughness), 2.0);
 
 #if IR == 1
-	vec3 refl = readReflection(fragPos, normal);
+	float reflLod = float(IR_MIPMAP_COUNT) * roughness;
+	vec3 refl = readReflection(fragPos, normal, reflLod);
 #else
 	const vec3 refl = vec3(1.0);
 #endif
@@ -135,7 +136,7 @@ void main()
 		if(light.diffuseColorShadowmapId.w < 128.0)
 		{
 			shadow = computeShadowFactorOmni(frag2Light,
-				shadowmapLayerIdx, -1.0 / light.posRadius.w);
+				shadowmapLayerIdx, 1.0 / sqrt(light.posRadius.w));
 		}
 
 		out_color += (specC + diffC)
@@ -194,7 +195,7 @@ void main()
 		out_color += vec3(1.0, 0.0, 0.0);
 	}
 #if IR == 1
-	out_color = out_color * 0.0000 + readReflection(fragPos, normal) *1.0;
+	out_color = out_color * 0.0000 + readReflection(fragPos, normal, 0.0) *1.0;
 #endif
 #endif
 }

+ 2 - 3
shaders/LightFunctions.glsl

@@ -31,9 +31,8 @@ uint calcClusterSplit(float zVspace)
 float computeAttenuationFactor(float lightRadius, vec3 frag2Light)
 {
 	float fragLightDist = dot(frag2Light, frag2Light);
-	fragLightDist = min(fragLightDist, lightRadius);
-
-	float att = 1.0 - fragLightDist / lightRadius;
+	float att = 1.0 - fragLightDist * lightRadius;
+	att = max(0.0, att);
 	return att * att;
 }
 

+ 4 - 0
src/gr/gl/RenderingThread.cpp

@@ -282,6 +282,10 @@ void RenderingThread::threadLoop()
 void RenderingThread::syncClientServer()
 {
 #if !ANKI_DISABLE_GL_RENDERING_THREAD
+	// Lock because there is only one barrier. If multiple threads call
+	// syncClientServer all of them will hit the same barrier.
+	LockGuard<SpinLock> lock(m_syncLock);
+
 	flushCommandBuffer(m_syncCommands);
 	m_syncBarrier.wait();
 #endif

+ 0 - 14
src/gr/gl/TextureImpl.cpp

@@ -573,20 +573,6 @@ void TextureImpl::generateMipmaps(U surface)
 	}
 }
 
-//==============================================================================
-U32 TextureImpl::computeMaxMipmapCount(U32 w, U32 h)
-{
-	U32 s = min(w, h);
-	U count = 0;
-	while(s)
-	{
-		s /= 2;
-		++count;
-	}
-
-	return count;
-}
-
 //==============================================================================
 void TextureImpl::copy(const TextureImpl& src, U srcSlice, U srcLevel,
 	const TextureImpl& dest, U destSlice, U destLevel)

+ 5 - 3
src/renderer/Drawer.cpp

@@ -338,7 +338,7 @@ Error RenderableDrawer::renderSingle(RenderContext& ctx)
 			ctx.m_nextVisibleNode->m_node->getComponent<RenderComponent>();
 
 		if(nextRenderable.canMergeDrawcalls(renderable)
-			&& ctx.m_cachedTrfCount <= MAX_INSTANCES)
+			&& ctx.m_cachedTrfCount < MAX_INSTANCES - 1)
 		{
 			// Can merge, will cache the drawcall and skip the drawcall
 			Bool hasTransform;
@@ -346,7 +346,8 @@ Error RenderableDrawer::renderSingle(RenderContext& ctx)
 			renderable.getRenderWorldTransform(hasTransform, trf);
 			ANKI_ASSERT(hasTransform);
 
-			ctx.m_cachedTrfs[ctx.m_cachedTrfCount++] = Mat4(trf);
+			ctx.m_cachedTrfs[ctx.m_cachedTrfCount] = Mat4(trf);
+			++ctx.m_cachedTrfCount;
 
 			return ErrorCode::NONE;
 		}
@@ -360,7 +361,8 @@ Error RenderableDrawer::renderSingle(RenderContext& ctx)
 
 		if(hasTransform)
 		{
-			ctx.m_cachedTrfs[ctx.m_cachedTrfCount++] = Mat4(trf);
+			ctx.m_cachedTrfs[ctx.m_cachedTrfCount] = Mat4(trf);
+			++ctx.m_cachedTrfCount;
 		}
 	}
 

+ 3 - 1
src/renderer/Ir.cpp

@@ -100,10 +100,12 @@ Error Ir::init(const ConfigSet& initializer)
 	texinit.m_mipmapsCount = MAX_U8;
 	texinit.m_samples = 1;
 	texinit.m_sampling.m_minMagFilter = SamplingFilter::LINEAR;
-	texinit.m_sampling.m_mipmapFilter = SamplingFilter::NEAREST;
+	texinit.m_sampling.m_mipmapFilter = SamplingFilter::LINEAR;
 
 	m_cubemapArr = getGrManager().newInstance<Texture>(texinit);
 
+	m_cubemapArrMipCount = computeMaxMipmapCount(m_fbSize, m_fbSize);
+
 	getGrManager().finish();
 	return ErrorCode::NONE;
 }

+ 6 - 4
src/renderer/Is.cpp

@@ -248,7 +248,8 @@ Error Is::initInternal(const ConfigSet& config)
 		"#define MAX_LIGHT_INDICES %u\n"
 		"#define GROUND_LIGHT %u\n"
 		"#define POISSON %u\n"
-		"#define IR %u\n",
+		"#define IR %u\n"
+		"#define IR_MIPMAP_COUNT %u\n",
 		m_r->getTileCountXY().x(),
 		m_r->getTileCountXY().y(),
 		m_r->getClusterCount(),
@@ -259,7 +260,8 @@ Error Is::initInternal(const ConfigSet& config)
 		m_maxLightIds,
 		m_groundLightEnabled,
 		m_sm.getPoissonEnabled(),
-		m_r->irEnabled());
+		m_r->irEnabled(),
+		m_r->irEnabled() ? m_r->getIr().getCubemapArrayMipmapCount() : 0);
 
 	// point light
 	ANKI_CHECK(getResourceManager().loadResourceToCache(m_lightVert,
@@ -628,7 +630,7 @@ I Is::writePointLight(const LightComponent& lightc,
 		* lightMove.getWorldTransform().getOrigin().xyz1();
 
 	slight.m_posRadius = Vec4(pos.xyz(),
-		lightc.getRadius() * lightc.getRadius());
+		1.0 / (lightc.getRadius() * lightc.getRadius()));
 	slight.m_diffuseColorShadowmapId = lightc.getDiffuseColor();
 
 	if(!lightc.getShadowEnabled() || !m_sm.getEnabled())
@@ -682,7 +684,7 @@ I Is::writeSpotLight(const LightComponent& lightc,
 		camFrc.getViewMatrix()
 		* lightMove.getWorldTransform().getOrigin().xyz1();
 	light.m_posRadius = Vec4(pos.xyz(),
-		lightc.getDistance() * lightc.getDistance());
+		1.0 / (lightc.getDistance() * lightc.getDistance()));
 
 	// Diff color and shadowmap ID now
 	light.m_diffuseColorShadowmapId =

+ 4 - 2
src/resource/MeshLoader.cpp

@@ -145,8 +145,10 @@ Error MeshLoader::load(const ResourceFilename& filename)
 	}
 
 	// Check indices
-	if(m_header.m_totalIndicesCount < 3
-		|| (m_header.m_totalIndicesCount % 3) != 0
+	U indicesPerFace = ((m_header.m_flags & Flag::QUADS) == Flag::QUADS)
+		? 4 : 3;
+	if(m_header.m_totalIndicesCount < indicesPerFace
+		|| (m_header.m_totalIndicesCount % indicesPerFace) != 0
 		|| m_header.m_totalIndicesCount > MAX_U16
 		|| m_header.m_indicesFormat.m_components != ComponentFormat::R16
 		|| m_header.m_indicesFormat.m_transform != FormatTransform::UINT)

+ 2 - 2
src/resource/Model.cpp

@@ -219,8 +219,8 @@ void ModelPatch::computePipelineInitializer(
 	if(key.m_pass == Pass::SM)
 	{
 		ds.m_format = Sm::DEPTH_RT_PIXEL_FORMAT;
-		ds.m_polygonOffsetFactor = 7.0;
-		ds.m_polygonOffsetUnits = 5.0;
+		ds.m_polygonOffsetFactor = 1.0;
+		ds.m_polygonOffsetUnits = 2.0;
 	}
 	else if(m_mtl->getForwardShading())
 	{

+ 7 - 7
testapp/Main.cpp

@@ -88,10 +88,10 @@ Error init()
 #if !PLAYER
 	cam->getComponent<MoveComponent>().
 		setLocalTransform(Transform(
-		//Vec4(147.392776, -10.132728, 16.607138, 0.0),
-		Vec4(0.0, 10, 0, 0),
-		//Mat3x4(Euler(toRad(0.0), toRad(90.0), toRad(0.0))),
-		Mat3x4::getIdentity(),
+		Vec4(147.392776, -10.132728, 16.607138, 0.0),
+		//Vec4(0.0, 10, 0, 0),
+		Mat3x4(Euler(toRad(0.0), toRad(90.0), toRad(0.0))),
+		//Mat3x4::getIdentity(),
 		1.0));
 #endif
 
@@ -488,7 +488,7 @@ Error initSubsystems(int argc, char* argv[])
 	config.set("is.sm.poissonEnabled", true);
 	config.set("is.sm.resolution", 1024);
 	config.set("lf.maxFlares", 32);
-	config.set("pps.enabled", false);
+	config.set("pps.enabled", true);
 	config.set("pps.bloom.enabled", true);
 	config.set("pps.bloom.renderingQuality", 0.5);
 	config.set("pps.bloom.blurringDist", 1.0);
@@ -509,13 +509,13 @@ Error initSubsystems(int argc, char* argv[])
 	config.set("pps.sharpen", true);
 	config.set("renderingQuality", 1.0);
 	config.set("width", 1280);
-	config.set("height", 1024);
+	config.set("height", 720);
 	config.set("lodDistance", 20.0);
 	config.set("samples", 1);
 	config.set("tessellation", true);
 	//config.set("maxTextureSize", 256);
 	config.set("ir.rendererSize", 64);
-	config.set("fullscreenDesktopResolution", false);
+	config.set("fullscreenDesktopResolution", true);
 	config.set("debugContext", false);
 	if(getenv("ANKI_DATA_PATH"))
 	{