Closed Olaf-007 closed 4 years ago
When you ask a GPU to render to a target, it can only render rectangular areas--it has no concept of rendering to a non-uniform shape. What you're asking for requires a fragment shader which would determine if a fragment (which are different from a pixel) would be visible within the viewport, and discards it if not visible.
Essentially, this is something you would need to implement yourself. Considering you're working with a dynamically changing viewport shape, I would probably implement this using a mask. The mask represents the viewable area of the viewport, and you discard everything that falls outside that mask.
Yes, this is the reason why I would propose it as a Godot intern solution. I tried masks and I tried textures but the problem keeps the same: the viewport is rendered in its whole resolution and only the visible parts are displayed. But this is on cost of calculation resources: why should Godot calculate fragments if they cannot be seen or are not used? If the GPU can render only rectangular areas, Godot could map a polygon-viewport-shape on a rectangular shape that can be calculated by the GPU. In fact, it should not matter how many Viewports I use and in which shape they are, when they are puzzled together and their sumerized visible resolution equals the resolution of the screen the fps should keep stable.
Here is the official demo for dynamic split screen: https://github.com/godotengine/godot-demo-projects/tree/3.2-57baf0a/viewport/dynamic_split_screen
Likely related to https://github.com/godotengine/godot/issues/25031.
This is an awesome resource! Nice, thank you. This finally gives me an idea of how I can achieve my aim without performance issues. Somehow I wish I could get around fragmental shaders - they are not newbiefriendly.
Describe the project you are working on: I created a splitscreen-game for two players left and right. My aim is to change the players view from left/right to up/down. This is considered to happen with a smooth animation - here is what I achieved: https://drive.google.com/open?id=1QtRp5Yflog3mWaifCC5z1_bdQs6vTZFe
Describe the problem or limitation you are having in your project: In the begining two viewports are used as textures for polygons left and right. Their resolution is the half of the screen as it is in the end of the animation. During the "turn" I have to increase the viewport resolution to the the screen size to fill the polygons with the full horizontal and vertical length. BUT now the computer has to render two viewports of the resolution of the whole screen where as the polygons still display only the half of each. This "waste of render overage" costs resources which can be seen in the fps-decrease (You can follow it in the video very well).
Describe the feature / enhancement and how it helps to overcome the problem or limitation: 1st. Polygon Viewports or Segmental Viewport Property: Viewports only precalculate the pixels that are actually displayed on the texture it renders to. (Actually I thought it would do so, but the collapsing fps tell the opposite) In this way, the amount of pixels which have to be calculated for the polygon texture would keep the same during the "turn". 2nd. The Camera position in relation to the viewport should be changable. Right now, a viewport displays a camera and adapts the camera perspective size to the viewport rect_size. Additionally, the Camera always is "in the center" of the viewport (even when the camera offset is changed). What if I would like to have the perspective from a side of the viewport? Now, I have to manage this with a trick: render a viewport with the double of width to a viewport of the half. But this cooperates with "1st": then I render three!! viewports only to have one in the end. Feel free to ask again, if I was not clear enaugh about this important feature.
Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams: I could imagine a property for viewports that defines if the viewports is rendered once so it can be used for multiple textures and materials or each pixel is only rendered when it is accessed via the ViewportTexture.
If this enhancement will not be used often, can it be worked around with a few lines of script?: No!! As you can see in the video example, there is a way around, but it drops the performance in a small scene dramatically.
Is there a reason why this should be core and not an add-on in the asset library?: 1st: This is a feature that can be implemented only in the core because there is no gd-script that could handly this. 2nd: This feature can be tricked with code but still on cost of performance - this may work in a low poly game but never in a grafically intense game. It can only be changed in the core of Godot.