How to cull objects behind terrain like CryEngine2

Started by
9 comments, last by wmonash 13 years ago
I found CryEngine2 could cull every thing behind terrain blocks, including terrain itself, i thought it might use the hardware query to do this ,but i found nothing in NvperfHud,the only thing i found was some one metioned in a forum: 'So you cant use terrain slopes and hills as a trick to optimize your level like Crysis does' in http://leadwerks.com/werkspace/topic/31 ... n-culling/
does any one know some hints or relative links about the solution?
thanks :)
Advertisement
I was actually just recently discussing this problem with a friend. He had very hilly terrain and wanted to optimize the rendering by culling the objects occluded by the hills. I wrote up a very simple test. Given a heightmap that's NxN, in the example's case 64 by 64, and a player's position you can perform an optimized 2DDDA grid traversal from the player to a point of interest see if it's occluded. In the example the player is the mouse position 2 meters above the terrain. The points of interest that are tested are points randomly positioned above the terrain.

You might be wondering how this helps for culling large amounts of entities. If you store your entities in an octree and perform frustum culling already you know that you have to expand nodes that intersect the frustum. So you can exploit this occlusion by doing a test for nodes of a certain depth (basically for nodes that represent a cube size that's small enough to be hidden behind a mountain). If you have to expand a node in the octree you first test the top 4 points of the cube by traversing the heightmap from the player and seeing if it can see the point. It's not perfect and really weird terrain can break the algorithm, but ideally it works and allows you to not expand nodes and thus not include entities in those nodes. I haven't test it myself, but it seems cheap enough to perform.
Will it be a little expensive? for example ,the terrain is 1024*1024 ,a lot of test are needed for every object in the scene,and if the object is very large(a big castle far away from the camera ),it is very possible to get a wrong result if only top 4 points of the castle's node are tested against terrain grid, we can avoid this by splitting the node into small segments(smaller than terrain's grid),but the number of test grows greatly in this case.
any suggestion?
According to my tests.
If implemented right, occlusion culling doesn't stall the rendering and actually helps.
Culling objects behind terrain simple. You don't even need to sort anything. Just draw the terrain first.
Occlusion culling conflicts with other "speeding up" techniques like instancing, so doing it on individual objects isn't the perfect way.
You should, for example occlusion cull octree nodes against one another and the terrain in that nodes you should have instanced objects that you draw in one draw call. It depends of the scene, since there maybe nodes that contain lost of different meshes, so instancing won't help much, and maybe you will be better off in this situation have per-object culling, not per node, especially if the nodes are big and objects are complex. I think there's alway a compromise, and there isn't an ideal solution for every situation.
the simplest way to do it would be to save for octree nodes what other ocetree nodes are visible from this node. you wouldn't save it for billion of nodes, but bit-tests for the octree-traversal. this can be computed offline in any way you'd like to. it's similar to the PVS the quake engines use, but on octree level, not on convex-bsp-cell level, if you sort objects into the octree, you'll get their visibility like free candy.

Tho, in cryengine it's done by a software occlusion culler, this way all kind of test: entity vs brush vs tree vs terrain work uniformly and it's editable in realtime, it's also quite fast, just some more work and experience is needed to get it running fast.

There is also Horizon Occlusion Culling
thanks for your answers !smile.gif
i asked the same question in ogre forum,they told me CryEngine utilize [color=#333333]Coherent Hierarchical Culling(CHC) to cull the scene.this algorithm make use of hardware occlusion query, but [color=#333333] when [color=#333333]i put crysis in NvperHud[color=#333333] i found [color=#333333]only one IDirect3DQuery9 was called [color=#333333] [color=#333333]after i scanned all DX API calls in one frame[color=#333333], it was the called before rendering the ocean. so i was puzzled..
[color=#333333]



i asked the same question in ogre forum,they told me CryEngine utilize [color="#333333"]Coherent Hierarchical Culling(CHC) to cull the scene.

[color="#333333"]
:), people come up with funky ideas :)


[color="#333333"]this algorithm make use of hardware occlusi[color="#333333"]on query, but [color="#333333"] when [color="#333333"]i put crysis in NvperHud[color="#333333"] i found [color="#333333"]only one IDirect3DQuery9 was called [color="#333333"]after i scanned all DX API calls in one frame[color="#333333"], it was the called before rendering the ocean. so i was puzzled..



[color="#333333"]this one is really just for the water and especially for rendering the reflection map. (if you don't see the water, no need to render the reflection), and in contrast to most objects in a level, that have simple boundaries, ocean water has waves and is kinda infinite in size, so using the occlusion hardware occlusion results for this one makes really sense. you can check that out in the editor, move close to some wall where the ocean is behind, and when you move through the wall (in editor mode), you see the ocean appears some frames later.


[color="#333333"]you can also experiment with the occlusion culling, just enable the drawcall and polycounter and watch how it rises and drops when you move behind objects, terrain is obviously culled by that, but you won't see any latency issues like you'd see with hardware occlusion queries.
so they use some kind of [color=#1C2837][size=2]software occlusion culler , i 'm so curious~~~angry.gif

so they use some kind of [color="#1C2837"]software occlusion culler , i 'm so curious~~~angry.gif


yes, software occlusion culling <3


what are you curious about? I might know it from somewhere ;)

This topic is closed to new replies.

Advertisement