In Unity’s shader graph with HDRP, this means that the transparency is controlled by both color values and the alpha values.
In URP, using the same shader graph setup, the premultiplied blend mode behaves differently than it does in HDRP, and the transparency is controlled only by the alpha values and premultiplied seems to act the same as alpha blend in URP.
This shader I had for HDRP.
I’m using version 10.4 of shader graph/HDRP/URP for this.
I’ve read this: Alpha Blending: To Pre or Not To Pre | NVIDIA Developer
but I’m not too sure what “SourceColor” or “DestinationColor” is referring to.
Here’s my current understanding: in engine, to create transparency, the image on top is blended with the image behind it. For additive, the image is add to the background. For multiply, the imagine is multiplied with the background. For alpha blend, the image is masked using the alpha channel?
And the premultiplied blend mode is meant to use the alpha channel to determine where the texture is additive (black) and where is alpha blend (white). Where it is Black in the alpha channel, RGB black would be come transparent.
For premultiplied blend mode to work, it would have to use premultiplied textures, which are textures that have the RGB multiplied with it’s own alpha channel.
So I came up with this formula to use in Unity Shader Graph:
Output RGB = Texture RGB * ( Vertex RGB * Tint RGB) * Emission Intensity
Output Alpha = {[Texture Alpha * (Vertex Alpha * Tint Alpha)] + [(Texture RGB adds together) / 3]} * Opacity
I avg out the rgb so the alpha isn’t just controlled by 1 of the RGB channel when I mess with tint/vertex color.
With that formula I made a URP premultiplied shader graph, and it seems to behave pretty similarly to the HDRP premultiplied shader graph, where the transparency is controlled by both alpha and color values.
But here I run into a problem, the image that shows up has distinct black edges.
So I ended up making s URP shader graph using this formula for the alpha instead:
Output Alpha = {(Vertex Alpha * Tint Alpha) + [(Texture RGB adds together) / 3]} * Texture Alpha * Opacity
Once I do this, the black edges are reduced (but still there).
This shader can also use textures that are not premultiplied, this removes the black edges completely and makes the image look brighter (and better imo).
The testing textures I used.
The results.
URP (Left) is the first URP shader, HDRP (center) is the HDRP shader), and URP 2 is using the second, revised URP shader. URP 2 is the only one here using the non-premultiplied texture.
Is my understanding of what on blend mode and premultiplied correct here?
Is Unity’s premultiplied working the way it is suppose to in either HDRP or URP?
Does my revised shader still counts as premultiplied blend mode? Does that even matter if it looks good and seems to have the right effect? Does it have the right effect??
Please let me know if there’s something I can do to improve these basic shaders.
Thank you for your help.
P.S. Are there any books on this kind of topic that I should read up on? I’d like to better understand how shaders work.