Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (780) Games in Android Showcase (233) games submitted by our members Games in WIP (856) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: 1 [2] 3 4 ... 7
 ignore  |  Print
 Voxel - a start  (Read 91517 times) 0 Members and 1 Guest are viewing this topic.
steg90

Senior Devvie

Medals: 2

 « Reply #30 - Posted 2013-03-10 23:23:07 »

I still think there is a way of doing just one glTranslatef, something like:

 1  2  3  4  5  6  7  8  9  10  11 `for(int x = 0; x < xAmount; x++){    for(int y = 0; y < yAmount; y++)    {        for(int z = 0; z < zAmount; z++)        {            glTranslatef(x, y, z);            glCallList(voxelList);        }    }}`

But obviously that won't work.

I guess if we store the blocks x,y,z in a 3d array, the above could work?!

int blocks[][][] = new int[16][16][16];

and use the index as the block position...
Opiop
 « Reply #31 - Posted 2013-03-11 01:14:25 »

Sorry, I don't think I understand, why would you multiply x by 2? Wouldn't there then be a gap between the cubes? I use the for loops and then call
 1 `glTranslatef(x, y, z)`
and it works fine (offsets are better than
 1 `glTranslatef()`
though, its far cheaper).
steg90

Senior Devvie

Medals: 2

 « Reply #32 - Posted 2013-03-11 08:06:43 »

Hi, the * 2 is the 'stride' or the width, height, depth of my cube (-0.5 to 0.5)

Still unsure how you can do this with just one glTranslatef...

So you just have the three loops and one glTranslatef?

Thanks,
Steve
Riven

« JGO Overlord »

Medals: 1357
Projects: 4
Exp: 16 years

 « Reply #33 - Posted 2013-03-11 09:33:40 »

 1  2  3  4  5  6  7  8  9  10  11  12  13  14 `int x0=0, y0=0, z0=0;for(int x = 0; x < xAmount; x++){    for(int y = 0; y < yAmount; y++)    {        for(int z = 0; z < zAmount; z++)        {            glTranslatef(x-x0, y-y0, z-z0);            glCallList(voxelList);            x0=x; y0=y; z0=z;        }    }}`

There, one translate-call. Needless to say that this is a horrible way to interact with drivers. Just fill VBOs already!

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
steg90

Senior Devvie

Medals: 2

 « Reply #34 - Posted 2013-03-11 19:34:13 »

Hi,

Hey, thanks for that, obvious now when look at it!

Guess next step then is to look at using VBO's?

Cheers
Agro
 « Reply #35 - Posted 2013-03-11 19:39:52 »

Yeah, they take up less calculations and rendering time because i think VBOs are stored in video memory. Am I right?

steg90

Senior Devvie

Medals: 2

 « Reply #36 - Posted 2013-03-11 19:47:49 »

I think you are correct in saying that.

So basically create the 'world' out of chunks, store in VBO's and render...

Of course, there are other optimisations that will need to be made, but, hey, I need to walk before
I can run!

At the moment, I've got a camera in place, a skybox and blocks being drawn using display lists, using simple random seed for height. So, need to implement:

1. Chunk rendering using display lists
2. Get rid of display lists and place chunks into VBO's
3. 2d/3d Perlin noise - 3d better if wanting caves etc...

Help! Lol

steg90

Senior Devvie

Medals: 2

 « Reply #37 - Posted 2013-03-11 22:03:31 »

Added latest screen show of 16x16x16 voxel, using simple random value for height and...still using display lists

I guess this would be regarded a chunk of the whole world and would be sent to the gpu in one blast using a VBO?  Also need some perlin/simplex noise for the heights, as mentioned just using a simple random number for them.

Thanks
Mike

« JGO Spiffy Duke »

Medals: 149
Projects: 1
Exp: 6 years

Java guru wannabe

 « Reply #38 - Posted 2013-03-11 22:13:12 »

Don't be scared of display lists. I'm running my game with displaylists in State of Fortune and it performs quite well. It even outperformed VBO's for drawing on my gfx card thanks to some driver optimization magic. It is a lot slower to update them though (factor 10 or so for my 66x66 chunks). VBO's are very useful when doing things like particle engines and dynamic animations, but other than that it isn't all too bad to use display lists.

Mike

My current game, Minecraft meets Farmville and goes online
State of Fortune | Discussion thread @ JGO
Opiop
 « Reply #39 - Posted 2013-03-11 22:31:03 »

So just to clarify, VBOs really aren't all that useful and don't offer much performance over Display Lists when used in static geometry?
steg90

Senior Devvie

Medals: 2

 « Reply #40 - Posted 2013-03-12 08:25:50 »

Thanks Mike,

Display lists have been completely removed from OpenGL 3.1 (still compatibility with ARB supported) and in 3.2 it is up to the driver writers if they want to support them - in compatibility profile.

