How to hide sides of blocks that cannot be seen?

Blitz3D Forums/Blitz3D Programming/How to hide sides of blocks that cannot be seen?

Liimbix(Posted 2015) [#1]
Hi all, as some of you know, I'm working on and expanding my voxel engine, and I would really like to work on optimizations so that it can run better before I add new features. My computer is not the beefiest, so I want to get the best performance possible. When it creates the world, as of now a 20*20 flat world, (so pretty small), it gives me about 30-32 FPS when all blocks are rendered in the camera. When I'm looking away from the blocks, I get about 56-61 FPS. I have heard about a method that programmers use, and that Notch used when he made Minecraft, was to hide the sides of blocks that are against another block. I'm not completely sure how to go about this. I have thought about getting the amount of triangles on the surface of these cubes and change one side to 0% transparency, but it seems that all of a cube's sides are one side, so I can't single out a certain side and just hide one of them. The next idea was to create 6 different, very thin rectangles, and attach them all as one cube, and hide the non-seen ones as necessary. But then I thought of, how would I redraw a texture on a missing side when a block is taken away, and when I place a block, how would I go about removing a side of a block that was already there. I'm sorry if I ranted, but I'm just looking for a method to hide one or more sides of a single cube, so that less tris are rendered. Thanks community (:


RemiD(Posted 2015) [#2]
One way to decrease render time would be to merge all cubes which are in the same area (10x10 area for example) in the same mesh in the same surface surface.

So you could keep a list of the cubes (with their properties) in order to be able to modify the cubes of the area, but when the world is not modified, the world would be only a few meshes with a few surfaces.

And when you want to modify the world, this would allow you to modify only some areas (the cubes of these areas) and consequently minimize the time it takes to build the new surface of each area.

Also to decrease the number of tris to render per area, you could separate each area in 6 meshes with 6 surfaces instead of 1 surface, one surface for each side of the cubes, (one surface for the front sides, one surface for the back sides, one surface for the left sides, one surface for the right sides, one surface for the top sides, one surface for the bottom sides)
And depending on in which direction the camera looks, calculate which sides are visible, and only display the meshes/surfaces with the visible sides.
(not sure if this would decrease or increase rendertime since you would reduce the number of triangles per area but you would increase the number of surfaces per area (up to 3 surfaces to display per area)

And to render a big world with many areas, maybe render the far away areas only each xms and keep this render in an image, and render the near areas each frame and draw this over the image of the faraway render. If your character/vehicle cannot move fast, this would be a good approach i think.

That's what i would try...


Liimbix(Posted 2015) [#3]
So, if I merge these cubes into one big one, would I just create a 10*10 cube, instead of littler ones? Or is there a command to merge multiple entities? Also, If I make one big cube instead of multiple little ones, how would I remove a chunk from that bigger block, whenever I break a block? Thanks so much for your help (:


RemiD(Posted 2015) [#4]
Also i would limit the number of cubes on Y

Let's say that an area is 10x10x10 = 1000cubes, this can be one surface of 12000tris or 6 surfaces of 2000tris (one for each side)
So for a zone of 10x10 areas (only 10units on Y) you would have either 100 surfaces of 12000tris or 600surfaces of 2000tris, knowing that not all surfaces would be visible and that you can render the far away surfaces only each xms and keep the image of the render, and draw the image of the render of the near surfaces each loop.

Also i suppose that you could calculate which cubes are the "surface" cubes (where player can walk on or which player can interact with) and only consider these cubes when building the area so that the numbers of cubes per area would be reduced.

Maybe you could have only one mesh and a few surfaces for a 100x100 area if you only consider the cubes which are on the surface) 100x100x12 = 120000 tris... doable...
And if you create one surface for each side, you would have 6 surfaces of 20000tris, again doable...

To add a cube or remove a cube from an area, you would have to first update the list of cubes of the concerned area, and then rebuild the surface of the area depending on the remaining cubes in the list.

Read the doc :
http://www.blitzbasic.com/b3ddocs/command_list_3d_cat.php?show=Mesh
http://www.blitzbasic.com/b3ddocs/command_list_3d_cat.php?show=Surface

An example that may help :
http://www.blitzbasic.com/Community/posts.php?topic=102895 (#1)

Maybe it is not the best approach, i don't know, i have never tried to do this, but the idea is to limit the number of surfaces and of vertices triangles per surface...