So far I’ve successfully implemented frustrum culling (objects that aren’t in camera’s view have their mesh renderers disabled), but how would I tackle realtime occlusion culling, so I can avoid overdraw? My levels can change and aren’t built with Unity’s scene editor directly so for both reasons I can’t use Unity’s occlusion culling system.
The main problem is how to get if object is hidden or visible. I mean I could cast several milion rays for each pixel of screen (in case of 1920x1080 it’d be 2073600 rays) but I think it’d be too heavy on the performance, even if I’d cast one ray for every 4 pixels (518400 rays for 1920x1680).
I doubt that (if there is a solution at all for that issue) people would be able to give it to you without seeing how your game’s levels look. E.g. for minecraft you could rather easily find a lot of cubes that can not be seen because they are connected to non-transparent cubes on all 6 sides. That would give you a way to avoid a lot of overdraw based on the data you have. If you have an indoor sci-fi corridor maze there might be ways to predict that if the player is in a room he will never be able to see more than this and the adjacent rooms and so on. Those are checks that you can perform without getting performance issues and those could boost performance significantly. But if you have something like a city it gets a whole lot more complicated.
Do you really need occlusion culling then? Could you maybe limit vision range in a graceful way through fog? Use more LODs? How bad are the performance problems you are currently having?
I don’t have performance problems… yet, but I want to future-proof my game so it won’t suddenly drop bellow 1fps, because some idiot put 1 million of game objects in camera’s view (as I said frustum culling is already a thing and all objects that aren’t seen by camera have their renderers disabled) and put it on Steam Workshop with description like “Wohoho, game’s optimization is a joke, here’s an example”.
You can’t really avoid that no matter what. People will try to play AAA games on “ultra” settings on 5 year old business laptops and then complain about bad performance.