Jump to content

  • Log In with Google      Sign In   
  • Create Account


XNA 4.0 voxel map rendering, using noise techniques


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
46 replies to this topic

#1 winsrp   Members   -  Reputation: 273

Like
0Likes
Like

Posted 19 January 2012 - 03:46 PM

First of all, HI all,

Second of all, I know and I'm fully aware I'm a newb on game creation.

I have programmed desktop applications for quite a while now (more than 7 years) and I wanted to make something in the gaming department.

I have tons of ideas, but I know that in programming you need to start by building a very strong foundation otherwise the whole thing would be crap.

Now I don't like c# much, even I can read it, program it, use it and all that, but I like vb.net better (personal preference), so I made my project for xna 4 which has a ground in c#, but then I made my game class in vb importing the same libraries and everything works like a charm thanks to the bless of the .net framework. I don't really care to do all the nasty conversions from c# to vb.net, actually they help me to understand the code better, instead of just copy paste.

I've made like 7 tutorials already of XNA 4.0, with lots of great techniques, and I decided that seems like time to start shaping my own game.

Having said that, I decided that my world would be made out of cubes, which will make destruction, movement and generation of new cubes by the player a rather simple operation, as they wont have weird shapes.

And as such the first thing i wanted is terrain + camera.

I've made a cube array of 32x32x32 (x,y,z), using y as height and made my camera to go around. Now with a couple simple rules, you can set, the first 4 y layers to be ground, and above it, to be air.. also made some optimization's, to have the renderer only display the vertices of the cubes that can be seen on the top layer, hiding all the vertices that are below other cubes. I still need to optimize it further so only the vertices that are on screen are displayed but that will be done in the following days.

Now the first thing that occurred to me was using a height map, which seems simple enough to start playing with the camera a little (I still, don't have gravity not hit-boxes, so the camera is only to see what is the result. Now the result is nice, and i have already tried it at a 1024x256x1024 scale, and it looks even better, but seems like missing lots of details, so 2 problems arise from this

#1 the mountains are way too smoothed.
#2 I am limiting the bounds of the map to the amount of x and z that I put on my array, currently 1024x1024, and you can see from side to side, not to mention walk from side to side in less than a minute.

For problem #1 I investigated on lots of techniques, currently read more than a hundred articles (not exaggerating here, currently have more than 150 tagged pages on this topic), and I would like to know how can you create something like this

http://www.gamedev.n...type-world-gen/

in XNA 4.0 as i have found lots of code, but have not yet fully understood the meaning of all the terms, and the combination of techniques to get this result, plus I would like to remove the floating islands that I have seen in some examples.

For problem #2, well, I first need to figure out how to get #1 done, and then how can I ask for a single [x,z] coordinate to get the array of next set of [y] cubes in any given direction, that will match the previews section.

Thanks all,

Winsrp.

Sponsor:

#2 winsrp   Members   -  Reputation: 273

Like
0Likes
Like

Posted 21 January 2012 - 08:57 PM

hmm... no love for the new guy,

I know that when your post gets to the second page, you better post an update to it, otherwise its dead.

I have managed to kind of get over problem #1, and definitively over problem #2, now the only problem i seem to have is the gradient to display more ground on the bottom and move air on top, which i have already tried like a 100 combinations and I cant get it to work..

Here are 5 sections in a cross array.

Test1.png

#3 way2lazy2care   Members   -  Reputation: 782

Like
0Likes
Like

Posted 21 January 2012 - 10:11 PM

Just because nobody replies doesn't mean they aren't interested. It just means they have nothing to say. Keep up the good work?

#4 Alpha_ProgDes   Crossbones+   -  Reputation: 4688

Like
0Likes
Like

Posted 22 January 2012 - 12:28 AM

A poster cannot live on views alone.
Beginner in Game Development? Read here.
 
Super Mario Bros clone tutorial written in XNA 4.0 [MonoGame, ANX, and MonoXNA] by Scott Haley
 
If you have found any of the posts helpful, please show your appreciation by clicking the up arrow on those posts Posted Image
 
Spoiler

#5 winsrp   Members   -  Reputation: 273

Like
0Likes
Like

Posted 23 January 2012 - 04:48 PM

ok so I managed to start using the libnoise, (as I was using something else), but I still haven't figured out how to make a gradient kind of map to load more ground on the lower half than the upper half.

Any ideas? as Libnoise seems to be rather popular, then I would think I might get a little more help here.

#6 winsrp   Members   -  Reputation: 273

Like
0Likes
Like

Posted 24 January 2012 - 09:17 PM

still not getting over the gradient map terrain, but i did some funny stuff, and stumble upon another interesting issue I'm shooting red balls at my terrain, when the ball hits the terrain then that block gets removed from the map. Really simple collision detection here. but it does something weird.

I've set up a test terrain of only 8 blocks on a 2x2x2 array to set out.

when i shoot the block somethings on screen it removes 2 blocks but checking on the buffers lists and all, it says it only removed one block, and the vertex and index buffer all say it only removed 1 block, still on screen 2 blocks are removed....

on the update method i check for collision and and then i clear the list that contains my vertices and indexes and refill it with the list.toarray that contains the new list of the remaining blocks, everything seems fine from the debuging stand point but not all blocks are displayed, even further more, at some point the missing blocks start to show up again... very weird.

#7 winsrp   Members   -  Reputation: 273

Like
0Likes
Like

Posted 25 January 2012 - 10:54 AM

Update: Never mind it was me being stupid, and not updating the indexes. So when you remove a block you need to recalculate the indexes as vertexes are not in the same order as they were before.

This is a section with no vertex optimization.

working section.png

#8 winsrp   Members   -  Reputation: 273

Like
0Likes
Like

Posted 26 January 2012 - 02:24 PM

does anyone know how to make some fast collition detection? I can check for sections and then blocks on each section, which allows me to shoot around 250 parallel bullets but if a single one touches the ground.. the game kind of stalls.

here a screen of several sections together and some holes from my bullets.

working group.png

#9 winsrp   Members   -  Reputation: 273

Like
0Likes
Like

Posted 26 January 2012 - 03:29 PM

and i have another question, hopefully ill get some hints on this one..

If i want to use perlin noise with different frequencies, but on the same map making it smooth, how can I make them fit together without looking like pasted in and cut.

#10 swiftcoder   Senior Moderators   -  Reputation: 9860

Like
0Likes
Like

Posted 26 January 2012 - 03:40 PM

There are many approaches, but one common approach is Fractal Brownian Motion.

Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#11 winsrp   Members   -  Reputation: 273

Like
0Likes
Like

Posted 27 January 2012 - 09:10 AM

hmm... but whats the difference between Perlin Noise and Fractal Brownian Motion? I currently have my perlin function that creates noise based on frecuency lacunarity persistance, octaves and such, I have read the article, but it seems to be talking of the same thing I have,

If i grab my function and change any of the parameters on the fly it will normally show weird results on screen like cutted sections and such, and I wanted to make some parts with high mountains, and others like long beaches and maybe some with large deep oceans and stuff

#12 swiftcoder   Senior Moderators   -  Reputation: 9860

Like
0Likes
Like

Posted 27 January 2012 - 11:05 AM

hmm... but whats the difference between Perlin Noise and Fractal Brownian Motion? I currently have my perlin function that creates noise based on frecuency lacunarity persistance, octaves and such, I have read the article, but it seems to be talking of the same thing I have

In that case, you have have already implemented fractal brownian motion.

<rant> Some idiot once misnamed value noise + fBm as 'Perlin noise', and ever since we are stuck with people using the wrong terminology </rant>

If i grab my function and change any of the parameters on the fly it will normally show weird results on screen like cutted sections and such

That sounds like a bug in your implementation. Changing the parameters (within reason) should always result in a continuous terrain.

and I wanted to make some parts with high mountains, and others like long beaches and maybe some with large deep oceans and stuff

That's a slightly different problem - fBm produces fairly uniform terrain across it's entire range. I would recommend you try out Ridged Multi-fractal - I don't have a reference implementation to hand, but I'm sure you can find one.


You generally have to combine several different types of fractal to achieve the kind of variety you are looking for, though. Consider using fBm to drive some of the parameters on a ridged multi-fractal...

Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#13 winsrp   Members   -  Reputation: 273

Like
0Likes
Like

Posted 27 January 2012 - 01:34 PM

Thanks for the info, I do know that Perlin noise is what should be called as 1 octave, with fixed frequency and persistance, and fBm is the combination of different octals of a single funtions (being Perlin, or other), I do have the implementation of all the functions as I have the libnoise for xna on my project and includes several of this fractal functions.

Now if I change the coordinates on my fBm for perlin noise, the values are really nice and smooth, but if i change the octaves, frecuency, etc on the fly, this will produce the cutted out sections that i have described. So I managed to combine a 2D perlin fBn that i use for initial height map, with another 2d perlin fBn with different values, and do some manual addition (i still need to use the add function from the libnoise to see if i get the same result as my manual implementation) in order to get a flat ground from the first and some more rough looking hills with the second, and im using a third 3d perlin fBn to create some caves and such on the ground.

All this combined seems to look rather nice, but now I have 2 more questions

1. how do i make the sections be split in biomes, so i have have a more desert looking area, and then a more rocky area. the problem in hand is not the generation itself, as I can do it by combining severs fBm functions, but more looking at the transition between areas? move from desert to grass, to mountains, to jungle, etc, without looking like im cutting sections again, if i stop a single fBm at a given time i don´t know if the mountain for example has reach its joing point between the next biome lets say desert, and so the mountain just gets cut flat from where i stop.

2. trying a single 3d perlin fBm, to make terrain i take every value > 0 as air, and any value < 0 as land, which produces an image such as the first i posted on this post, is there a way to apply a gradient on this function, so that i get more land on the botom and more air on top, ensuring that the lower layers are full ground and the upper layers full air, and the result in the middle seems smootly round instead of a flat area?

thanks.

http://www.blueplanetbiomes.org/world_biomes.htm

#14 M6dEEp   Members   -  Reputation: 890

Like
0Likes
Like

Posted 30 January 2012 - 12:54 AM

I've been fiddling around with different methods of implementing biomes in my own block engine and I think the best way to do that would be to create a different noise map (or generation layer, I do like buzz words) all together for them.

Currently I have a few noise generator modules linked together like an assembly line. Each module is responsible for generating a segment of the terrain (one module does underground cave systems, another does above ground features, etc). Doing it this way allows me to easily move/toggle the generation stages and edit them in isolation. My plan for biomes is to insert another module that generates a large scale noise and then interpolate between different biome terrain modules from this.

As for collision detection, I assume that you are using a 3D array to store your terrain. A method would be to use the camera position to index into the array and check to see if the blocks they're walking into are solid or air.

To make the terrain infinite like in Minecraft, I went with a circular array that goes pretty much like this:

Posted Image

Hope this helps.

#15 winsrp   Members   -  Reputation: 273

Like
0Likes
Like

Posted 30 January 2012 - 04:02 PM

interesting bit of information, i currently can do collisions, but they seem to take quite a while, so I'm optimizing those, i had to shrink the chunks otherwise i couldn't do multiple high velocity projectiles with explosions.. after 10 concurrent projectiles the game kind of stalls at 7 fps, until most of explosions are done (and I don't even have an explosion effect yet!!, I only remove the blocks), I also make quite some memory optimization as i couldn't load too many cubes at once, only around 250K, (I'm now around 3.4M in less than 5 secs, and I can also do 7.5M blocks on screen in less than 10 secs) but my frame rate starts to slow a bit to 30 fps... so planning on optimizing this as well.

Currently I'm not advancing much as I know that if I start doing lots of stuff optimizing its going to be a pain latter, and by doing so now, I will carry all those optimization's to further stages.

I still have to make it so the maps loads as I move, but that is a really near next step now.

Thanks for all the info.

Now with that out of the way... the next question.

i don't have a model in my screen and I don't want to start learning another program such as blender, to start doing one, so I thought... why don't I make a model in game... and so the question is..

how do I make a model in code?, for example I know how to make 4 blocks on top of each other with different dimensions, but how do i make the feet move in a walk position given the following model.

model.png

so its a head on top with a block, a body in the middle block and the 2 lower blocks are feet.

please don't mock my incredible paint skills. tx.

#16 winsrp   Members   -  Reputation: 273

Like
0Likes
Like

Posted 31 January 2012 - 08:52 AM

another quick question,

I was doing frustum culling, with the following code

boundingFrustum.Matrix = viewMatrix * projectionMatrix

So i then checked against my sections

If boundingFrustum.Contains(Section.BoundingBox) <> ContainmentType.Disjoint Then

but then it occurred to me... what if I start moving the world instead of the camera, it will make it easier for some validations that seem to be a pain in the... you know.

Instead of updating a camera position vector, I update a worldposition vector, and then do a worlmatrix.translation based on worldposition -1 (as it has to move against the camera). But now my frustum culling its all messed up.

Any ideas how can I apply frustum with world translation in place?

#17 winsrp   Members   -  Reputation: 273

Like
0Likes
Like

Posted 31 January 2012 - 09:04 AM

wow... never mind, I found out what I was doing bad!!... idiot me I had to update the section bounding box based on the new world position otherwise the world looks like moving but the bounding box of it is not... also need to update any other bounding box in the world... hmm...

#18 winsrp   Members   -  Reputation: 273

Like
0Likes
Like

Posted 31 January 2012 - 09:32 AM

no good then... ill move the camera, as moving the world will imply updating the bounding boxes of all my cubes.. and so no good. Performance hit was too big.

#19 winsrp   Members   -  Reputation: 273

Like
0Likes
Like

Posted 31 January 2012 - 09:31 PM

I seem to be having some trouble after 11 millon cubes, only around 400k faces loaded on mem (takes 22secs to load).., and i have applied as much culling as I have managed to find (actually didn't even knew what culling was till like 2 days ago)

memory collapses, even when frame rate is rather good at 60fps, it loads arrays with 700mb in memory, for all the cubes (only positions in x,y,z, color and height, and bounding box), and then it fills another 500mb with the vertex and index buffers... so I can load as much as near 13 million cubes, and it it goes over 1.6GB of ram and runs out of memory.

It seems like 1.6GB of mem is rather extensive for just some cubes... yes, lots of cubes I know, but still seems like it should be able to hold a larger amount, I was trying to get to near 20/30 million, but seems impossible.

So I was reading about instancing, but I don't know if this can be applied here. Here is a little screen.

nice world.png

#20 Waterlimon   Crossbones+   -  Reputation: 2477

Like
1Likes
Like

Posted 01 February 2012 - 06:26 AM

I think you would do it like, for each chunk, generate a single mesh thing and draw that instead of every cube separately. Then when you change that chunk you regenerate the mesh. And only draw faces which touch air.

o3o





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS