LWJGL - Voxel Engine

This looks very nice but forgive me I just quickly read most the posts and was wondering what makes this different from minecraft? Also do you have a way to save and load maps yet?

No, it doesn’t save or load maps.

Also, I am not trying to create something different. I am justing trying to learn new stuff.

To clarify - you only hold the chunks you can see in memory?

@TH3Fatal - we are all doing these sort of ‘minecraft’ clones for learning purposes :slight_smile:

I save the chunks which are really close to me temporary to a list, in which I do all my checks. Collision, block picking, etc.

So am I well the voxel aspect because I have an idea for a small game that can use voxels instead of diving in the deep end of java game development

@Pauler - ok, and do you only store these chunks in memory? What I’m saying is, I have an ArrayList which stores chunks, at the moment it stores all the chunks in my game, which, obviously is a big bottle neck and this isn’t how to do it. I believe you only add chunks to memory when you can see them and remove the ones you can’t?

For instance, if you have 64x64 chunks, this in my game is (64x4096 blocks) x (64x4096 blocks) = 524288 , now unless you got a decent graphics card with a good deal of memory, memory will run out. My gfx card is an Intel 3000 HD, so not very good, uses shared memory I believe??

What I am getting at the moment in my game is, say with 16x16 chunks, runs fine, but once all chunks have been seen, the game slows down and CPU usage goes to 64%…If I then reset my camera position back to 0,0,0 the CPU usage drops back to 19% - any ideas what this could be?!

Thanks

Improved chunk management - dynamic loading and unloading.
Face culling,
Block culling,
Chunk culling,
Simple block picking,


https://www.youtube.com/watch?v=9Bo9Au2ph4I

Thanks,
Steve

Hashing will be significantly slower than a dynamic array.

Why you use math abs? Multiplying real number with itself make it positive always. Also you don’t need sqrt when comparing distances.


			int deltax=(int)x - c.getX() * 32;
			int deltaz=(int)z - c.getZ() * 32;
			int deltay = 1;
			int distance2=deltax*deltax+deltay*deltay+deltaz*deltaz;
	                int radius2 = (Chunk.CHUNK_SIZE * 8)
                        radius2*=radius2;//precalculate this
			if(distance2 < radius2)
			{
				c.render();
			}


@pauler and @steg.

Both projects looking great. Hoping to get some time to tackle a very large map…Been researching threads to help with getting chunks ready in the background.

I need to do some optimising still first tho!

Your both inspiring me to do more as your projects look great. :slight_smile:

@Pitbuller - Not using that formula anymore, didn’t seem to work for me. Thanks anyway.

@Vermeer - Your project(s) inspire me :wink: I was thinking of putting a thread in for the dynamic loading - basically run a thread, check if chunk is in view or not, if not, remove from memory (active chunklist array).

@Roquen - dynamic array - thus back to an ArrayList? This would only be faster if used object indexes - thus say object 10 would be index 10, will have a think about this as need fast look ups.

Just added frustum culling but finding using the distance formula better…

As anybody else implemented frustum culling in their voxel project and how does it fair over
doing a distance check?

I think I will use frustum culling for other objects in my project, not for the voxels, will stick with distance formula.

8QPOuDn-ZXA

Added save and load.

PS: Camtasia destroyed the fps.

Looks awesome so fare. Nice to see save and loading is working for you :slight_smile: I just got save and loading done for me voxel game thanks to Vermeer. 8)

Frustum culling is dead cheap. Distance formula can’t be faster than it if you use it right. Draw call is at least magnitude slower than any sane bounding box frustum culling method that you can ever write.
For iOs project I frustum cull every particle as optimization.(Sphere frustum test. Even this is better than distance checkl) This was faster than rendering them all with one draw call even before any simd optimizions.

I’m using mark morleys frustum cull, maybe I got it wrong somewhere?

Code: http://pastebin.java-gaming.org/83b53604950

To use the cubeInFrustum, it states to supply the centre of the cube and half the size which is what I’m doing in my code. Must admit, I don’t think it is working as it should though, maybe I’ve got the x,z and size wrong - I’m taking it that X is half the width and Z half the depth of the chunk - my chunks being 16 blocks wide and 16 blocks depth, you can see I just times the x by 8 and z by 8.

