Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
games submitted by our members
Games in WIP (500)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2] 3 4 ... 7
  ignore  |  Print  
  Voxel - a start  (Read 18395 times)
0 Members and 1 Guest are viewing this topic.
Offline steg90

Senior Member


Medals: 1



« Reply #30 - Posted 2013-03-11 00: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...
Offline opiop65

JGO Kernel


Medals: 124
Projects: 7
Exp: 3 years


Team Alluminum


« Reply #31 - Posted 2013-03-11 02: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).

Offline steg90

Senior Member


Medals: 1



« Reply #32 - Posted 2013-03-11 09: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
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online Riven
« League of Dukes »

JGO Overlord


Medals: 605
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #33 - Posted 2013-03-11 10: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
Offline steg90

Senior Member


Medals: 1



« Reply #34 - Posted 2013-03-11 20: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
Offline Agro
« Reply #35 - Posted 2013-03-11 20:39:52 »

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

Offline steg90

Senior Member


Medals: 1



« Reply #36 - Posted 2013-03-11 20: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
 
Offline steg90

Senior Member


Medals: 1



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

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

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.

https://sites.google.com/site/voxbygame/

Thanks
Offline Mike

JGO Wizard


Medals: 69
Projects: 2
Exp: 5 years


Java guru wanabee


« Reply #38 - Posted 2013-03-11 23: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 Smiley
State of Fortune | Discussion thread @ JGO
Offline opiop65

JGO Kernel


Medals: 124
Projects: 7
Exp: 3 years


Team Alluminum


« Reply #39 - Posted 2013-03-11 23: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?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline steg90

Senior Member


Medals: 1



« Reply #40 - Posted 2013-03-12 09: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
Offline Mike

JGO Wizard


Medals: 69
Projects: 2
Exp: 5 years


Java guru wanabee


« Reply #41 - Posted 2013-03-12 09: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 Smiley 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 Smiley
State of Fortune | Discussion thread @ JGO
Offline steg90

Senior Member


Medals: 1



« Reply #42 - Posted 2013-03-12 11: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
Offline Mike

JGO Wizard


Medals: 69
Projects: 2
Exp: 5 years


Java guru wanabee


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

Simplex is the easiest way to go while still getting a nice result Smiley 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 Smiley
State of Fortune | Discussion thread @ JGO
Offline orogamo

Senior Member


Medals: 5
Projects: 1



« Reply #44 - Posted 2013-03-12 13:52:33 »

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

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

Senior Member


Medals: 1



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

Thanks guys,

Will take a look at the code  Grin

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?

Thanks again, really appreciate your advice.

Steve
Offline opiop65

JGO Kernel


Medals: 124
Projects: 7
Exp: 3 years


Team Alluminum


« Reply #46 - Posted 2013-03-13 21:12:39 »

Thanks guys,

Will take a look at the code  Grin

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?

Thanks again, really appreciate your advice.

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?

Offline steg90

Senior Member


Medals: 1



« Reply #47 - Posted 2013-03-13 21: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
Offline Mike

JGO Wizard


Medals: 69
Projects: 2
Exp: 5 years


Java guru wanabee


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

Hi Mike,

Everyone is Mike? Smiley

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 Smiley

Mike

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

Senior Member


Medals: 1



« Reply #49 - Posted 2013-03-13 22: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
Offline HeroesGraveDev

JGO Kernel


Medals: 212
Projects: 11
Exp: 2 years


If it wasn't Awesome, it wasn't me.


« Reply #50 - Posted 2013-03-14 03: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.

Offline steg90

Senior Member


Medals: 1



« Reply #51 - Posted 2013-03-15 19: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
Offline HeroesGraveDev

JGO Kernel


Medals: 212
Projects: 11
Exp: 2 years


If it wasn't Awesome, it wasn't me.


« Reply #52 - Posted 2013-03-15 20: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.

Offline steg90

Senior Member


Medals: 1



« Reply #53 - Posted 2013-03-15 22: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
Offline Agro
« Reply #54 - Posted 2013-03-15 22:23:48 »

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

Offline steg90

Senior Member


Medals: 1



« Reply #55 - Posted 2013-03-15 23: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
Offline HeroesGraveDev

JGO Kernel


Medals: 212
Projects: 11
Exp: 2 years


If it wasn't Awesome, it wasn't me.


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

I just finished writing a post here with some code

Offline steg90

Senior Member


Medals: 1



« Reply #57 - Posted 2013-03-16 11: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 not
private void renderBlock(Block b)
{
   if(b.IsActive())
   {
      glCallList(voxelList);  
   }
}


How could the glTranslatef be removed?

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

JGO Knight


Medals: 37
Projects: 1
Exp: 3 years


Spacegame in progress


« Reply #58 - Posted 2013-03-16 12: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.
Offline steg90

Senior Member


Medals: 1



« Reply #59 - Posted 2013-03-16 17: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  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (53 views)
2014-04-15 18:08:23

BurntPizza (51 views)
2014-04-15 03:46:01

UprightPath (65 views)
2014-04-14 17:39:50

UprightPath (48 views)
2014-04-14 17:35:47

Porlus (65 views)
2014-04-14 15:48:38

tom_mai78101 (89 views)
2014-04-10 04:04:31

BurntPizza (149 views)
2014-04-08 23:06:04

tom_mai78101 (245 views)
2014-04-05 13:34:39

trollwarrior1 (203 views)
2014-04-04 12:06:45

CJLetsGame (210 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!