GetCulled
This function indicates whether an entity has been culled from rendering or not.
Syntax
- bool GetCulled(camera=null)
Parameters
- camera: (Camera): specifies the camera to return culling information for.
Returns
(boolean)
If no camera is specified, the function will return true if the entity was rendered by any camera in the last frame, including shadowmap rendering for lights. A single directional light in the scene, for example, will cause confusing results because objects will seem to be unoccluded even when hidden behind walls. Therefore, the camera you want to test should be passed to the function to get more useful results.
Example
#include "Leadwerks.h"
using namespace Leadwerks;
int main(int argc, const char *argv[])
{
Leadwerks::Window* window = Leadwerks::Window::Create();
Context* context = Context::Create(window);
World* world = World::Create();
Camera* camera = Camera::Create();
camera->Move(0, 0, -8);
Light* light = DirectionalLight::Create();
light->SetRotation(35, 35, 0);
//Create a model to act as an occluder
Model* model = Model::Box();
model->SetScale(2);
model->SetColor(0.0, 0.0, 1.0);
//Create a model to test the visibility of
model = Model::Box();
model->SetColor(0.0, 1.0, 0.0);
model->SetPosition(0.0, 0.0, 6.0);
//Enable individual entity occlusion culling. Normally we would not do this
//because the occlusion test is as expensive as just rendering the object.
//A courser occlusion culling system is always active in the world octree.
model->SetOcclusionCullingMode(true);
while (true)
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;
model->SetPosition(Math::Sin(Leadwerks::Time::GetCurrent() / 20.0)*4.0, 0, 4);
if (window->KeyHit(Key::Space))
{
model->SetOcclusionCullingMode(!model->GetOcclusionCullingMode());
}
Leadwerks::Time::Update();
world->Update();
world->Render();
context->SetBlendMode(Blend::Alpha);
context->DrawText("Culled: " + String(model->GetCulled(camera)), 2, 2);
context->DrawText("Occlusion culling mode: " + String(model->GetOcclusionCullingMode()), 2, 22);
context->Sync();
}
}