SetOcclusionCullingMode
This function sets the entity occlusion testing mode.
Syntax
- SetOcclusionCullingMode(bool occlusionmode)
Parameters
- occlusionmode: if set to true the entity will use per-entity occlusion testing, otherwise only octree occlusion testing will be used.
Remarks
Per-entity occlusion testing is only recommended for objects that are expensive to render, like animated characters. The octree system already uses occlusion testing and will cull most occluded objects. You generally do not need to adjust this setting explicitly because by default, lights and animated models are set to use per-entity occlusion testing.
Leadwerks features hardware occlusion culling built into the scene octree. This eliminates the need for most occlusion culling on individual entities. Since the occlusion test itself has a small performance cost, it only makes sense to use it on individual entities that have a high cost of rendering, such as lights and animated models. By default, these are both set automatically to use occlusion culling on a per-entity basis.
Except for special circumstances, it is generally not necessary or advisable to adjust occlusion culling settings yourself, as changes may actually degrade performance.
Example
--Create a window
window = Window:Create()
context = Context:Create(window)
world = World:Create()
camera = Camera:Create()
camera:Move(0,0,-3)
local light = DirectionalLight:Create()
light:SetRotation(35,35,0)
--Create a model to act as an occluder
local 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,6)
--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 do
if window:Closed() or window:KeyHit(Key.Escape) then return false end
model:SetPosition(Math:Sin(Time:GetCurrent()/20.0)*4.0,0,4)
if (window:KeyHit(Key.Space)) then
model:SetOcclusionCullingMode(not model:GetOcclusionCullingMode())
end
Time:Update()
world:Update()
world:Render()
context:SetBlendMode(Blend.Alpha)
context:DrawText("Culled: "..tostring(model:GetCulled(camera)),2,2)
context:DrawText("Occlusion culling mode: "..tostring(model:GetOcclusionCullingMode()),2,22)
context:Sync()
return true
end