Only rendering objects on screen is very laggy

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.

https://gyazo.com/6610115fcf0c1ffcd2e3827e4c653536

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.

2 Likes

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.

2 Likes

Well streaming enabled is set to true, but the radius is 64 studs, which isn’t helpful in this case unfortunately

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

1 Like

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 :sweat_smile:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.