GLBasic forum

Main forum => GLBasic - en => Topic started by: Schranz0r on 2010-Sep-28

Title: Minecraft Clone
Post by: Schranz0r on 2010-Sep-28
hi buddys
Want to write a "simple" Minecraft clone, called "Worldcraft" (working title).
I start a small test to see how fast GLBasic is on 3D without any tweeks in code :D
Just a flat 256x1x256...

if i look on the ground i have 30 FPS if i look far away it drops to 8-9 FPS !
Anyone knows a trick to increse the FPS/ Render FASTER!?

Code see attachment

[attachment deleted by admin]
Title: Re: Minecraft Clone
Post by: Slydog on 2010-Sep-28
That's 256 x 256 cubes arranged as a plane!
That's 65,000 cubes * 12 polys is over 780,000 polys!

Does GLBasic have built in frustum culling?

I see you used Front Face culling, which should save you half of the poly renders.

Try moving your X_SETTEXTURE to outside of your loop.
Ideally you will use the same texture image that contains all of your textures, and assigning the UVs manually.

Then if this is still too slow, you may need to get into creating your cubes by hand in code, but combining multiple cubes into one object, say a 4x4x1 cube object and dynamically adding / removing polys as needed.
[Edit]
What I mean is that each 4x4x1 area will be a separate 3d model dynamically created, then only changes need to be done on the edited block of cubes.  You may be able to increase this quite a bit, like up to say 32x32x1.  Don't calculate each block of cubes each frame.

Ideally, you only NEED (256 + 1) vertices by (256 + 1) vertices * 2 to describe what you see, as the other faces are blocked by the sides of the other cubes.  So try finding patterns maybe to dynamically create only the polys needed, but this will get very complicated and may be slow to calculate.

Also, maybe setting a limit on how far you can see could help, using the Far Clip value in X_MAKE3D.

But wow, I can still predict it being slow.  Would love to see how far you can take this!
Is iPhone out of the question? ha!

[Edit]
What's the fastest shader out there?  That meets your minimum requirements that is.  What shader does GLBasic use by default, may be room for improvement.
Title: Re: Minecraft Clone
Post by: Scott_AW on 2010-Sep-29
Actually I've been working with similar stuff, if you use a ray casting system that might work.

I've only worked with a basic single level ray cast, it scans out a single floor to detect if floor/walls are present.

