-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Render GUIs on a texture, then render that texture on screen #1874
Render GUIs on a texture, then render that texture on screen #1874
Conversation
b1c8371
to
a96406a
Compare
Update on this: currently there are at least 2 known errors in OpenGL renderer: EDIT: error 2 fixed now. |
01defe8
to
e6c5550
Compare
Hey, this works for me! Tested and both error 1 and 2 seem to be fixed indeed! :) I think you fixed the caveat you mention in #1837 , on item 1 , about rendering at screen res. |
I need to tidy (squash) the commits again, and there's also one logical mistake about switching render targets that has to be fixed (it is not seen in the current setup, but may surface if there's more complex batch configuration).
No, I did nothing in regards to that. |
034a529
to
173bdee
Compare
This lets apply additional effects, such as transparency or rotation, to the whole GUI, not worrying about visual inconsistencies or correct content clipping.
There are two problem that we have: 1. The texture which we render to also must have a valid alpha channel in the end (unlike the final backbuffer). Therefore we must make sure that it retains a sum of alphas of all the sprites drawn on top of it. See: https://stackoverflow.com/questions/27929483/directx-render-to-texture-alpha-blending/27932112#27932112 2. The resulting texture pixels will contain colors (RGB components) already multiplied by alpha ("premultiplied alpha"). If we draw this texture onto screen using default blend op, then its source colors will again be multiplied by its alpha, producing incorrect result (source colors will look "dimmer"). Therefore we also need to use a special blend op for this, which takes source RGB as-is, but still uses src alpha to correctly blend with the dest RGB. Oh, and it must also account for optional extra transparency.
See previous (Direct3D) commit for comments.
This may be a temporary solution, but it's necessary, because otherwise engine will fail later, with a seemingly unrelated error, which will be harder to diagnose.
173bdee
to
14eb84c
Compare
I wanted to do some additional refactor, but met couple of difficulties. So, I'll merge this pr first and make another attempt on refactor bit later. |
Resolves #1838 and will potentially help #1837 after merged/ported to ags4.
After implementing rendering GUI controls as separate textures (see #988 and #1393 for details), it turned out that the implementation has a serious mistake: any additional visual effect applied to a whole GUI, such as Transparency, would apply incorrectly, as controls would blend with GUI background using same effect, producing different visual result.
I guess there may be different approaches for resolving this problem. But we also assume that in the future GUI may be assigned more various properties, such as rotation (already exists in ags4), which makes it more difficult to clip controls to GUI borders on screen, or custom shaders, which would be expected to be applied to GUI & controls in whole, while each control might also have its own individual effect, making things more complicated.
Therefore the chosen solution is to render whole GUI on a texture and then render that texture on screen. This is kind of similar in logic to what is done in software rendering, except still done as a scene render by GPU, without bitmap operations.
Additionally, same technique may be used later for anything, if necessary (maybe for room viewports, if we decide to support translucent viewports sorted among GUIs, etc).
What this PR includes: