Terrain depth interaction

Post Reply
purplehaze
Posts: 7
Joined: Wed Oct 16, 2013 10:45 am

Terrain depth interaction

Post by purplehaze »

Hi all

My application uses a 4096x4096 terrain made out of 33x33 vertex chunks (chunks are resized and drawn in different positions depending on LOD, etc), but for the sake of this post, we can assume my player/avatar is always on a chunk of terrain at 33x33 vertices.

I understand it's fairly simple to get a rigid body interacting with a terrain but my player can sometimes be drawn 'under' the terrain - imagine he's walking in snow and the top layer of snow is represented by the terrain triangles. In certain areas, the snow is deeper than others so to represent that, I'm using a kind of perlin noise texture which sits (conceptually) under the terrain and effectively gives a nice randomish snow depth across certain areas of the terrain.

My question is, how would I get bullet to work with the rigid body (assume this is just a box at the moment) against the heights of the terrain layer minus the depth texture?

Thanks
c6burns
Posts: 149
Joined: Fri May 24, 2013 6:08 am

Re: Terrain depth interaction

Post by c6burns »

Do you actually need to use the height information from a texture? Couldn't you simply hand bullet one static mesh (adjusted by your texture), and then render the surface of the snow? Or is there a more complex idea about a physical interaction with the snow ... like slowly sinking to a max depth, or adjusting damping/friction based on snow depth?
purplehaze
Posts: 7
Joined: Wed Oct 16, 2013 10:45 am

Re: Terrain depth interaction

Post by purplehaze »

c6burns wrote:Do you actually need to use the height information from a texture? Couldn't you simply hand bullet one static mesh (adjusted by your texture), and then render the surface of the snow? Or is there a more complex idea about a physical interaction with the snow ... like slowly sinking to a max depth, or adjusting damping/friction based on snow depth?
Yes to both really, effectively this is for snowboarding. The snowboard on normal plain terrain at vertices 1m apart doesn't give a very granular or slopey feel. Plus when the snowboarder goes into deeper snow, I want the depth of the snow to change or be variable within that 1m which is why my perlin noise texture will be of higher resolution, probably 8 depth heights (or texels per metre). This way, the player can go from piste into powder seamlessly and whilst in the powder can hit bumpy areas, etc.
c6burns
Posts: 149
Joined: Fri May 24, 2013 6:08 am

Re: Terrain depth interaction

Post by c6burns »

Ok I understand much better now, thank you! Sounds fun!

I think the answer is still going to be that outside of bullet you generate meshes using your actual scene geometry modified by your depth texture. So meshes are made during a preprocess and at runtime the texture isn't needed by bullet. The geometry that goes into bullet can be higher resolution than the scene geometry, no problem. If complexity gets out of hand, then for performance you page in/out sections of physical terrain around the player.

You could also raytest the height difference between the snow layer (the surface terrain with collisions disabled) and the more complex depth layer (the physical terrain with collisions enabled). From there you can adjust physical properties based on current depth. This is how I would approach the issue and I am doing something similar to that in my current project albeit with water not snow. I am by no means an expert though :)
purplehaze
Posts: 7
Joined: Wed Oct 16, 2013 10:45 am

Re: Terrain depth interaction

Post by purplehaze »

c6burns wrote:Ok I understand much better now, thank you! Sounds fun!

I think the answer is still going to be that outside of bullet you generate meshes using your actual scene geometry modified by your depth texture. So meshes are made during a preprocess and at runtime the texture isn't needed by bullet. The geometry that goes into bullet can be higher resolution than the scene geometry, no problem. If complexity gets out of hand, then for performance you page in/out sections of physical terrain around the player.

You could also raytest the height difference between the snow layer (the surface terrain with collisions disabled) and the more complex depth layer (the physical terrain with collisions enabled). From there you can adjust physical properties based on current depth. This is how I would approach the issue and I am doing something similar to that in my current project albeit with water not snow. I am by no means an expert though :)
Thanks for the response. I wasn't sure whether passing geometry to the Bullet engine every frame was going to be too slow, it's no problem to make a more granular mesh of what's immediately around the player rather than passing in the entire terrain as I do that already for something else.

Is that what generally happens with terrains in bullet if the size is large? (I mean simply passing in a subset of it rather than the whole terrain/chunk)
c6burns
Posts: 149
Joined: Fri May 24, 2013 6:08 am

Re: Terrain depth interaction

Post by c6burns »

The real performance hit (at least in my case) comes from creating the collision shape of the rigidbody. You would want to do that during scene setup or in a background thread. Adding and removing bodies from the world is a fairly trivial operation.
purplehaze
Posts: 7
Joined: Wed Oct 16, 2013 10:45 am

Re: Terrain depth interaction

Post by purplehaze »

c6burns wrote:The real performance hit (at least in my case) comes from creating the collision shape of the rigidbody. You would want to do that during scene setup or in a background thread. Adding and removing bodies from the world is a fairly trivial operation.
So creating the collision shape for the terrain may be costly. It may just be better to handle the terrain collision manually and use bullet for collisions with things likes rocks and trees such.
Post Reply