Infinite Terrain And Rendering

So i have been trying to make infinite voxel terrain is there a way that i can make it so if a block is underground or is surrounded by other blocks it will not render to reduce lag.
Or if there is a block on the side of the hill and a face is facing towards other blocks so they wont get rendered.

Is there an efficient way to do this?

There is a way but your studio might crash I dont have a script just telling you.

Do you know the way to do it by any chance?

I’m not sure how to do rendering techniques on terrain but you can try using StreamingEnabled?

i already have streamingEnabled i am trying to implement so faces facing other blocks that side wont get rendered

You could use tables to store chunks instead of parts, and then make it so every time a chunk is loaded/updated it recalculates the faces, so if a block atleast 1 airblock on one of it’s sides then it should render, if it doesn’t then it won’t render

1 Like

Is there an efficient way to do this?

Well I’m not sure but what I do is store tables inside tables, so if your chunk is 16x16x16 then it would be a table that has 16 other tables (each table is a layer on the Y Axis), and these have another 16 tables (These are on the X axis), and then they just have block id’s (Z Axis), so 0 = air, 1 = dirt, etc
Now you just get a block and see it’s surroundings, for example block 4,7,3 of a chunk (X,Y,Z format)
You now should check all blocks surrounding it, up side is 4,8,3

For optimization I’d say you only calculate these stuff when a chunk is loaded for the first time and cache that then only recalculate these when a chunk is updated and only for the blocks surrounding the updated block, so you don’t recaluclate it for the whole chunk, also make sure to check for neighboring chunks, so if a block is on the border of a chunk it will also check the block at the side of it even if it was on another chunk

Do you possibly have some code to check if the block is surrounded?

Nope, you gotta make it yourself, you could use my method or your own

When initially rendering voxels, you could check if a voxel is completely surrounded on all sides. If so, no need to render. You would also have to implement some kind of ‘voxel update’ which would update the voxels surrounding the one modified (if you need terrain modification).

1 Like

Yeah i am trying to do that but i cant really find a way to do that im having trouble writing the actual code i have been scratching my head for a few days trying to find a solution but i cant get a working code.

Do you by any chance know a code/method i can check if the block is surrounded

Unfortunately I can’t really help you with that part. I would suggest making an API to make it easier to access voxels at certain positions.