Author Topic: Voxel - Visibility  (Read 12539 times)

Offline Slydog

  • Prof. Inline
  • *****
  • Posts: 930
  • KodeSource
    • View Profile
    • KodeSource
Re: Voxel - Visibility
« Reply #15 on: 2013-Oct-02 »
Looking great!  :good:

I see now you are drawing each visible face of each cube each frame? 
Wouldn't this cause major performance issues? 
Opposite of a chunking system where you are trying to minimize the number of objects rendered.
I think before you were creating the chunk model prior to the main game loop, and only displaying that one chunk object each frame.

And, I think you can simplify your Render() function down to this code:
Code: (glbasic) [Select]
FUNCTION Render:
X_MOVEMENT -CHUNKSIZE/2-CUBESIZE/2, -CHUNKSIZE/2-CUBESIZE/2, -CHUNKSIZE/2-CUBESIZE/2
X_PUSHMATRIX
FOR x = 1 TO CHUNKSIZE
FOR y = 1 TO CHUNKSIZE
FOR z = 1 TO CHUNKSIZE
IF self.cubes[x][y][z].bin = 0 THEN CONTINUE

ALIAS bin AS self.cubes[x][y][z].bin
X_MOVEMENT x, y, z

IF bAND(bin, CUBE_TOP)    > 0 THEN X_DRAWOBJ FACE_TOP, 0 // Draw TOP
IF bAND(bin, CUBE_BOTTOM) > 0 THEN X_DRAWOBJ FACE_BOTTOM, 0 // Draw BOTTOM
IF bAND(bin, CUBE_FRONT)  > 0 THEN X_DRAWOBJ FACE_FRONT, 0 // Draw FRONT
IF bAND(bin, CUBE_BACK)   > 0 THEN X_DRAWOBJ FACE_BACK, 0 // Draw BACK
IF bAND(bin, CUBE_RIGHT)  > 0 THEN X_DRAWOBJ FACE_RIGHT, 0 // Draw RIGHT
IF bAND(bin, CUBE_LEFT)   > 0 THEN X_DRAWOBJ FACE_LEFT, 0 // Draw LEFT
   
NEXT
NEXT
NEXT
X_POPMATRIX
ENDFUNCTION

But, I love it so far!  Great screenshot.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5064
  • O Rly?
    • View Profile
Re: Voxel - Visibility
« Reply #16 on: 2013-Oct-02 »
hmm i thinks its OK if we use frustrum culling, but the big question here is: HOW! :D
 :S
« Last Edit: 2013-Oct-02 by Schranz0r »
I <3 DGArray's :D

PC:
AMD Ryzen 7 1700 @3.9GHz, 16GB HyperX Fury 3000MHz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4310
    • View Profile
    • Portfolio
Re: Voxel - Visibility
« Reply #17 on: 2013-Oct-02 »
Uau! A Borg Assimilation Cube! Great!

Some faces look flipped, is that correct? (maybe my eyes are tricking me)

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5064
  • O Rly?
    • View Profile
Re: Voxel - Visibility
« Reply #18 on: 2013-Oct-02 »
the faces are right!!!111one :D
I <3 DGArray's :D

PC:
AMD Ryzen 7 1700 @3.9GHz, 16GB HyperX Fury 3000MHz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3372
  • Integrated Brain
    • View Profile
Re: Voxel - Visibility
« Reply #19 on: 2013-Oct-02 »
Joder!!! :noggin: this it's really interesting... I think if multiply the cubes a lot of times then you can do another Zbrush , I suppose the CPU will begin to launch flames but for try it  =D =D =D

Out of jokes, but this for make nice games with another style can be a good ppoint for start... a nice thing will be explode any cube in some cube more littles...

Thanks to both for the work... about the Fustrum I leave in someplace I don't know where is, how do all fustrum, chunks, water , physics... a lot of things... I try to search again...

Thanks for the hard work!!!  :booze: :booze:

Offline Slydog

  • Prof. Inline
  • *****
  • Posts: 930
  • KodeSource
    • View Profile
    • KodeSource
Re: Voxel - Visibility
« Reply #20 on: 2013-Oct-04 »
I had fun with this for the past day or so (using my code as a base (but stole an idea or two from Schranz0r!). I found a few bugs in my original code postings - oops!).

Only exposed faces are added to the mesh, as expected.

I added an automatic chunking mechanism.
This means that a 16,16,16 map with a chunk size of 8,8,8 will generate 2x2x2 (eight) chunk meshes.
This reduced my 16x16x16 map generation from 10seconds to 1second!.
It seems the more triangles in a mesh, the longer it takes for GLBasic (or OpenGL) to generate and finalize the mesh.
Same total triangles, but as 1 mesh took 10+seconds, but as 8 different meshes, takes just over a second, total.


I included the project files as a zip, instead of posting each file (4 files) contents.
I tried commenting the main Voxel TYPE as best I could, so hopefully it is easy to follow and understand.

