Jump to content

Culling seems to get slow quickly


Go to solution Solved by Josh,

Recommended Posts

Posted

The culling is noticeably slower than the camera movement. At first I didn't really think this was a "bug" per se, because I had over 8000 models in the scene; however, it is still noticeable (although to a lower extent) with model counts as low as 4. The models have between 0 and 1024 vertices (with most having 0).

I do this code for each model:

model->AddMesh(mesh);
model->UpdateBounds();
model->Staticize();

Here is a video of this happening with 8000 models (7600 of which have no vertices):

Another thing I tried was to filter out models with zero vertices from being created (I thought maybe that was the problem), but that didn't stop the issue (even for as little as 4 remaining models).

  • Upvote 1

i now hate love C++

Beeeeeeeeeeeeeep~~This is a test of the emergency signature system~~Beeeeeeeeeeeeeep

RX 6800XT | i5-13600KF | 32GB DDR5 | 1440p is perfect

Posted
6 minutes ago, Josh said:

If you are running in debug mode, I think this is okay. How is the result in release mode?

I noticed it in release mode too, but I haven't tested it as extensively.

i now hate love C++

Beeeeeeeeeeeeeep~~This is a test of the emergency signature system~~Beeeeeeeeeeeeeep

RX 6800XT | i5-13600KF | 32GB DDR5 | 1440p is perfect

  • 4 weeks later...
Posted

I am having trouble finding a convex hull implementation that doesn't triangulate the results. Could write my own but it might take a couple of days to get right...

Let's build cool stuff and have fun. :)

  • Solution
Posted

Implemented Camera:SetSweptCulling and it works nicely. Will be in next build.

#include "UltraEngine.h"
#include "ComponentSystem.h"

using namespace UltraEngine;

