Vladimir Sabantsev Posted June 28 Posted June 28 Hello, I'm trying to distribute my additional cameras rendering across different frames to boost performance. Unfortunately, setting Camera::SetRealtime(false) doesn't have any positive effect on the frame count. In case of the following example I get FPS drop from 600 to 480 when I add 12 inactive cameras for depth cubemap capture: #include "Leadwerks.h" namespace lwe = Leadwerks; int main(int argc, const char* argv[]) { auto displays = lwe::GetDisplays(); auto window = lwe::CreateWindow("Leadwerks", 0, 0, displays[0]->size.x, displays[0]->size.y, displays[0], lwe::WINDOW_FULLSCREEN); auto framebuffer = lwe::CreateFramebuffer(window); auto world = lwe::CreateWorld(); auto light = lwe::CreateDirectionalLight(world); auto sphr_c = lwe::CreateSphere(world); auto cone_0 = lwe::CreateCone(world, 0.5f, 1.f, 64); auto sphr_0 = lwe::CreateSphere(world); auto cube_0 = lwe::CreateBox(world); auto cone_1 = lwe::CreateCone(world, 0.5f, 1.f, 64); auto sphr_1 = lwe::CreateSphere(world); auto cube_1 = lwe::CreateBox(world); auto cube_f = lwe::CreateBox(world); auto clnd_0 = lwe::CreateCylinder(world, 0.5f, 1.f, 64); cube_f->SetScale(100.f, 1.f, 100.f); cube_f->SetPosition(0.f, -3.001f, 0.f); light->SetRotation(60, 0, 0); light->SetColor(0.5f); world->SetAmbientLight(0.05f, 0.1f, 0.1f); sphr_c->SetScale(0.3f); cone_1->SetScale(1.5f); cone_0->SetPosition( 0.f, +1.f, +2.f); sphr_0->SetPosition(+2.f, +1.f, 0.f); cube_0->SetPosition(+1.f, +2.f, +1.f); cone_1->SetPosition( 0.f, -1.f, -2.f); sphr_1->SetPosition(-2.f, -1.f, 0.f); cube_1->SetPosition(-1.f, -2.f, -1.f); clnd_0->SetPosition(-2.1f, -2.f, -1.f); #if 1 std::vector<std::shared_ptr<lwe::Camera>> extra_camera_vec; auto texture_1 = lwe::CreateTexture(lwe::TEXTURE_CUBE, 1024, 1024, lwe::TEXTURE_DEPTH, {}, 6); auto texture_2 = lwe::CreateTexture(lwe::TEXTURE_CUBE, 1024, 1024, lwe::TEXTURE_DEPTH, {}, 6); for (uint32_t i = 0; i < 6; ++i) { auto texbuff = lwe::CreateTextureBuffer(1024, 1024, 0, true); texbuff->SetDepthAttachment(texture_1, i); auto camera = lwe::CreateCamera(world); camera->SetRenderTarget(texbuff); camera->SetRealtime(false); extra_camera_vec.push_back(camera); } for (uint32_t i = 0; i < 6; ++i) { auto texbuff = lwe::CreateTextureBuffer(1024, 1024, 0, true); texbuff->SetDepthAttachment(texture_2, i); auto camera = lwe::CreateCamera(world); camera->SetRenderTarget(texbuff); camera->SetRealtime(false); extra_camera_vec.push_back(camera); } #endif auto main_camera = CreateCamera(world); while (!window->Closed() && !window->KeyDown(lwe::KEY_ESCAPE)) { world->Update(); world->Render(framebuffer, false, 9999); } return 0; } In my project this performance drop is much more noticeable - from ~600 to ~120 no matter if SetRealtime is true or false on pretty much the same scene, but I'm not sure what else contributes to it. I would expect inactive cameras to have virtually no effect on performance. 1 Quote
Solution Josh Posted July 30 Solution Posted July 30 The problem isn't actually the cameras, but the directional light. Each camera gets a unique copy of the directional light, because the shadow renders at different orientations depending on the camera view. You can use renderlayers to make it so the directional light does not appear in the extra cameras, but it would be difficult to keep the camera refresh state synchronized on both the main thread and the rendering thread. auto displays = lwe::GetDisplays(); auto window = lwe::CreateWindow("Leadwerks", 0, 0, 1280, 720, displays[0], lwe::WINDOW_TITLEBAR); auto framebuffer = lwe::CreateFramebuffer(window); auto world = lwe::CreateWorld(); auto light = lwe::CreateDirectionalLight(world); auto sphr_c = lwe::CreateSphere(world); auto cone_0 = lwe::CreateCone(world, 0.5f, 1.f, 64); auto sphr_0 = lwe::CreateSphere(world); auto cube_0 = lwe::CreateBox(world); auto cone_1 = lwe::CreateCone(world, 0.5f, 1.f, 64); auto sphr_1 = lwe::CreateSphere(world); auto cube_1 = lwe::CreateBox(world); auto cube_f = lwe::CreateBox(world); auto clnd_0 = lwe::CreateCylinder(world, 0.5f, 1.f, 64); cube_f->SetScale(100.f, 1.f, 100.f); cube_f->SetPosition(0.f, -3.001f, 0.f); light->SetRotation(60, 0, 0); light->SetColor(0.5f); light->SetRenderLayers(2); world->SetAmbientLight(0.05f, 0.1f, 0.1f); sphr_c->SetScale(0.3f); cone_1->SetScale(1.5f); cone_0->SetPosition(0.f, +1.f, +2.f); sphr_0->SetPosition(+2.f, +1.f, 0.f); cube_0->SetPosition(+1.f, +2.f, +1.f); cone_1->SetPosition(0.f, -1.f, -2.f); sphr_1->SetPosition(-2.f, -1.f, 0.f); cube_1->SetPosition(-1.f, -2.f, -1.f); clnd_0->SetPosition(-2.1f, -2.f, -1.f); #if 1 std::vector<std::shared_ptr<lwe::Camera>> extra_camera_vec; auto texture_1 = lwe::CreateTexture(lwe::TEXTURE_CUBE, 1024, 1024, lwe::TEXTURE_DEPTH, {}, 6); auto texture_2 = lwe::CreateTexture(lwe::TEXTURE_CUBE, 1024, 1024, lwe::TEXTURE_DEPTH, {}, 6); for (uint32_t i = 0; i < 6; ++i) { auto texbuff = lwe::CreateTextureBuffer(1024, 1024, 0, true); texbuff->SetDepthAttachment(texture_1, i); auto camera = lwe::CreateCamera(world); camera->SetRenderTarget(texbuff); camera->SetRealtime(false); camera->SetRenderLayers(1); extra_camera_vec.push_back(camera); } for (uint32_t i = 0; i < 6; ++i) { auto texbuff = lwe::CreateTextureBuffer(1024, 1024, 0, true); texbuff->SetDepthAttachment(texture_2, i); auto camera = lwe::CreateCamera(world); camera->SetRenderLayers(1); camera->SetRenderTarget(texbuff); camera->SetRealtime(false); extra_camera_vec.push_back(camera); } #endif auto main_camera = CreateCamera(world); main_camera->SetRenderLayers(3); while (!window->Closed() && !window->KeyDown(lwe::KEY_ESCAPE)) { world->Update(); world->Render(framebuffer, false, 9999); } return 0; 1 Quote Let's build cool stuff and have fun.
Recommended Posts
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.