A good discussion here:

http://www.slideshare.net/Mark_Kilgard/opengl-32-and-more

As the voxels are static is display list the best way, although, the player will be able to remove blocks so does this mean the display lists will need rebuilding?

Regards,
Steve
Mike

« JGO Spiffy Duke »

Medals: 149
Projects: 1
Exp: 6 years

Java guru wannabe

 « Reply #41 - Posted 2013-03-12 08:40:02 »

So just to clarify, VBOs really aren't all that useful and don't offer much performance over Display Lists when used in static geometry?

With my tests (using the different Riven VBO/VA techniques) I managed a more stable fps with VBO's (constantly in the 80's) while with display lists it fluctuated a bit more when looking around, but it was constantly higher (90-110).

Display lists have been completely removed from OpenGL 3.1 (still compatibility with ARB supported) and in 3.2 it is up to the driver writers if they want to support them - in compatibility profile.

Luckily LWJGL doesn't force you to use the 3.1 profile then I can just talk for myself and I've had less compatibility issues with State of Fortune which uses Displaylists than I have with State of Profit that uses VBO's. Sure, you need to have a really crappy (intel...) gfx driver to not be able to use VBOs correctly, but they are out there.

As the voxels are static is display list the best way, although, the player will be able to remove blocks so does this mean the display lists will need rebuilding?

