1. Hey! Guest! The 34th GMC Jam will take place between August 22nd, 12:00 UTC (Thursday noon) and August 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

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

Discussion in 'Programming' started by RoddKOREA, Aug 10, 2019.

  1. RoddKOREA

    RoddKOREA Member

    Joined:
    Jun 13, 2019
    Posts:
    6
    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?
     
  2. Bentley

    Bentley Member

    Joined:
    Jun 18, 2017
    Posts:
    765
    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.
     
  3. RoddKOREA

    RoddKOREA Member

    Joined:
    Jun 13, 2019
    Posts:
    6
    Yes, that's it!
    I wanna do reducing instances processed outside the camera
     
  4. obscene

    obscene Member

    Joined:
    Jun 21, 2016
    Posts:
    2,402
    Deactivate them, and if that's not an option check if they're in view before running code.
     
  5. RoddKOREA

    RoddKOREA Member

    Joined:
    Jun 13, 2019
    Posts:
    6
    When is the time to check, exactly?
    if every step do I check, It will process too much
     
  6. obscene

    obscene Member

    Joined:
    Jun 21, 2016
    Posts:
    2,402
    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.
     
  7. RoddKOREA

    RoddKOREA Member

    Joined:
    Jun 13, 2019
    Posts:
    6
    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)
     
  8. Joe Ellis

    Joe Ellis Member

    Joined:
    Aug 30, 2016
    Posts:
    893
    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
     
    Ido-f likes this.
  9. RoddKOREA

    RoddKOREA Member

    Joined:
    Jun 13, 2019
    Posts:
    6
    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...
     
  10. rIKmAN

    rIKmAN Member

    Joined:
    Sep 6, 2016
    Posts:
    4,336
    Tiles are automatically culled by the engine when outside the view
     
  11. Joe Ellis

    Joe Ellis Member

    Joined:
    Aug 30, 2016
    Posts:
    893
    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: Aug 12, 2019

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice