I’m currently working on a voxel terrain system similar to Minecraft, and I decided that before continuing I should improve performance.
In order to improve performance I’m trying to only show objects visible within the players FOV by setting their transparency, but its not helping at all. You can clearly see that objects are missing on the corner of the screen.
local Camera = workspace.CurrentCamera
local RunService = game:GetService("RunService")
local BlockFolder = workspace.Blocks
game:GetService("RunService").RenderStepped:Connect(function()
for _,Part in pairs(BlockFolder:GetChildren()) do
if Part:IsA("Part") then
local _, VisibleToPlayer = Camera:WorldToScreenPoint(Part.Position)
if VisibleToPlayer then
Part.Transparency = 0
else
Part.Transparency = 1
end
end
end
end)
I’m 90% sure Roblox already implements frustum culling, which is effectively what you’re doing. The reason it clips off at the edges of the screen is that the corner of the block is on screen, but the center is not.
Well on that case what should I do to improve performance? I was also planning on shooting a raycast from each part to the character to make sure its not hidden by another part, but I imagine firing all those raycasts from each part every frame would be pretty intensive.
I would probably just do a chunk system like what Minecraft does, don’t render the chunks that are far away. Also, you could only render the parts that are visible by “flood filling” around air/transparent blocks.
Have you considered using StreamingEnabled? It doesn’t accomplish exactly what your suggesting here, but it does do a similar effect where it only streams Instances onto the players screen in a certain stud radius.
Well in that case I suggest go with @Pokemoncraft5290’s idea and create a custom chunk loader system like Minecraft so you are able to set the minimum streaming stud radius to whichever value you want
But I have to add that depending how this is approached, this could result in an extremely unoptimized system. Roblox added StreamingEnabled for this exact reason. Just some food for thought