When you remove blocks the display lists will need rebuilding, but if you try out State of Fortune you'll notice that the time it takes to rebuild the displaylist isn't even noticable as long as you spread out the rebuilding of several containers over several frames (which you should do with VBO's as well).

I'm not saying to use displaylists instead of VBOs, I'm just saying that it isn't as bad as people say they are. Especially seeing as at least my NVIDIA drivers optimize the (semi) static ones so heavily that they outperform what I can do with VBOs, even while following Riven's latter examples (http://www.java-gaming.org/topics/introduction-to-vertex-arrays-and-vertex-buffer-objects-opengl/24272/view). For anything dynamic that needs to be rebuilt more or less every frame, use VBOs, especially as you can multithread the creation of them with ease.

Mike

My current game, Minecraft meets Farmville and goes online
State of Fortune | Discussion thread @ JGO
steg90

Senior Devvie

Medals: 2

 « Reply #42 - Posted 2013-03-12 10:06:47 »

Cheers Mike,

Very interesting.

I'm quite new to OpenGL, was stuck on the direct3d band wagon for a while.

Have you any advice on a simple technique to get heights for my voxels, just using a simple random value at the moment which looks crud, need it look smoother, I've got the SimplexNoise class, but not tried to use it as yet.

Thanks,
Steve
Mike

« JGO Spiffy Duke »

Medals: 149
Projects: 1
Exp: 6 years

Java guru wannabe

 « Reply #43 - Posted 2013-03-12 11:08:34 »

Simplex is the easiest way to go while still getting a nice result To get an interesting landscape you can run it several times with a different frequency and weight. Something like this:

height=SimplexNoise.noise(x,y);
height+=SimplexNoise.noise(x/16,y/16)*10;

Mike

My current game, Minecraft meets Farmville and goes online
State of Fortune | Discussion thread @ JGO
orogamo
 « Reply #44 - Posted 2013-03-12 12:52:33 »

If you need terrain generation look at mine
http://www.java-gaming.org/topics/terrain-generator/27502/view.html

Local Copy: https://dl.dropbox.com/u/39535549/Volt.jar (Demo + Source)
steg90

Senior Devvie

Medals: 2

 « Reply #45 - Posted 2013-03-13 20:06:30 »

Thanks guys,

Will take a look at the code

Mike - height=SimplexNoise.noise(x,y);  the x and y, taking it I store the height inside an array
and then render?

I do this:

 1 `int voxelHeights[] = new int[xAmount * zAmount];  // used to store amount of voxels on y`

and in render:

 1  2  3  4  5  6  7  8  9  10  11  12  13  14 `int index = 0;      for(int x = 0; x < this.xAmount; x++)      {         for(int z = 0; z < this.zAmount; z++)         {            for(int y = 0; y < voxelHeights[index]; y++)            {               glTranslatef(x,y,z);               glCallList(voxelList);               glTranslatef(-x,-y,-z);            }            index++;         }      }`

At the moment, I use random value for height:

 1  2  3  4  5  6  7  8 `private void generateWorld() {      Random randomGenerator = new Random();      for (int heights = 0; heights < xAmount * zAmount; heights++) {         int height = randomGenerator.nextInt(16);         if(height == 0) height = 1;         voxelHeights[heights] = height;      }   }`

So I'm guessing that I need to put the simplex noise in my generateWorld method?

Steve
Opiop
 « Reply #46 - Posted 2013-03-13 20:12:39 »

Thanks guys,

Will take a look at the code

Mike - height=SimplexNoise.noise(x,y);  the x and y, taking it I store the height inside an array
and then render?

I do this:

 1 `int voxelHeights[] = new int[xAmount * zAmount];  // used to store amount of voxels on y`

and in render:

 1  2  3  4  5  6  7  8  9  10  11  12  13  14 `int index = 0;      for(int x = 0; x < this.xAmount; x++)      {         for(int z = 0; z < this.zAmount; z++)         {            for(int y = 0; y < voxelHeights[index]; y++)            {               glTranslatef(x,y,z);               glCallList(voxelList);               glTranslatef(-x,-y,-z);            }            index++;         }      }`

At the moment, I use random value for height:

 1  2  3  4  5  6  7  8 `private void generateWorld() {      Random randomGenerator = new Random();      for (int heights = 0; heights < xAmount * zAmount; heights++) {         int height = randomGenerator.nextInt(16);         if(height == 0) height = 1;         voxelHeights[heights] = height;      }   }`

So I'm guessing that I need to put the simplex noise in my generateWorld method?

Steve

I don't know anything about simpleX, but I think that yes, you should probably put it in your generateWorld method. I'm confused, a little, about why you call
 1 `glTranslatef()`
twice though, with positive and then negative values. Would that cancel the translate and just set the voxel position back at zero?
steg90

Senior Devvie

Medals: 2

 « Reply #47 - Posted 2013-03-13 20:50:21 »

Hi Mike,

The glTranslate twice is to reset position back of the model matrix.  I know I should just use one glTranslate, will resort to this later.

put this in my generateWorld to get heights from simplexnoise:

 1  2  3  4  5  6  7  8  9  10 `int index = 0;      for(int x = 0; x < xAmount; x++)      {         for(int y = 0; y < zAmount; y++)         {            int height = (int)SimplexNoise.noise(x, y);            voxelHeights[index] = height;            index++;         }      }`

I use height for how many voxels I draw on the Y, but SimplexNoise returns a double from the value of -1 to 1, don't get how I can use this?

Thanks
Mike

« JGO Spiffy Duke »

Medals: 149
Projects: 1
Exp: 6 years

Java guru wannabe

 « Reply #48 - Posted 2013-03-13 21:14:30 »

Hi Mike,

Everyone is Mike?

If your Simplex returns values from -1 to 1, just do (int)((result+1)/2*desired max height) or something like that.

Use pop and push matrix instead of translating back

Mike

My current game, Minecraft meets Farmville and goes online
State of Fortune | Discussion thread @ JGO
steg90

Senior Devvie

Medals: 2

 « Reply #49 - Posted 2013-03-13 21:27:56 »

Hi,

This is what I got for the simplex noise:

 1  2  3  4  5  6  7  8  9  10  11 `int index = 0;      for(int x = 0; x < xAmount; x++)      {         for(int z = 0; z < zAmount; z++)         {                        int height = (int) (SimplexNoise.noise(x/16F, z/16F)*16F);            voxelHeights[index] = height;            index++;         }      }`

height is sometimes zero, thus no height, what would you do with that, set it to 1? I'm taking it depending on the height you could set the block type to say water, grass, dirt, snow for instance?

Thanks again,
Steve
HeroesGraveDev

JGO Kernel

Medals: 382
Projects: 11
Exp: 4 years

┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻

 « Reply #50 - Posted 2013-03-14 02:54:15 »

Simplex Noise returns values between -1 and 1.

Multiplying it by 16 and flooring results in an integer between -16 and 16.

If you want to have only positive values, you need to divide by 2 and add half the max value.

Eg:

 1 `(SimplexNoise.noise(x/16F, y/16F)/2F+0.5F)*16;`

Will give a value between 0 and 16.

steg90

Senior Devvie

Medals: 2

 « Reply #51 - Posted 2013-03-15 18:17:44 »

Thanks,

Got that working.

One question, how do you once you render a chunk, place another one next to it, above etc?

Regards,
Steve
HeroesGraveDev

JGO Kernel

Medals: 382
Projects: 11
Exp: 4 years

┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻

 « Reply #52 - Posted 2013-03-15 19:48:34 »

What I do with voxel engines is put every single voxel in a chunk into one VBO. Then I render it.
Other chunk just mean I need to offset the data I put in the VBO.

What you do is translate to the position of the voxel, then draw it. Meaning you have to draw again and again and again etc.

The only solution to your problem at the moment, is to translate to the coordinates of the next chunk and repeat the process.

steg90

Senior Devvie

Medals: 2

 « Reply #53 - Posted 2013-03-15 21:18:12 »

Hi,

So you put one chunk into VBO then render it, then get next chunk, put that into VBO, translate, then render it etc?...

I'm using display list atm, doesn't seem too bad...but should it be in a VBO?

Thanks again
Agro
 « Reply #54 - Posted 2013-03-15 21:23:48 »

Display list is ok for learning purposes, but you'll want to begin using VBOs for better performance.

steg90

Senior Devvie

Medals: 2

 « Reply #55 - Posted 2013-03-15 22:12:08 »

Are VBO's definitely faster than display lists for static geometry?

Just trying to find a good tutorial on drawing a cube with a VBO.

This looks good:

http://www.java-gaming.org/topics/introduction-to-vertex-arrays-and-vertex-buffer-objects-opengl/24272/view.html

Just to recap, say if I have 20 chunks, I put one chunk into VBO then render, translate, then next chunk into VBO then render etc?...

Thanks
HeroesGraveDev

JGO Kernel

Medals: 382
Projects: 11
Exp: 4 years

┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻

 « Reply #56 - Posted 2013-03-15 22:37:37 »

I just finished writing a post here with some code

steg90

Senior Devvie

Medals: 2

 « Reply #57 - Posted 2013-03-16 10:18:47 »

Thanks for that :-)

It is looking like you shouldn't use glTranslatef - so if not using a translate, do the blocks need to be in some form of local coordinate space?  Sorry for not understanding fully, just trying get my head around how you would draw a block without glTranslatef and put another block at the side of it?
Do you have to translate all the blocks first then send to the GPU?

Here is my render code for a block:

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24 `for(int chunkAmount = 0; chunkAmount < 1; ChunkManager.getInstance().GetChunkCount(); chunkAmount++)      {         Chunk c = ChunkManager.getInstance().GetChunk(chunkAmount);            for (int x = 0; x < c.CHUNK_SIZE; x++) {            for (int y = 0; y < c.CHUNK_SIZE; y++) {               for (int z = 0; z < c.CHUNK_SIZE; z++) {                  GL11.glPushMatrix();                  glTranslatef(x,y,z);   // !! Translating for each block in a chunk                  renderBlock(c.GetBlock(x,y,z));                  GL11.glPopMatrix();               }            }         }      }// render given block - just check if it is active or notprivate void renderBlock(Block b){   if(b.IsActive())   {      glCallList(voxelList);      }}`

How could the glTranslatef be removed?

Thanks again, really, really appreciate all the help.
Steve
RobinB

JGO Ninja

Medals: 45
Projects: 1
Exp: 3 years

Spacegame in progress

 « Reply #58 - Posted 2013-03-16 11:38:41 »

Hi,

So you put one chunk into VBO then render it, then get next chunk, put that into VBO, translate, then render it etc?...

I'm using display list atm, doesn't seem too bad...but should it be in a VBO?

Thanks again

VBO's are just like display lists, so you only have to store data inside it when the data changed.
Each chunk, block or object can have its own VBO.
With VBO's its possible to update only a small part of the data, what would be much faster then updating all data like with display lists.

glTranslatef(x,y,z); can be removed by making the list (or the VBO in the future) draw the whole chunk instead one block.
steg90

Senior Devvie

Medals: 2

 « Reply #59 - Posted 2013-03-16 16:28:38 »

Thanks,

So, we can just use an offset on the vertex data for a block to position it?

Also, how would I store all the blocks for a chunk into one display list?

I guess I should do this next:

1. Put chunk into a VBO (all blocks for a chunk) - add an offset to each vertex in block to position it (modify vertex position directly) instead of using glTranslatef...
2. Render chunk
3. Get next chunk, repeat 1 until all chunks done

Does this seem ok?  Then in (3) we add offset to chunk position (width of chunk)?

Thanks
Pages: 1 [2] 3 4 ... 7
 ignore  |  Print

 hadezbladez (712 views) 2018-11-16 13:46:03 hadezbladez (355 views) 2018-11-16 13:41:33 hadezbladez (699 views) 2018-11-16 13:35:35 hadezbladez (175 views) 2018-11-16 13:32:03 EgonOlsen (2368 views) 2018-06-10 19:43:48 EgonOlsen (2502 views) 2018-06-10 19:43:44 EgonOlsen (1465 views) 2018-06-10 19:43:20 DesertCoockie (2131 views) 2018-05-13 18:23:11 nelsongames (1927 views) 2018-04-24 18:15:36 nelsongames (2600 views) 2018-04-24 18:14:32
 Deployment and Packagingby mudlee2018-08-22 18:09:50Java Gaming Resourcesby gouessej2018-08-22 08:19:41Deployment and Packagingby gouessej2018-08-22 08:04:08Deployment and Packagingby gouessej2018-08-22 08:03:45Deployment and Packagingby philfrei2018-08-20 02:33:38Deployment and Packagingby philfrei2018-08-20 02:29:55Deployment and Packagingby philfrei2018-08-19 23:56:20Deployment and Packagingby philfrei2018-08-19 23:54:46
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org