Bläddra i källkod

Optimizations. Need to pass 300FPS

Panagiotis Christopoulos Charitos 13 år sedan
förälder
incheckning
2d270ac806

+ 0 - 6
include/anki/scene/Renderable.h

@@ -185,11 +185,6 @@ public:
 	{
 		return ubo;
 	}
-
-	Ubo& getInstancingUbo()
-	{
-		return instancingUbo;
-	}
 	/// @}
 
 protected:
@@ -199,7 +194,6 @@ protected:
 private:
 	RenderableVariables vars;
 	Ubo ubo;
-	Ubo instancingUbo;
 };
 /// @}
 

+ 6 - 15
shaders/IsLpGeneric.glsl

@@ -22,24 +22,15 @@
 layout(std140, row_major, binding = 0) uniform commonBlock
 {
 	/// Packs:
-	/// - x: zNear. For the calculation of frag pos in view space
-	/// - zw: Planes. For the calculation of frag pos in view space
-	uniform vec4 nearPlanes;
-
-	/// For the calculation of frag pos in view space. The xy is the 
-	/// limitsOfNearPlane and the zw is an optimization see PpsSsao.glsl and 
-	/// r403 for the clean one
-	uniform vec4 limitsOfNearPlane_;
+	/// - xy: Planes. For the calculation of frag pos in view space
+	uniform vec4 planes_;
 
 	uniform vec4 sceneAmbientColor;
 
 	uniform vec4 groundLightDir;
 };
 
-#define planes nearPlanes.zw
-#define zNear nearPlanes.x
-#define limitsOfNearPlane limitsOfNearPlane_.xy
-#define limitsOfNearPlane2 limitsOfNearPlane_.zw
+#define planes planes_.xy
 
 struct Light
 {
@@ -88,6 +79,7 @@ uniform sampler2DArrayShadow shadowMapArr;
 /// @{
 in vec2 vTexCoords;
 flat in int vInstanceId;
+in vec2 vLimitsOfNoearPlaneOpt;
 /// @}
 
 /// @name Output
@@ -106,8 +98,7 @@ vec3 getFragPosVSpace()
 	fragPosVspace.z = -planes.y / (planes.x + depth);
 
 	/// XXX OPT: Do that a varying
-	fragPosVspace.xy = (vTexCoords * limitsOfNearPlane2) - limitsOfNearPlane;
-	fragPosVspace.xy *= -fragPosVspace.z;
+	fragPosVspace.xy = vLimitsOfNoearPlaneOpt * (-fragPosVspace.z);
 
 	return fragPosVspace;
 }
@@ -302,7 +293,7 @@ void main()
 #endif
 
 #if 0
-	fColor = fColor * 0.5 + normal * 0.5;
+	fColor = fColor * 0.005 + vec3(vLimitsOfNoearPlaneOpt, 1.0);
 #endif
 
 #if 0

+ 6 - 0
shaders/IsLpVertex.glsl

@@ -4,8 +4,11 @@
 
 layout(location = 0) in vec2 position;
 
+uniform vec4 limitsOfNearPlane;
+
 out vec2 vTexCoords;
 flat out int vInstanceId;
+out vec2 vLimitsOfNoearPlaneOpt;
 
 void main()
 {
@@ -20,4 +23,7 @@ void main()
 	vTexCoords = (position + ij) * SIZES;
 	vec2 vertPosNdc = vTexCoords * 2.0 - 1.0;
 	gl_Position = vec4(vertPosNdc, 0.0, 1.0);
+
+	vLimitsOfNoearPlaneOpt = 
+		(vTexCoords * limitsOfNearPlane.zw) - limitsOfNearPlane.xy;
 }

+ 15 - 25
src/collision/Sphere.cpp

