Jump to content

Culling seems to get slow quickly


IceBurger
 Share

Go to solution Solved by Josh,

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 4 weeks later...

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...

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

I was able to integrate the convex hull solver from the Bullet Physics library and it seems to work okay. Testing...

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

  • Solution

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

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

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
  • Intel® Core™ i7-8550U @ 1.80 Ghz 
  • 16GB RAM 
  • INTEL UHD Graphics 620
  • Windows 10 Pro 64-Bit-Version
Link to comment
Share on other sites

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

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...