+4 votes

It seemed obvious to me, until I found the VisibilityEnabler node.
When I create a sprite, or any visual node, will it be culled when it is out of view?
If not, does it means I have to add a VisibilityEnabler on every object?

in Engine by (28,974 points)
edited by

1 Answer

+1 vote

Good question. Frustrum culling is definitely implemented for 3D. You can test it. Make a 3D scene, move with camera, open the Debugger and open the Monitor tab. There is a number Objects Drawn. It shows 0 in 2D scenes and I think there should be something like Sprites Drawn for 2D (you could open a feature request on GitHub). But even though I can't test it, I'm pretty sure the sprites are also culled.

It looks like VisibilityEnabler affects only animations and physics. RigidBody is still simulated even outside of view. Frustrum culling is related to rendering.

by (830 points)

You're right!
But... I was also thinking about nodes drawing things from script, in _draw(). How can the engine know when to call _draw() if you don't provide a bounding box? Is it computed on the fly?

You don't have to provide your own bounding box. AABB is automatically computed and recomputed, if you add surface. You can find functions like _recompute_aabb in mesh.cpp.

In 3D yes, but in 2D?

C++ is not my thing but from a brief look to the code base, I think the clipping rectangles are computed inside function _render_canvas_item in visual_server_raster.cpp. So yeah, even if you use _draw(), it looks like there is a frustrum clipping.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.