GML How to use 'Occlusion Culling' in 2D graphics?

R

RoddKOREA

Guest
I mean
I saw a tech about 'Occlusion Culling' other name is 'Frustum Culling'.
I wanna use it in my 2D graphics project.
and how can I?
 

Bentley

Member
It's funny you mention that. Was just working on silhouettes.

Wait, by "occlusion culling" do you mean reducing instances processed? If so, nevermind; if yes, I'll post/explain the code.
 
R

RoddKOREA

Guest
Yes, that's it!
I wanna do reducing instances processed outside the camera
 

obscene

Member
Usually you do it in an alarm every 30 or 60 frames. If you have different objects you want to check, you might use 2 alarms and stagger them. To further optimize this you might consider only doing it if the camera has moved since the last time it was done.
 
R

RoddKOREA

Guest
I save the data of objects into ds_list. (its id, coordinates)
and every step, I checked the deactivated objects were in the camera.
if the deactivated object is in the camera, I activate it, and exclude the data of it from ds_list.
I got a better, now.
but every step is dangerous maybe.
I've got try your idea every 30 or 60 frames. (or more faster)
 

Joe Ellis

Member
If your putting the coordinates of each instance into a ds_list, that will be a hell of alot slower than having an "if pos is outside view" in each instance, cus your still checking that, but first putting the coordinates into a list, so its faster to not put them into a list and check them straight away.
A good way would be to make triggers, like invisible objects when the player touches them, that activate certain instances, so if the player enters the next area it'll activate the instances for that area and deactivate the ones in the previous area
 
R

RoddKOREA

Guest
If your putting the coordinates of each instance into a ds_list, that will be a hell of alot slower than having an "if pos is outside view" in each instance, cus your still checking that, but first putting the coordinates into a list, so its faster to not put them into a list and check them straight away.
A good way would be to make triggers, like invisible objects when the player touches them, that activate certain instances, so if the player enters the next area it'll activate the instances for that area and deactivate the ones in the previous area
I don't know wat you mean.
I mean, there are many tiles in my game. Like terraria, starbound, ..
but it's too much. so i wonder how to deactive and active more than 20000 tile objects...
 

rIKmAN

Member
I don't know wat you mean.
I mean, there are many tiles in my game. Like terraria, starbound, ..
but it's too much. so i wonder how to deactive and active more than 20000 tile objects...
Tiles are automatically culled by the engine when outside the view
 

Joe Ellis

Member
They normally use a chunking system for that, each chunk being a grid of tiles or blocks, and there is a bigger grid of chunks, then when the player enters a new chunk, it deactivates ones that are n grid spaces away from that chunk, and activates the new ones.
But they will have implemented a custom tile handling system to work with the chunks, I don't think they would activate and deactivate thousands of tiles, just the few chunks. So you'd have to make up some custom system like this, I think. But it won't be that hard once you know all the things you need to do it. There is this thread with a good tutorial by gmwolf here: https://forum.yoyogames.com/index.php?threads/open-world-chunk-system.6035/
and theres alot of stuff online about it.
The thing which makes chunking much faster is the lack of having to activate and deactivate every object in each chunk. Instead, the engine simply draws all the objects in the active chunks, and activating and deactivating chunks is alot faster cus there are alot less of those in the world
 
Last edited:
Top