int main(int argc, const char* argv[])
{
    //Get the displays
    auto displays = GetDisplays();

    //Create a window
    auto window = CreateWindow("Ultra Engine", 0, 0, 1280*2, 720*2, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);

    //Create a world
    auto world = CreateWorld();

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

    //Create a camera
    auto camera = CreateCamera(world);
    camera->SetClearColor(0.125);
    camera->SetPosition(0, 0, -4);
    camera->AddComponent<CameraControls>();

    bool swept = true;
    camera->SetSweptCulling(true);
    window->SetText("Swept culling enabled");

    //Create a light
    auto light = CreateDirectionalLight(world);
    light->SetRotation(45, 35, 0);
    light->SetColor(2);

    std::vector<shared_ptr<Entity> > boxes;

    //Create a model
    auto model = CreateBox(world);
    
    for (int x = 0; x < 100; ++x)
    {
        for (int y = 0; y < 5; ++y)
        {
            auto inst = model->Instantiate(world);
            inst->SetPosition(x * 2 - 100, y * 2 - 4, 8);
            boxes.push_back(inst);
        }
    }

    model = nullptr;

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        if (window->KeyHit(KEY_SPACE))
        {
            swept = not swept;
            camera->SetSweptCulling(swept);
            if (swept)
            {
                window->SetText("Swept culling enabled");
            }
            else
            {
                window->SetText("Swept culling disabled");
            }
        }
        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

 

  • Like 1

Let's build cool stuff and have fun. :)

Posted

The swept culling works nicely, but i noticed that it is not working with terrains.

As soon as a terrain is visible i get a  "vector subscript out of range" exception:

>	$PROJECTNAME_d.exe!std::vector<class UltraEngine::Vec3,class std::allocator<class UltraEngine::Vec3> >::operator[](unsigned __int64)	Unbekannt
 	$PROJECTNAME_d.exe!UltraEngine::Culling::CullingTerrain::Draw(class std::shared_ptr<class UltraEngine::Culling::CameraVisibilityList> &,class std::map<class std::shared_ptr<class UltraEngine::Render::RenderMesh>,class std::shared_ptr<class UltraEngine::Culling::SurfaceBatch>,struct std::less<class std::shared_ptr<class UltraEngine::Render::RenderMesh> >,class std::allocator<struct std::pair<class std::shared_ptr<class UltraEngine::Render::RenderMesh> const ,class std::shared_ptr<class UltraEngine::Culling::SurfaceBatch> > > > &,class std::shared_ptr<class UltraEngine::Culling::CullingWorld>,class std::shared_ptr<class UltraEngine::Culling::CullingBuffer>,class std::shared_ptr<class UltraEngine::Culling::CullingCamera>,class std::shared_ptr<class UltraEngine::Render::RenderCamera>,bool,int)	Unbekannt
 	$PROJECTNAME_d.exe!UltraEngine::Culling::CullingOctreeNode::DrawEntities(class std::shared_ptr<class UltraEngine::Culling::CameraVisibilityList> &,class std::map<class std::shared_ptr<class UltraEngine::Render::RenderMesh>,class std::shared_ptr<class UltraEngine::Culling::SurfaceBatch>,struct std::less<class std::shared_ptr<class UltraEngine::Render::RenderMesh> >,class std::allocator<struct std::pair<class std::shared_ptr<class UltraEngine::Render::RenderMesh> const ,class std::shared_ptr<class UltraEngine::Culling::SurfaceBatch> > > > &,class std::shared_ptr<class UltraEngine::Culling::CullingWorld>,class std::shared_ptr<class UltraEngine::Culling::CullingBuffer>,class std::shared_ptr<class UltraEngine::Culling::CullingCamera>,class std::shared_ptr<class UltraEngine::Render::RenderCamera>,class UltraEngine::Vec3 const &,int,int,bool,int)	Unbekannt
 	$PROJECTNAME_d.exe!UltraEngine::Culling::CullingOctreeNode::Draw(class std::shared_ptr<class UltraEngine::Culling::CameraVisibilityList> &,class std::map<class std::shared_ptr<class UltraEngine::Render::RenderMesh>,class std::shared_ptr<class UltraEngine::Culling::SurfaceBatch>,struct std::less<class std::shared_ptr<class UltraEngine::Render::RenderMesh> >,class std::allocator<struct std::pair<class std::shared_ptr<class UltraEngine::Render::RenderMesh> const ,class std::shared_ptr<class UltraEngine::Culling::SurfaceBatch> > > > &,class std::shared_ptr<class UltraEngine::Culling::CullingWorld>,class std::shared_ptr<class UltraEngine::Culling::CullingBuffer>,class std::shared_ptr<class UltraEngine::Culling::CullingCamera>,class std::shared_ptr<class UltraEngine::Render::RenderCamera>,class UltraEngine::Vec3 const &,int,bool,bool,int)	Unbekannt
 	$PROJECTNAME_d.exe!UltraEngine::Culling::CullingCamera::BuildVisibilityLists(class std::shared_ptr<class UltraEngine::Culling::CullingWorld>,class std::shared_ptr<class UltraEngine::Culling::CullingBuffer>,class std::shared_ptr<class UltraEngine::Culling::VisibilityList>)	Unbekannt
 	$PROJECTNAME_d.exe!UltraEngine::Culling::CullingWorld::BuildVisibilityLists(class std::shared_ptr<class UltraEngine::Culling::CullingBuffer>,class std::shared_ptr<class UltraEngine::Culling::CullingWorld>)	Unbekannt
 	$PROJECTNAME_d.exe!UltraEngine::Culling::CullingThreadManager::Update(bool)	Unbekannt
 	$PROJECTNAME_d.exe!UltraEngine::Core::ThreadManager::EntryPoint(class std::shared_ptr<class UltraEngine::Object>)	Unbekannt
 	$PROJECTNAME_d.exe!UltraEngine::Thread::thread_function(void *)	Unbekannt
 	ucrtbased.dll!00007ff985793010()	Unbekannt
 	kernel32.dll!00007ffa6a8e7344()	Unbekannt
 	ntdll.dll!00007ffa6c1026b1()	Unbekannt

 

  • Upvote 1
  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Posted

Easy fix. 

#include "UltraEngine.h"
#include "ComponentSystem.h"

using namespace UltraEngine;

int main(int argc, const char* argv[])
{
    //Get the display list
    auto displays = GetDisplays();

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

    //Create a world
    auto world = CreateWorld();
    world->SetAmbientLight(0);

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

    //Create a camera
    auto camera = CreateCamera(world);
    camera->SetFov(70);
    camera->SetPosition(0, 50, 0);
    camera->SetRotation(45, 0, 0);
    camera->SetClearColor(0.125);
    camera->SetSweptCulling(true);

    //Sunlight
    auto light = CreateDirectionalLight(world);
    light->SetRotation(45, 35, 0);
    light->SetColor(2);

    //Create terrain
    auto terrain = CreateTerrain(world, 512);
    terrain->LoadHeightmap("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Terrain/512.r16");
    terrain->SetScale(1, 100, 1);

    //Create base material
    auto ground = CreateMaterial();
    auto diffusemap = LoadTexture("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Materials/Ground/river_small_rocks_diff_4k.dds");
    auto normalmap = LoadTexture("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Materials/Ground/river_small_rocks_nor_gl_4k.dds");
    ground->SetTexture(diffusemap, TEXTURE_BASE);
    ground->SetTexture(normalmap, TEXTURE_NORMAL);
    terrain->SetMaterial(ground);

    //Create paint material
    auto rocks = CreateMaterial();
    diffusemap = LoadTexture("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Materials/Ground/Rocks_Dirt_Ground_2k.dds");
    normalmap = LoadTexture("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Materials/Ground/Rocks_Dirt_Ground_2k_dot3.dds");
    auto dispmap = LoadTexture("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Materials/Ground/Rocks_Dirt_Ground_2k_disp.dds");
    rocks->SetTexture(diffusemap, TEXTURE_BASE);
    rocks->SetTexture(normalmap, TEXTURE_NORMAL);
    rocks->SetTexture(dispmap, TEXTURE_DISPLACEMENT);

    int rocklayer = terrain->AddLayer(rocks);

    //Apply material based on terrain slope
    for (int x = 0; x < terrain->resolution.x; ++x)
    {
        for (int y = 0; y < terrain->resolution.y; ++y)
        {
            float slope = terrain->GetSlope(x, y);
            if (slope > 15.0f)
            {
                float wt = Min((slope - 15.0f) / 10.0f, 1.0f);
                terrain->SetLayerWeight(rocklayer, x, y, wt);
            }
        }
    }

    //Camera controls
    camera->AddComponent<CameraControls>();

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

 

  • Like 1

Let's build cool stuff and have fun. :)

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.

×
×
  • Create New...