#Keyword _ALPHAPREMULTIPLY_ON
1 messages · Page 1 of 1 (latest)
My understanding is that keyword is no longer tied to the blend mode - https://github.com/Unity-Technologies/Graphics/blob/5b723784671c637b2397b395a60474c68ee7af73/Packages/com.unity.render-pipelines.universal/Editor/ShaderGUI/BaseShaderGUI.cs#L1095
(instead to a _BlendModePreserveSpecular property/checkbox. I think as of 2022 versions)
Thank you for the response,
the property _BlendModePreserveSpecular adds a checkbox called Preserve Specular lighting when the blend mode is put on Alpha or Additive, it works well but it has nothing to do with Premultiply.
Hmm kinda. Shader Graph's "Premultiply" mode has been a bit of a mess. Afaik it sets the Blend operation correctly but the keyword is a separate thing that Unity defines.
In the past the _ALPHAPREMULTIPLY_ON was linked directly to the Blend Mode, hence the naming. But the purpose of the keyword was to "move the multiply with alpha into the shader". For unlit graphs it would do :
#ifdef _ALPHAPREMULTIPLY_ON
surfaceDescription.BaseColor *= surfaceDescription.Alpha;
#endif
And for PBR/Lit I think that would only be on the diffuse side of shading calculations, leaving specular alone.
Doing that made it basically equivalent to the Alpha blend mode. There's many threads mentioning that confusing behaviour/bug. e.g.
https://realtimevfx.com/t/im-having-a-hard-time-understanding-how-premultiplied-blend-mode-is-suppose-to-work-in-unity/17552/
https://discussions.unity.com/t/pre-mult-bug-issue-unresolves/734353
In 2021.2 the above snippet was removed which fixed that for unlit graphs. But afaik it stayed the same for lit (Premultiply would still diffuse *= alpha)
As of 2022.1 that behaviour was separated. The keyword is the same but despite the name _ALPHAPREMULTIPLY_ON, it is tied to _BlendModePreserveSpecular and not related to the blend mode anymore. Similar to what I linked earlier, this shows when the keyword is enabled :
bool preserveSpecular = (material.HasProperty(Property.BlendModePreserveSpecular) && material.GetFloat(Property.BlendModePreserveSpecular) > 0) && blendMode != BlendMode.Multiply && blendMode != BlendMode.Premultiply;
if (preserveSpecular){
srcBlendRGB = UnityEngine.Rendering.BlendMode.One;
material.EnableKeyword(ShaderKeywordStrings._ALPHAPREMULTIPLY_ON);
}
(Could probably confirm by using your graph with Alpha blend mode and toggling the Preserve Specular Lighting option. It should switch between blue/red)
Not sure why they didn't rename the keyword... perhaps for backwards compatibility reasons. But that seems to be how it is (based on reading various branches of the Graphics repo, mainly BaseShaderGUI.cs). If you actually need to know the blend mode, you're probably better off making your own keyword & setting it from a script.