Are Shaders Rendered When Not Visible?

Godot Version

4.3

Question

Are shaders still rendered when they are not visible?
I have been trying out using shaders to change the appearance of some text within a Label node and then modifying the Labels position and visibility with an AnimationPlayer node. (This is being used to display some simple ‘level complete’ message to the player, in case you were wondering).
What I am curious about is whether or not the shader material is taking up processing power when it is not visible, ie when the Label is off screen or has its CanvasItem Visible variable set to false.

If all of the object’s polygons are outside of viewport, fragment function won’t be executed as it runs once per pixel. Vertex function may still run if the whole object is not culled away by engine’s frustum culling. This typically operates on object’s axis aligned bounding boxes. In that case no shaders will run for the object.

1 Like

Ok, I think I understand. So the engine will automatically not try to render an object and its shaders so long as it is totally out of the viewport and this evaluation is done regardless of actual visibility?

Yes. This is called frustum culling and it’s one of the fundamental optimization techniques in rendering. The engine does a computationally inexpensive check of object’s bounding box against the viewing volume and if the box is guaranteed to be outside - the object won’t be sent further down the rendering pipeline.

Sometimes an object geometry may be fully outside but its bounding box may still intersect the viewing volume. In this case the object won’t be visible at all but the vertex shader will run.

Note that this doesn’t deal with mutual overlapping of objects. An object that it fully behind another object will still be rendered. From frustum culling perspective - they’re both considered visible.

Perfect. Thank you so much for the explanation.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.