Custom Occlusion Culling

Knowing the position of my camera/ship, and the position of objects, I think I can make an custom occlusion culling in my game.
There is a big planet in the screen center that is in fixed position, and all other objects is in orbit of it, so I can know witch object is behind the planet in relation with the camera all the time.
So, how can I implement the occlusion culling ?

  1. I have read about the way to do it, I guess in my case I can just disable render on the entire object when I detect its behind the planet, so is it the right way to do it ?

    • spatial.setCullHint(CullHint.Dynamic); // Object is visible, disable culling, its the default
    • spatial.setCullHint(CullHint.Always); // Object is behind the planet, turn the culling on
  2. It expecting it to make no difference in the physics, I mean, I am not disabling the objects physics here, just the render right ? It will continue to collide even behind the planet I hope.

  3. Do I need to put this command in the pre-render or in the update is fine ?

Easiest way is I hinted before: set the far plane to the center of the planet. Anything beyond the center of the planet is automatically culled.

I’m not the OP, but since I read all posts and try to understand all problems and solutions, I have to ask:

I didn’t understood. By settings the Far Plane of Frustum at center of planet, will be a Frustum Culling, not a occlusion, so if the Camera is seeing beyond the planet center, i’ll be culled also, even if object is not occluded by planet…or I misunderstood something?

That is a great idea, I didnt know its possible to do it. Will try it.

You are correct, but if I set the plane right, I think it will do the culling right, since the planet is at the center of the screen and dont move… Of course, it will not be exactly on the center of the planet, but a litle bit beyond this, at least its what I understood form pspeed.

My understanding is that he’s essentially making a 2D game looking at a planet… so I was guessing that the planet takes up the entire field of view. I guess I haven’t seen a screen shot or anything so it was just a wild guess.

Nop, its an 3D game, but as far as I understood, it stills apply, right ?

Does the planet take up the entire field of view?

No, but 90%. Also, the planet is fixed, but the ship moves arround it, so I will maybe need to setup this plane every frame ?

I imagin something like it:

If he do it, objects like A and D will be culled.

Exactly, thanks friend, I was about to draw something like that.

What is drawn in the other 10%? Are there objects drawn there that are farther away than the center of the planet?

If the center of the planet doesn’t move relative to the camera position then you do not need to reset the far plane every frame.

The camera and the ship moves … Always in the planet orbit.

What I think he needs is what I was trying to learn on those days:

Cull the red area. So this interest me also :grin:

relative to the center of the planet? Or is the center of the planet always in the same place on the screen.

I need to bow out of this thread now… it’s already exceeded my “playing 20 questions” limit as I don’t even know what your game looks like really. So it’s hard for me to offer accurate tips.

Plenty of other smart people can help you with your issue, though… so good luck.

The planet is allways in the same place on the center of the screen.
This idea to use the far plane may work if I understood how it works.
Can you point out some info about how to setup it ?
Also, I have skymap on the scene, will it be cutted if I do the plane cut ?

How precise has to be? What if you simplify the red area to a cylinder?

Supposing the planet is at (0,0,0) and the camera is aligned to the X axis you could, do

  pos = object.getLocalTranslation();
  if (pos.x < 0 && new Vector2f(pos.y, pos.z).length() < planetRadius) {
         // do culling
  }

This assuming the objects aren’t big enough, otherwise you could multiply the radius by a factor.
Of course don’t instantiate a vector each time, I put it like that so it’s easier to read (you may save the radius squared and simply add X and Y squared).

But probably setting the back plane to a safer distance is faster.

I am not sure I understood your suggestion.
The original idea was to to check if each object is in the cone behind the planet ( red area ).
The problem with this idea is that I will need to loop for all objects for each frame, and I am not sure if it will improve performance or decrease it.
The suggestion to use the camera frustum far plane would fix the problem since I could do it in the pre-render only once per frame, but it seems it will cut down the skymap from the view…
I am not sure what alternatives I have here, maybe do the check on the objects control update for each individual object on pre-render ? That way I just dont need the loop.

If I understand it right, it will always be on your backplane besides of how far you set it.

@afonsolage your pictures are great :slight_smile:

1 Like

Occlusion Culling is always a performance hit. From my point of view, it has to rely on pre calculated data to be a win.

Since the planet is fixed, i think a 3d grid of chunks can be possible, you can precalculate which chunks of the grid will be visible for each chunk. All the performance critical parts can be precalculated and then stored.

But other question, do you have any performance issues? Or just too early optimisation :wink:

Since it is high likely that you are already cpu limited, introducing a cpu bound algorithm won’t help you that much. All a guess of course but from my experience nearly everyone is hitting the cpu limit for some other type of missed optimisation

2 Likes