The thing about frustum culling is that you should need to check a very small percentage of regions. At a logical top level you’re checking against 5 gradient space (one less since far and near are offsets), quickly planes will drop away as a child region is either totally inside or outside and you’re finally left with none to check.

This is my first open gl project so I also lack some basic knowledge.

Can some one help me to turn the quads to triangles? It seems a bit complicated as far as I call glbegin and glend only once.

This my code in case you are interested:



public void renderFace(int side) {
		
		switch(side) {
		
		case 1: //bot
			
			GL11.glTexCoord2f(spriteX, spriteY + small);	GL11.glVertex3f(x1, y1, z1);
			GL11.glTexCoord2f(spriteX, spriteY);	GL11.glVertex3f(x1 + width, y1, z1);
			GL11.glTexCoord2f(spriteX + small, spriteY);	GL11.glVertex3f(x1 + width, y1, z1 + length);
			GL11.glTexCoord2f(spriteX + small, spriteY + small);	GL11.glVertex3f(x1, y1, z1 + length);
			break;
		
		case 2: //top
			
			GL11.glTexCoord2f(spriteX, spriteY + small);	GL11.glVertex3f(x1, y1 + height, z1);
			GL11.glTexCoord2f(spriteX, spriteY);	GL11.glVertex3f(x1, y1 + height, z1 + length);
			GL11.glTexCoord2f(spriteX + small, spriteY);	GL11.glVertex3f(x1 + width, y1 + height, z1 + length);
			GL11.glTexCoord2f(spriteX + small, spriteY + small);	GL11.glVertex3f(x1 + width, y1 + height, z1);
			break;
			
		case 3: //back
			GL11.glTexCoord2f(spriteX + small, spriteY + small);	GL11.glVertex3f(x1, y1, z1 + length);
			GL11.glTexCoord2f(spriteX, spriteY + small);	GL11.glVertex3f(x1 + width, y1, z1 + length);
			GL11.glTexCoord2f(spriteX, spriteY);	GL11.glVertex3f(x1 + width, y1 + height, z1 + length);
			GL11.glTexCoord2f(spriteX + small, spriteY);	GL11.glVertex3f(x1 , y1 + height, z1 + length);
			break;
			
		case 4: //front
			
			GL11.glTexCoord2f(spriteX, spriteY + small);	GL11.glVertex3f(x1, y1, z1);
			GL11.glTexCoord2f(spriteX, spriteY);	GL11.glVertex3f(x1, y1 + height, z1);
			GL11.glTexCoord2f(spriteX + small, spriteY);	GL11.glVertex3f(x1 + width, y1 + height, z1);
			GL11.glTexCoord2f(spriteX + small, spriteY + small);	GL11.glVertex3f(x1 + width, y1, z1);	
			break;
			
		case 5: //left
			GL11.glTexCoord2f(spriteX + small, spriteY + small);	GL11.glVertex3f(x1, y1, z1);
			GL11.glTexCoord2f(spriteX, spriteY + small);	GL11.glVertex3f(x1, y1, z1 + length);
			GL11.glTexCoord2f(spriteX, spriteY);	GL11.glVertex3f(x1, y1 + height, z1 + length);
			GL11.glTexCoord2f(spriteX + small, spriteY);	GL11.glVertex3f(x1, y1 + height, z1);
			break;
		
		case 6:
			GL11.glTexCoord2f(spriteX, spriteY + small);	GL11.glVertex3f(x1 + width, y1, z1);
			GL11.glTexCoord2f(spriteX, spriteY);	GL11.glVertex3f(x1 + width, y1 + height, z1);
			GL11.glTexCoord2f(spriteX + small, spriteY);	GL11.glVertex3f(x1 + width, y1 + height, z1 + length);
			GL11.glTexCoord2f(spriteX + small, spriteY + small);	GL11.glVertex3f(x1 + width, y1, z1 + length);
			break;
			
		}
		
	}


up.

Are you talking about a 3D triangle or a 2D triangle?