Heres a lastest demo (http://gamejolt.com/open-source/games/rpg/the-crawl-3d-rpg-maker/2479/)

Thats made with Evaldraw which has voxel rendering, but the map is composed of tiles.

I've started working on a GLBasic version, the raycasting bit at least.


And have been working on a way of rendering ortho square based voxels but it still needs some work.


Raycaster engine is based off of Ken Silverman's ray casting algorithm, although the tile data storage method I came up with.  Both projects are open source so I can share some code if you need anything.
Title: Re: Minecraft Clone
Post by: matchy on 2010-Sep-29
Here's my mc clone v1: http://www.glbasic.com/forum/index.php?action=dlattach;topic=5058.0;attach=2368

Whilst looking around I found this...16-bit ALU in minecraft:
http://www.youtube.com/watch?v=LGkkyKZVzug
Title: Re: Minecraft Clone
Post by: Slydog on 2010-Sep-29
Hmm, now I think that Scott_AW might be on to something.

Ray casting is fast, but going beyond one level may be very difficult.
Damn, because the concept is relatively easy, and involves no 3D engine at all.

But, check this link, it's Ken Silverman's Voxlap page:
http://www.advsys.net/ken/voxlap.htm (http://www.advsys.net/ken/voxlap.htm)

Look at his Cave.exe screenshot, looks very much like Minecraft.
Each pixel would be a cube from Minecraft.
Except, Cave.exe uses solid colours for the pixels, and you would want to texture map those pixels instead.
But, it would be much faster and enable you to draw much larger worlds.
Title: Re: Minecraft Clone
Post by: Schranz0r on 2010-Sep-29
Minecraft is 3D :D
No raycast or voxel!


It must give a trick to render that bunch of cubes fast...  :'(
Title: Re: Minecraft Clone
Post by: Schranz0r on 2010-Sep-29
Quote from: Schranz0r on 2010-Sep-29
Minecraft is 3D :D
No raycast or voxel!


It must give a trick to render that bunch of cubes fast...  :'(

OK a saw a indev video of Minecraft and on the top its says  for example: 7 chunks updatet!
The trick is to reduce the objects into chunks and maybe 56x56x56 if the far enough...
Anyone knows how to make this?!
current i have no idea  ;/
Title: Re: Minecraft Clone
Post by: Slydog on 2010-Sep-29
Right, that's what I thought they did, as I suggested in my first post (my first [EDIT]).

So, if your world is 500x500x500, and your chunks are 50x50x50, it would take 10x10x10 chunks to fill your world.
Most chunks would be empty as they would represent the air and ground/cave data that has no exposed sides.
You would dynamically create each chunk (using X_OBJADDVERTEX) by adding faces that are visible on any side, not the entire cube.
So for example if you had a hole in a wall that exposes a face/side of the next chunk, but that face is the only visible face on that chunk, that chunk would only need that one face (2 polys, 4 vertices).

If you had a 50x50x1 wall or floor exposed (completely flat in this example), you would need to create a dynamic 3d model that has 51x51x2 vertices.  You need the sub-vertices (even though they don't extrude/indent) to define the UV index into your texture map for each cube face.

[Edit]
My bad, you would need more vertices because the sub-vertices can't be shared between neighboring cube faces since they refer to different locations in the UV map.  Each cube would need its own 4 vertices (one for each corner), so you would need 100x100x2 I think.

Each chunk in the world is created at the start of the level, and you only have to modify (or recreate) the current chunk that has just been edited.

You still maintain a 500x500x500 array to hold the world cube data, and use this to create your dynamic chunks.
You would calculate the world array locations for each chunk, and loop through the world array looking for exposed faces, then add those faces to your new chunk model. 

Checking for exposed faces should be easy, just check its immediate neighbor in the world array, if it's a solid cube type (not air or transparent), then ignore it.
Title: Re: Minecraft Clone
Post by: Slydog on 2010-Sep-29
If GLBasic uses frustum culling, then only the chunks in the player's view would be drawn.
If not, you may need to create your own frustum culling algorithm so you only draw the required chunks.
Title: Re: Minecraft Clone
Post by: Leginus on 2010-Sep-29
Could you not introduce some 3d fog to limit your viewing distance?
Title: Re: Minecraft Clone
Post by: Schranz0r on 2010-Sep-29
No, we want to see far!
Fog comes on more then 512? :)
Title: Re: Minecraft Clone
Post by: Kitty Hello on 2010-Sep-30
you can render the 6 viewing sides of such a huge cube to an offscreen sprite, and draw a big cube using that sprite for far-away-objects then.
Title: Re: Minecraft Clone
Post by: Schranz0r on 2010-Sep-30
hmm... and if i walk around the perspective fails?

Gernot, how can i add a object to a another one?

Title: Re: Minecraft Clone
Post by: Kitty Hello on 2010-Sep-30
you can't merge objects.
Title: Re: Minecraft Clone
Post by: Scott_AW on 2010-Sep-30
What about using openGL commands directly?
Title: Re: Minecraft Clone
Post by: Schranz0r on 2010-Sep-30
Only way to "marge" objects is to read the vertices of each cube in a chunk and redraw it as "chunkobject" but the texture are now the problem..?
Title: Re: Minecraft Clone
Post by: Slydog on 2010-Sep-30
If they share the same texture, then no problem.
Just use the 'X_GETFACE' command, and it includes the texture coordinates.
But, if the models use two different textures, you could merge both textures into one sprite, offsetting one of them.  Then using 'X_GETFACE', apply that offset to the texture coordinates.

But, it may be way more simpler to just remember the vertice data for each model in separate arrays, then combining the two vertice data arrays, then recreate a new model (using 'X_OBJADDVERTEX').  That's how I'm doing it for a 3D multi-level maze game I'm working on, created randomly, and just adding on the new block one at a time.
Title: Re: Minecraft Clone
Post by: Schranz0r on 2010-Sep-30
To read the vertices and then use "X_OBJADDVERTEX" is what im saying with:

Quote from: myself ;)read the vertices of each cube in a chunk and redraw it as "chunkobject"
Title: Re: Minecraft Clone
Post by: Kitty Hello on 2010-Oct-01
uhm. You have an array of cubes - just rebuild a cube-chunk.
Title: Re: Minecraft Clone
Post by: Hatonastick on 2010-Oct-02
I was curious as I've never heard of this game so I looked it up.  Very... Um... Different isn't it? :)  I love the look of it.  Been watching a lot of the vids.  Seems to be a clever sandbox world -- reminds me a bit of a clever Rogue-like, something like Dwarf Fortress, but in 3D combined with a Lego set.  Quite impressive in many ways.

My favourite video of something made in Minecraft so far (except maybe the bit right near the end :)):

Title: Re: Minecraft Clone
Post by: matchy on 2010-Oct-02
Yes, I've read this was compared to Dwarf Fortress, which is another popular game I need to try out.

In an effort to replicate the world, my first app, I had all the blocks as objects but we now know that will slow down in world distance. I've started a second version which relies on the "CHUNK" (segment) theory I guess. That is a 3D tiled objects of 16x16x16 cubed area with only the sided that are on the outside created. This object segment is again tiled in the world. When a block of the segment is removed, the segment is object is recreated. Any more, it is too slow to recreate. Looks good so far and I am able to achieve great distances with smooth fps (not iPad tested yet for v2).
Title: Re: Minecraft Clone
Post by: Schranz0r on 2010-Oct-04
I can't create chunks... I'm to stupid for that! :)
Has anyone create a world now, with chunks?  ::)
Title: Re: Minecraft Clone
Post by: matchy on 2010-Oct-11
Check out this new video and notice the background distance "chunk" update!

Title: Re: Minecraft Clone
Post by: Schranz0r on 2011-Jan-25
anyone got the trick?
I realy realy want to know how it works... i'm maybe to stupid, but here we have some good brains in this Forum :D
Title: Re: Minecraft Clone
Post by: Albert on 2011-Jan-26
50x50x50 http://sol.gfxile.net/cubes.html
Title: Re: Minecraft Clone
Post by: Hatonastick on 2011-Jan-26
You can have my brain if you like but I doubt it will help much as it is old and shriveled -- hang on while I go get a hacksaw and a jar.

Seriously though please keep at it.  I'd love to see something like this done with GLB.