@@ -7,37 +7,27 @@ namespace anki {
 //==============================================================================
 F32 Sphere::testPlane(const Plane& p) const
 {
-	const Sphere& s = *this;
-	F32 dist = p.test(s.getCenter());
+	F32 dist = p.test(center);
 
-#if 0
-	if(dist > s.getRadius())
+	F32 out = dist - radius;
+	if(out > 0)
 	{
-		return dist - s.getRadius();
-	}
-	else if(-dist > s.getRadius())
-	{
-		return dist + s.getRadius();
+		// Do nothing
 	}
 	else
 	{
-		return 0.0;
-	}
-#else
-	F32 opt = dist - s.getRadius();
-	if(opt > 0)
-	{
-		return opt;
-	}
-	else if((opt = dist + s.getRadius()) < 0)
-	{
-		return opt;
-	}
-	else
-	{
-		return 0.0;
+		out = dist + radius;
+		if(out < 0)
+		{
+			// Do nothing
+		}
+		else
+		{
+			out = 0.0;
+		}
 	}
-#endif
+
+	return out;
 }
 
 //==============================================================================

+ 7 - 7
src/renderer/Drawer.cpp

@@ -220,7 +220,7 @@ void RenderableDrawer::render(Frustumable& fr, RenderingStage stage,
 	/* Instancing */
 	U32 instancesCount = renderable->getRenderableInstancesCount();
 
-	if(instancesCount < 1)
+	if(ANKI_UNLIKELY(instancesCount < 1))
 	{
 		return;
 	}
@@ -230,22 +230,22 @@ void RenderableDrawer::render(Frustumable& fr, RenderingStage stage,
 
 	Bool blending = mtl.isBlendingEnabled();
 
-	if(blending)
+	if(!blending)
 	{
-		if(stage != RS_BLEND)
+		if(stage == RS_BLEND)
 		{
 			return;
 		}
-
-		GlStateSingleton::get().setBlendFunctions(
-			mtl.getBlendingSfactor(), mtl.getBlendingDfactor());
 	}
 	else
 	{
-		if(stage == RS_BLEND)
+		if(stage != RS_BLEND)
 		{
 			return;
 		}
+
+		GlStateSingleton::get().setBlendFunctions(
+			mtl.getBlendingSfactor(), mtl.getBlendingDfactor());
 	}
 
 	GlStateSingleton::get().enable(GL_BLEND, blending);

+ 5 - 7
src/renderer/Is.cpp

@@ -66,8 +66,7 @@ struct ShaderTiles
 
 struct ShaderCommonUniforms
 {
-	Vec4 nearPlanes;
-	Vec4 limitsOfNearPlane;
+	Vec4 planes;
 	Vec4 sceneAmbientColor;
 	Vec4 groundLightDir;
 };
@@ -586,6 +585,9 @@ void Is::lightPass()
 	// shader prog
 	lightPassProg->bind();
 
+	lightPassProg->findUniformVariable("limitsOfNearPlane").set(
+		Vec4(r->getLimitsOfNearPlane(), r->getLimitsOfNearPlane2()));
+
 	commonUbo.setBinding(COMMON_UNIFORMS_BLOCK_BINDING);
 	pointLightsUbo.setBinding(POINT_LIGHTS_BLOCK_BINDING);
 	spotLightsUbo.setBinding(SPOT_LIGHTS_BLOCK_BINDING);
@@ -623,12 +625,8 @@ void Is::run()
 		|| (groundLightEnabled
 			&& !groundVectorsEqual(groundLightDir, prevGroundLightDir)))
 	{
-		const Camera& cam = scene.getActiveCamera();
 		ShaderCommonUniforms blk;
-		blk.nearPlanes = Vec4(cam.getNear(), 0.0, r->getPlanes().x(),
-			r->getPlanes().y());
-		blk.limitsOfNearPlane = Vec4(r->getLimitsOfNearPlane(),
-			r->getLimitsOfNearPlane2());
+		blk.planes = Vec4(r->getPlanes().x(), r->getPlanes().y(), 0.0, 0.0);
 		blk.sceneAmbientColor = Vec4(scene.getAmbientColor(), 0.0);
 
 		if(groundLightEnabled)

+ 1 - 1
src/renderer/Ssao.cpp

@@ -16,7 +16,7 @@ struct ShaderCommonUniforms
 //==============================================================================
 void Ssao::createFbo(Fbo& fbo, Texture& fai, F32 width, F32 height)
 {
-	Renderer::createFai(width, height, GL_RED, GL_RED, GL_FLOAT, fai);
+	Renderer::createFai(width, height, GL_RED, GL_RED, GL_UNSIGNED_BYTE, fai);
 	fai.setFiltering(Texture::TFT_LINEAR);
 
 	fbo.create();

+ 2 - 2
src/scene/Scene.cpp

@@ -112,8 +112,8 @@ void Scene::update(F32 prevUpdateTime, F32 crntTime, Renderer& r)
 
 	doVisibilityTests(*mainCam, r);
 
-	sectorGroup.doVisibilityTests(*mainCam,
-		VisibilityTest(VT_RENDERABLES | VT_LIGHTS), &r);
+	/*sectorGroup.doVisibilityTests(*mainCam,
+		VisibilityTest(VT_RENDERABLES | VT_LIGHTS), &r);*/
 
 #if 0
 	for(SceneNode* n : nodes)