Jump to content

Instances & Swept Culling


SpiderPig
 Share

Recommended Posts

So the max instance count is about 65k but does that include things like sub-passes and meshes?

I mean can we have 65,000 instanced cubes or with 2 sub-passes are we limited to only 32,000 cubes?

Also, with your Instanced geometry benchmark code, I've added in swept culling and a few more cubes.  Even with swept culling enabled it doesn't make much difference.  In my game I only have a few thousand instances and it doesn't hep much there either.

Can I turn off culling for particular objects or all of them?  I'd like to test the performance of both options.

#include "UltraEngine.h"
#include "ComponentSystem.h"
using namespace UltraEngine;

int main(int argc, const char* argv[])
{
	const int count = 32;
	RegisterComponents();

	//Get the displays
	auto displays = GetDisplays();

	//Create a window
	auto window = CreateWindow("Instanced Geometry", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);

	//Create framebuffer
	auto framebuffer = CreateFramebuffer(window);

	//Create world
	auto world = CreateWorld();

	//Create camera
	auto camera = CreateCamera(world);
	camera->SetPosition(0, 0, -count * 2);
	camera->SetClearColor(0.125);
	camera->SetDepthPrepass(false);
	camera->AddComponent<CameraControls>();
	camera->SetSweptCulling(true);
	camera->SetOcclusionCullingMode(false);
	

	//Create box 
	auto box = CreateBox(world);
	box->SetCollider(NULL);

	auto mtl = CreateMaterial();
	mtl->SetColor(0.5f);
	mtl->SetShaderFamily(LoadShaderFamily("Shaders/Unlit.fam"));
	box->SetMaterial(mtl);

	//Create instances
	std::vector<shared_ptr<Entity> > boxes;
	boxes.reserve(count * count * count);
	int x, y, z;
	for (x = 0; x < 32; ++x)
	{
		for (y = 0; y < 32; ++y)
		{
			for (z = 0; z < 64; ++z)
			{
				auto inst = box->Instantiate(world);
				inst->SetPosition(3.0f + float(x - 1 - (count / 2)) * 2, 3.0f + float(y - 1 - (count / 2)) * 2, 3.0f + float(z - 1 - (count / 2)) * 2);
				boxes.push_back(inst);
			}
		}
	}

	box = NULL;

	//Fps display
	auto font = LoadFont("Fonts/arial.ttf");
	auto sprite = CreateSprite(world, font, "", 14);
	world->RecordStats(true);
	sprite->SetRenderLayers(2);
	sprite->SetPosition(2, framebuffer->size.y - font->GetHeight(14) - 2, 0);
	auto orthocam = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
	orthocam->SetRenderLayers(2);
	orthocam->SetClearMode(ClearMode(0));
	orthocam->SetPosition(float(framebuffer->size.x) * 0.5f, float(framebuffer->size.y) * 0.5f, 0);

	//Main loop
	while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
	{
		//Check for failed renderer initialization
		while (PeekEvent())
		{
			const auto e = WaitEvent();
			if (e.id == EVENT_STARTRENDERER and e.data == 0)
			{
				Notify(L"Renderer failed to intialize.\n\n" + e.text, "Ultra Engine", true);
				return 0;
			}
		}

		sprite->SetText("FPS: " + String(world->renderstats.framerate));

		world->Update();
		world->Render(framebuffer, false);
	}
	return 0;
}

 

Link to comment
Share on other sites

When I say a limit on instances, I mean on the number that exist in the world. The limit is due to the fact that entity indexes into a storage buffer use an unsigned short integer (2 bytes). This does not have any relation to the number of instances drawn, which may be more for things like shadows and the early z pass.

  • Thanks 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...