Skip to main content
GameDev.net gamedev.net
🔒 Locked

directx volume terrain

Started by widmowyfox Apr 26, 2016 at 11:35 AM 12 replies 3.2k views
Original Post
widmowyfox
widmowyfox

Hello, I want to make my terrain 3d- add underground caves, mining option etc.

How can I edit 2d grid? I tried with simple face moving but it doesnt expand grid of course.

I want to achive something like this

using the easiest way. Any tips?

Hodgman
Hodgman

Marching cube is this black cube on video, but what is isosurface?

An isosurface in this case is the boundary between the "inside" and the "outside" of the object -- it's the thing you're trying to compute so that you'll have your terrain :)

widmowyfox
widmowyfox

ok now I am totally lost , thanks :D

I want to lean on http://paulbourke.net/geometry/polygonise/

There's isosurface (it's the thing you're trying to compute so that you'll have your terrain) so what is this box and how can i get position of vertices? Is it volume of terrain?

ohhh and one more: What is isolevel and how can I get it?

I need voxel grid for that, right?

Another example

JTippetts
JTippetts

Yes and I read http://paulbourke.net/geometry/polygonise/

but I cant imagine how it exacly works :/

Any examples in directx?

Marching cube is this black cube on video, but what is isosurface?


The black cube in the video is not "marching cube". That's just the guy's editing cursor, a visual marker to show the location he's looking at to edit.

Marching cube is an algorithm, or set of steps, that can convert a density field function to a mesh.

An isosurface can be described as the set of all points where the density function is equal to some value, this value being the "isolevel".

To start with, you need to understand that your volume terrain is going to basically be a mathematical function that for some input (x,y,z) will return a value, or density, at that location. This output value is typically a floating point value in the range of 0 to 1. So any given coordinate location within the bounds of your world or level will have a corresponding density value. The iso-level parameter determines where the boundary between "solid" and "open" lies. If you set iso-level to 0.5, then any (x,y,z) location whose density value is less than or equal to 0.5 is considered "solid", while everywhere else is considered open.

The tricky part in this type of thing is generating a mesh that follows the iso-surface of the density function at the threshold of iso-level. The Marching Cubes algorithm is one such technique. It operates by splitting the volume up into discrete cubical cells, and evaluating the density function at each corner of each cell. Cells where some of the points are "solid" and others are "open" are considered to be parts of the iso-surface, and the algorithm will generate a small bit of mesh geometry for this cell, representing a divide between the solid and open cells. Once all surface cells are evaluated, the resulting pieces of geometry are consolidated to form the surface mesh of the volume.

The term "marching cubes" comes from the mental metaphor of cubes "marching" across the surface of the volume, since an optimization in the algorithm includes starting at a known surface cell and recursing out to neighbors of that cell that are ALSO surface cells.
Norman Barrows
Norman Barrows

>> Marching cube is an algorithm, or set of steps, [snip]

a most lucid explanation!

+1

i'd heard of it, but never looked it up. with just that short explanation you provided, i now understand what it does and how it works. a most clever algo.

Norm Barrows Rockland Software Productions "Building PC games since 1989"</
widmowyfox
widmowyfox

thanks, I understand now, one more question:

All of these is how to generate 3d grid base on volume-density data, but how can I edit this grid (videos). Is it editing base on isolevel changes?I already have grid base on height map and I only want to make it editable.

JTippetts
JTippetts
If you store your terrain as a 3D grid of values, then you can edit the terrain by changing the value stored at a particular location. You can generate your mesh using marching cubes, using the 3D grid as the density function. Each cell of the 3D grid would be interpreted as a corner point for a set of cubes. Editing operations could be either binary (set a particular array location to either 1 or 0) or smooth (add or subtract a small increment). Smooth editing would result in smoother mesh generation.

As for isolevel, you just pretty much determine what you want that to be when you start. Set it at, say, 0.5 and then you don't usually change that again. That's simply the arbitrarily-chosen value of where you locate your iso surface.
widmowyfox
widmowyfox

But this will require dynamic buffer and calculate all triangles every time even when i dont edit anything.

JTippetts
JTippetts
You will need to recalculate triangles only when a value is changed. You can also reduce the amount of recalculation that is performed by splitting your volume up into 'chunks', where each chunk is some arbitrary dimension of cells, and running marching cubes on a per-chunk basis. Then you only need to regenerate the chunks that are actually affected by the edit, rather than the entire landscape mesh.
widmowyfox
widmowyfox

Wow, nice idea. Maybe i dont have to recalculate all triangles but I still have to create dynamic buffer for each chunk :/

And I need to store a lot of volume data. What is the best way to increse speed? Binary files?

JTippetts
JTippetts

Wow, nice idea. Maybe i dont have to recalculate all triangles but I still have to create dynamic buffer for each chunk :/


Probably, yes.

And I need to store a lot of volume data. What is the best way to increse speed? Binary files?


Well, binary files are usually more quickly loaded than text files, yes. Other than that, you'll need to profile to find where your bottlenecks are, and try to apply optimizations as needed.
vinterberg
vinterberg

You can also generate the triangles on the GPU in realtime using a geometry shader, so you just send the voxel data directly :)

.:vinterberg:.  

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.