• RuntimesUnity
  • Is PMA shader support URP 2D Additive Lights?

Hi, I found alpha blending is broken when I use PMA shader with URP 2D additive light.
This is spine animation with additve 2d light. Alpha blending is broken.

This is my spine animation's material. Spine animation is export with PMA ticked.

My workaround is modify some shader code to make it works, but I am not sure it is correct fix or not.

In Shaders/2D/Include/Spine-Sprite-StandardPass-URP-2D.hlsl Line 96
Replace half4(main.rgb, 1) to main.
half4 pixel = half4(CombinedShapeLightShared(main, mask, input.lightingUV).rgb, main.a);
In Shaders/2D/Spine-SkeletonLit-URP-2D.shader Line 116
Also replace half4(main.rgb, 1) to main.
return half4(CombinedShapeLightShared(main, mask, i.lightingUV).rgb, main.a);
In URP package /Shaders/2D/Include/CombinedShapeLightShared.hlsl Line 25, 44, 63, 82
Add something like this. (X should be correspond to _ShapeLightTexture's index)
#if _ALPHAPREMULTIPLY_ON || !_STRAIGHT_ALPHA_INPUT
          shapeLightXAdditive *= color.a;
#endif

Is PMA shader not support 2D additive lights yet? Or something I doing wrong.
Thanks for your helping.. 🥰

Related Discussions
...

Unfortunately we could not reproduce the issue you are describing. Using PMA textures and setting up Material properties accordingly rendered correctly on our end. Are you sure that you're using the latest spine-unity URP shaders UPM package? If so, does the problem also occur when you create a new Material (e.g. delete the existing material and re-import) and change the shader to the URP 2D shader again? Perhaps there are leftover material keywords set from previous material changes.

If this still does not resolve your problem, could you please send us a minimal Unity project that still shows this error? You can send it as a zip package to contact@esotericsoftware.com, briefly mentioning this forum thread URL so that we know the context. Then we can have a look at what's going wrong.

Regarding your code modifications: Please note that in general the CombinedShapeLightShared.hlsl file can't be modified by us, as it's part of the official Unity Universal RP package.

    Harald
    Hi! I send a minimal Unity project via email.
    Thanks for your helping.

    Thanks for sending the reproduction project, we received everything.

    The problem is actually independent of whether PMA or straight alpha textures are used.
    The technical details of what causes the issue is that the Additive lighting blend style in combination with the shader's general additive blend mode is leading to an incorrect result currently, since the shader has PMA applied before lighting. While we might be able to adjust the Universal Render Pipeline/2D/Spine/Skeleton Lit accordingly, it might be problematic to support Universal Render Pipeline/2D/Spine/Sprite while still correctly supporting the many configurable options. We will have to think about this a bit.

    What you could do is set the mask channel of the Additive lighting blend mode to anything but None (e.g. to A to use the alpha channel) in order to not be applied everywhere (including the transparent areas). Then you would set the Mask property of the Material to the main texture, which then automatically masks the additive light to the alpha channel. This would be a simple workaround which does not require you to draw a special mask texture (as e.g. a rim light mask would require).

    Note that this masking workflow is similar as with the Rim lighting style in the URP 2D Shaders example scene, which requires the mask R channel to be set accordingly, otherwise the light will be applied at the whole opaque area instead of only at the rim.

    We have adjusted the Spine URP 2D shaders accordingly to respect the texture alpha channel when using Additive light blend style. A bugfix commit has been pushed to the 4.1 and 4.2-beta branches. If you still want to use the 4.0 Spine URP shaders UPM package, you could manually apply the changes of this commit to your 4.0 package.

    For later reference: The issue has been tracked under this ticket URL:
    EsotericSoftware/spine-runtimes2250

    Note that with this bugfix it is no longer necessary to use the mask-workaround described in the posting above. Please let us know if this fixes the issues on your side as well. Thanks for reporting!

      Very glad to hear, thanks for letting us know. 🙂