-
Notifications
You must be signed in to change notification settings - Fork 440
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
Support arbitrary background color with the DistanceField shader #448
Comments
Hi, this artifact is usually due to a wrongly set up blending. What blending do you use? There's a difference between blending for non-premultiplied alpha and premultiplied alpha, and the change you've done above is basically changing from a premultiplied alpha workflow to a non-premultiplied alpha workflow. Details and sample code here: https://doc.magnum.graphics/magnum/classMagnum_1_1GL_1_1Renderer.html#a42c00dd07d227c8975b07e39ad3f6b09 TL;DR: I assume your blend function is Cool graphics btw., is the game public? :) |
You guessed that right.
SDF rendering is indeed much better with this setting! However the rendering of my own shaders (here my rounded rectangle frag shader) is all broken: Seems like I have much more to learn about OpenGL than I thought I already had. I'll see what I can do about it. Sorry for the inconvenience and thank you very much for your kind help, once again.
Thank you! Yes, the game is completely free and GPL-licensed. It's a kind of match-three game and you can play it directly here: http://ternarii.com/ |
A hack could be to use the non-premultiplied blending for the rectangle and premultiplied for the SDF things; a proper solution would be converting your shader to assume premultiplied alpha also. Not sure if that helps, but colors with premultiplied alpha never have RGB channels a higher value than the alpha. So check your shader and do something like |
The game is fun, got to 23k before it got all filled up and I lost :D Will mention it in the list of cool things for the next release if that's okay with you ;) |
I've finally been able to grasp how premultiplied alpha works. It indeed makes things easier in some cases. Thank you very much for the hints.
Not bad for a start ;). I'm glad you enjoy the game!
That would be with great pleasure! |
Great! I remember I wanted to add support for arbitrary background color in the DistanceField shader (instead of always |
@mosra Nice! Thanks again :). |
Hi Mosra,
I get some unwanted, unaesthetic dark outlines when drawing white SDF (glyphs or images) over various colors, although outline range is
{0.5, 0.5}
:This is due to the following line of the frag shader (DistanceFieldVector.frag):
This result isn't surprising, as multiplying the whole color with the smoothstep causes in-between, semi-transparent pixels to be darker (as their R, G and B channels have lower values).
I get a much cleaner result by applying the smoothstep to the alpha channel only:
Outcome:
This fix won't suffice however, because it causes all outlines to be much lighter than wanted (as you can see on the "PURITY ROOM" text at the bottom of the image, or on the corners (which are SDF images as well)). This behavior isn't surprising either, as the outline code consists of adding values to fragment color:
I've yet to understand this part of the shader (I'm not so fluent in shader coding) to come up with a proper fix. Hopefully you'll be able to find something simple?
The text was updated successfully, but these errors were encountered: