Doesn't Godot automatically discard the fragments outside the screen?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By 2plus2makes5

This is probably a stupid question but i want to know for sure.
If you use something like this in the spatial fragment shader:


you will discard(=avoid the draw) every fragment/pixel that is outside the screen, does godot do this automatically?

If you are in the editor with the camera preview and the view is wider than the camera preview you will see the difference, without this everything is drawn, with this only the content inside the camera preview is drawn.

Obviously showing everything has to be a desired feature in the editor but i wanted to know if it’s the same in game or not.

Just for your info if i add those lines to the spatial fragment shader my game runs slower lol.

:bust_in_silhouette: Reply From: Zylann

Godot (and any renderer, really) will not process fragments that are not inside the viewport.

It may be larger in the editor because the viewport is the scene view’s viewport, which may be drawing using a different camera. But in game, it will respect whatever viewport and active camera you may have.

If you are doing this in a UI, you may be able to use the clip_contents property of the Control node, so that the pixels outside the rectangle won’t be processed by the fragment shader (this is how scrollviews are made).