To Do:
- Perlin Noise Generator for MineCraft style landscapes
- UpdateVoxel(x,y,z, cubeType) -> To allow dynamic voxel editing.  Will regenerate the affected chunk(s)
- Interface to delete or add a new voxel to the map, and display the new map
- Texture Map: Use an external texture map tool to design the voxel textures, allow multiple voxel types (dirt, grass), auto map the textures to the model
« Last Edit: 2013-Oct-04 by Slydog »
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Offline Hark0

  • Prof. Inline
  • *****
  • Posts: 1020
  • Geek Developer
    • View Profile
    • LitioPixel - Desarrollo de videojuegos con GLBasic | Videogame development with GLBasic
Re: Voxel - Visibility
« Reply #21 on: 2013-Oct-05 »
Great work!

What is the limit of cube size?

http://litiopixel.blogspot.com
litiopixel.blogspot.com - Desarrollo videojuegos Indie · Pixel-Art · Retroinformática · Electrónica Development Indie Videogames · Pixel-Art · Retrocomputing · Electronic

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4310
    • View Profile
    • Portfolio
Re: Voxel - Visibility
« Reply #22 on: 2013-Oct-05 »
Gave a go, looks and moves about great. :good:

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4158
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: Voxel - Visibility
« Reply #23 on: 2013-Oct-05 »
 :good:
I came. I saw. I played.

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5064
  • O Rly?
    • View Profile
Re: Voxel - Visibility
« Reply #24 on: 2013-Oct-06 »
OK... complete rewrite of the code, rendering in realtime with OpenGL (gl.gbas)
Texturemapping added.
More improvements incomming!  :whip:

4x4x4_chunks.png is a screenshot of a "World" with 4x4x4 Chunks each chunk = 16x16x16


Source see attachment!
Anyone interested to make a Minecraftstyle game?!
« Last Edit: 2013-Oct-06 by Schranz0r »
I <3 DGArray's :D

PC:
AMD Ryzen 7 1700 @3.9GHz, 16GB HyperX Fury 3000MHz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4158
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: Voxel - Visibility
« Reply #25 on: 2013-Oct-07 »
While I'm no fan of Minecraft, I love to see things like this being done with GLB.

Keep up the excellent work chaps :)
I came. I saw. I played.

Offline Hark0

  • Prof. Inline
  • *****
  • Posts: 1020
  • Geek Developer
    • View Profile
    • LitioPixel - Desarrollo de videojuegos con GLBasic | Videogame development with GLBasic
Re: Voxel - Visibility
« Reply #26 on: 2013-Oct-07 »
I'm thinking in "voxatron"....  :P
http://litiopixel.blogspot.com
litiopixel.blogspot.com - Desarrollo videojuegos Indie · Pixel-Art · Retroinformática · Electrónica Development Indie Videogames · Pixel-Art · Retrocomputing · Electronic

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5064
  • O Rly?
    • View Profile
Re: Voxel - Visibility
« Reply #27 on: 2013-Oct-07 »
I'm thinking in "voxatron"....  :P

 :good:
I <3 DGArray's :D

PC:
AMD Ryzen 7 1700 @3.9GHz, 16GB HyperX Fury 3000MHz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3372
  • Integrated Brain
    • View Profile
Re: Voxel - Visibility
« Reply #28 on: 2013-Oct-07 »
Like Erico says this things are absolutely awesome... again I do the same question, this it's the same techique for do a Zbrush or a Voxel Modeler... I think in a Voxel Modeler you using millions at the same time, this it's possible in GLbasic, I think Using OpenGl, can't be too much problem?¿...

Offline Slydog

  • Prof. Inline
  • *****
  • Posts: 930
  • KodeSource
    • View Profile
    • KodeSource
Re: Voxel - Visibility
« Reply #29 on: 2013-Oct-08 »
I was going to stop updating this, as I have no immediate use for it, but doing this is too much fun.

Here's my latest update, which includes a Perlin Noise generator, to create a MineCraft-ish landscape.
I use this to create a height map: anything below is dirt, anything above is air.
(MineCraft's algorithm is much more complex, with random caves, with minerals, etc).

It is much faster this way than completely random dirt/air cubes, as there are a lot less exposed faces.
I simply used a random shade of green for the top (grass), and a random brown for the dirt sides.

The main line that gets the perlin height is this:
Code: (glbasic) [Select]
//x#, y#, maxHeight#, frequency#, amplitude#, persistance#, octaves%
height = noise.GetRandomHeight(x,z, 1, 0.1, 1, 0.15, 3)

I don't know much about the specific perlin input values, but I found that frequency seems to make it spaced out more, and lower looks better.

Here's the site I derived this Perlin Noise TYPE from:
http://ploobs.com.br/?p=1742

I attached a screeny and the source project.  Have fun.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]