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 ?
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
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.
Do I need to put this command in the pre-render or in the update is fine ?
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?
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.
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.
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
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