TerrainTriangles ( terrain )
Parameters
| terrain - terrain entity to query |
Description
|
Returns how many terrain triangles were submitted in the last render pass. This is counted after everything that reduces it - frustum culling, the detail level each chunk chose, the extra stitching where a fine chunk meets a coarse one, and any cells removed by holes. It is the real geometry cost of the landscape for that pass rather than a theoretical maximum, which makes it the single best number for tuning terrain. Put it in a debug overlay and change one thing at a time. Pull TerrainLODRanges in and watch it drop; raise TerrainDetail and watch it climb; fly the camera up and see how quickly a wide view multiplies it. Next to your frame time it answers the question that actually matters - whether the landscape or everything else is the expensive half of the scene. Read it after RenderWorld. The terrain counters are cleared at the start of every render pass, so this describes the pass that just finished; if a second camera also draws the terrain, its pass replaces the first one's number. Gotcha: it counts this terrain only. For the whole scene use TrisRendered. Holes are a two-sided trade here - they remove their own cells from the count, but a chunk containing any hole is forced to full detail, so a few scattered holes across a big map can raise the figure rather than lower it. See also: TerrainVisibleChunks, TerrainCulledChunks, TerrainLODRanges, TerrainDetail, TrisRendered. |
Example
; TerrainTriangles 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 ; 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 detail=8000 wire=0 sun_angle#=-30 While Not KeyDown(1) ; Press [ / ] to change the TerrainDetail triangle budget If KeyDown(26) And detail>1000 Then detail=detail-100 If KeyDown(27) And detail<20000 Then detail=detail+100 TerrainDetail terrain,detail,True ; W toggles wireframe so you can see the triangles being counted If KeyHit(17) Then wire=1-wire WireFrame wire ; 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 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 ; Triangles actually submitted after LOD, stitching and holes triangles=TerrainTriangles(terrain) Text 0,0,"Arrows: move [ / ] : detail budget W: wireframe Esc: exit" Text 0,20,"TerrainTriangles(terrain) = "+triangles Text 0,40,"TerrainDetail budget: "+detail Flip Wend End
Index