TerrainCulledChunks ( terrain )
Parameters
| terrain - terrain entity to query |
Description
|
Returns how many of a terrain's chunks frustum culling rejected in its last render pass. This is the other half of TerrainVisibleChunks: the two always add up to the terrain's total chunk count, which is handy because there is no command that reports that total directly. Each chunk is tested as a world-space box that includes its own minimum and maximum height, so a chunk is only thrown away when the whole column of ground it covers is off screen. A big culled number is good news - it is geometry the renderer never touched. The useful reading is the ratio. If you spin the camera and the culled count barely moves on a large terrain, the camera is seeing nearly everything and you are paying for the whole landscape every frame; fog with a shorter camera range, or a lower camera, does more for you there than tightening TerrainLODRanges. Read it after RenderWorld. Like the other terrain counters it is cleared at the start of each render pass, so it describes the pass that just finished and a second camera's pass replaces the first camera's figure. Gotcha: culled chunks are cheap, not free - their bounds are still refreshed each pass, and the count says nothing about triangles. This is also per terrain; for whole entities culled across the scene use RenderCulledEntities instead. See also: TerrainVisibleChunks, TerrainTriangles, TerrainLODRanges, RenderCulledEntities, CameraRange. |
Example
; TerrainCulledChunks Example ; --------------------------- Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,6,-40 CameraClsColor camera,110,150,200 light=CreateLight(1) RotateEntity light,50,-30,0 ; Rolling hills built from a sine-wave height field terrain=CreateTerrain(128) For z=0 To 127 For x=0 To 127 ModifyTerrain terrain,x,z,0.2+Sin(x*10)*Cos(z*10)*0.12 Next Next ScaleEntity terrain,0.5,20,0.5 PositionEntity terrain,-32,-5,-32 TerrainShading terrain,True TerrainDetail terrain,8000,True ; Plain grass texture drawn in code grass=CreateTexture(8,8,1+8) SetBuffer TextureBuffer(grass) : ClsColor 75,135,60 : Cls : SetBuffer BackBuffer() EntityTexture terrain,grass sun_angle#=-30 While Not KeyDown(1) ; The sun slowly circles so the hills' shading shifts sun_angle=sun_angle+0.2 RotateEntity light,50,sun_angle,0 ; Arrow keys move the camera - turning aims chunks out of the frustum If KeyDown(200) Then MoveEntity camera,0,0,0.1 If KeyDown(208) Then MoveEntity camera,0,0,-0.1 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 RenderWorld ; Count the chunks frustum culling rejected in that render pass culled=TerrainCulledChunks(terrain) Text 0,0,"Arrow keys: fly (turn to cull more chunks) Esc: exit" Text 0,20,"TerrainCulledChunks(terrain) = "+culled+" of 16 chunks" Text 0,40,"Visible: "+TerrainVisibleChunks(terrain)+" Triangles: "+TerrainTriangles(terrain) Flip Wend End
Index