Followers 0

# How to cull objects behind terrain like CryEngine2

## 10 posts in this topic

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 [url="http://leadwerks.com/werkspace/topic/3192-occlusion-culling/"]http://leadwerks.com/werkspace/topic/31 ... n-culling/[/url]
does any one know some hints or relative links about the solution?
thanks
0

##### Share on other sites
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. [url="http://assaultwars.com/javascript/heightmapocclusion.html"]I wrote up a very simple test[/url]. 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.
1

##### Share on other sites
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?
0

##### Share on other sites
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.
1

##### Share on other sites
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.

1

##### Share on other sites
There is also [url="http://research.cs.queensu.ca/%7Ejstewart/terrainSummary/"]Horizon Occlusion Culling[/url]
1

##### Share on other sites
i asked the same question in ogre forum,they told me CryEngine utilize [color=#333333][url="http://www.cg.tuwien.ac.at/~scherzer/chc/index.html"]Coherent Hierarchical Culling[/url](CHC) to cull the scene.this algorithm make use of hardware occlusion query, but [/color][color=#333333] when [/color][color=#333333]i put crysis in NvperHud[/color][color=#333333] i found [/color][color=#333333]only one IDirect3DQuery9 was called [/color][color=#333333] [/color][color=#333333]after i scanned all DX API calls in one frame[/color][color=#333333], it was the called before rendering the ocean. so i was puzzled..[/color]
[color=#333333]
[/color]

0

##### Share on other sites
[quote name='jdyyx1984' timestamp='1301325699' post='4791358']
i asked the same question in ogre forum,they told me CryEngine utilize [color="#333333"][url="http://www.cg.tuwien.ac.at/~scherzer/chc/index.html"]Coherent Hierarchical Culling[/url](CHC) to cull the scene.[/color]

[color="#333333"][/quote], people come up with funky ideas
[/color]
[quote name='jdyyx1984' timestamp='1301325699' post='4791358']
[color="#333333"]this algorithm make use of hardware occlusi[/color][color="#333333"]on query, but [/color][color="#333333"] when [/color][color="#333333"]i put crysis in NvperHud[/color][color="#333333"] i found [/color][color="#333333"]only one IDirect3DQuery9 was called [/color] [color="#333333"]after i scanned all DX API calls in one frame[/color][color="#333333"], it was the called before rendering the ocean. so i was puzzled..[/quote][/color]

[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]

[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.
[/color]
1

##### Share on other sites
so they use some kind of [color=#1C2837][size=2]software occlusion culler , i 'm so curious~~~[/size][/color][img]http://public.gamedev.net/public/style_emoticons/default/angry.gif[/img]
0

##### Share on other sites
[quote name='jdyyx1984' timestamp='1301329533' post='4791375']
so they use some kind of [color="#1C2837"][size="2"]software occlusion culler , i 'm so curious~~~[/size][/color][img]http://public.gamedev.net/public/style_emoticons/default/angry.gif[/img]
[/quote]

yes, software occlusion culling <3

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

1

##### Share on other sites
i'm using horizon occlusion culling with hierarchical Z occlusion map, the result is very satisfied.
horizon occlusion culling is very fast but in some situation it can not work( like stand on top of the hill), so mixed with hierarchical Z occlusion map.

1

## Create an account

Register a new account