Godot Version
godot-4
Question
So I’ve got a shader that is altering the UV. To apply it as post-shader I used a transparent ColorRect that is using the shader. Unfortunately the edge-cases (literally the edge of the window) are problematic: If you have a texture that is rendered in the first (normal) step on the edge of the window and it gets shifted more to the center of the window, you get a ‘stretching’ on the edge. See here on the left side:
To fix this my best attempt is to render everything inside a viewport that is larger than the actual window and then render that to a TextureRect. Until this point I used the Viewport Stretchig mode in the project settings so my in-game coordinates are the same as my pixels. But now with the projection from the viewport to the TextureRect the shader-effect gets pixelated (which looked awful).
To fix this my best attempt is to increase my projects viewport size and change the Streching mode to canvas-item. Now I use a SubViewport which has the intentional viewport size (+ the extra on the edges of the previous fix), where the actual level is rendered. This way the game is still pixe-perfect. Then I project that to a TextureRect inside another SubViewport with the size of the projects viewport (+ the extra on the edges of the previous fix). In this SubViewport I use the ColorRect for the post-shader. And finally I render that to a TextureRect in the main-viewport.
Though this is working fine on my (not so new) gaming-PC, the FPS on my working Laptop is dropping to 30. The problem seems to be the multiple rendering-steps (3 if I am correct). But I don’t understand why it is that hard of a bottleneck. And it actually bugs me that I can’t find any better solution because I am aware that rendering 3 times is extremely unefficient. In fact with my own engine (which was buggy as hell; that is why I changed to godot xD) I was able to handle the exact same shader (just in GLSL) much more efficient.
So my questions are: Is there a better solution? Why is the bottleneck that hard?