rive-unity icon indicating copy to clipboard operation
rive-unity copied to clipboard

Transparency Issues

Open KnightOwl-Git opened this issue 1 year ago • 10 comments

I noticed some slight transparency issues when using the new widget components (which are awesome by the way!!)

Blending from a color to full transparency has this muddy in-between color. The yellow background here is the camera background in Unity.

Screenshot 2025-01-10 at 11 46 56 AM

For comparison, here's what it looks like when the yellow background is within the rive file itself: Screenshot 2025-01-10 at 11 49 42 AM

In addition, there's a slight dark outline around rive graphics with alpha transparency, most visible with a bright object against a bright background. My guess is that this is the same problem as the above interacting with the anti-aliasing.

Screenshot 2025-01-10 at 11 47 00 AM

KnightOwl-Git avatar Jan 10 '25 19:01 KnightOwl-Git

Thanks for reporting this, we're looking into it internally!

It sounds like the same issue mentioned here. There's a workaround in that thread that you could try in the meantime for the dark outline.

damzobridge avatar Jan 10 '25 23:01 damzobridge

Thanks! Is there any way to apply that legacy shader to the rive canvas object material through a script? Or would I need to render to a texture and then display it manually?

KnightOwl-Git avatar Jan 11 '25 07:01 KnightOwl-Git

For now, you can create a material that uses the legacy shader, then use GetComponent on the RivePanel to get the CanvasRendererRawImage and apply it directly there.

397652957-56784649-6e91-436d-80ef-65fcf7d998da

We're going to expose a way to pass in materials directly in an upcoming release.

damzobridge avatar Jan 11 '25 20:01 damzobridge

When I try running this script, I get an error saying "CanvasRendererRawImage" is inaccessible due to its protection level.

Screenshot 2025-01-11 at 1 26 39 PM Screenshot 2025-01-11 at 1 27 22 PM

Sorry if I'm missing something obvious, I'm new to Unity!

KnightOwl-Git avatar Jan 11 '25 21:01 KnightOwl-Git

No worries! If you do transform.GetComponent<RawImage>() instead, does that work for you?

damzobridge avatar Jan 12 '25 03:01 damzobridge

That works, thanks so much! I see now that the transparency issue has to do with pre-multiplied alpha vs straight alpha (same as the current unreal runtime build)

KnightOwl-Git avatar Jan 12 '25 04:01 KnightOwl-Git

Someone mentioned the same problem in the community here: https://community.rive.app/c/support/color-accuracy-issue-in-unity-if-background-is-transparent-gamma-color-space

lancesnider avatar Apr 11 '25 20:04 lancesnider

Someone mentioned the same problem in the community here: https://community.rive.app/c/support/color-accuracy-issue-in-unity-if-background-is-transparent-gamma-color-space

that's me! thanks for the discussion it helped me fix it, and if you still need to use Linear color space when using Rive, I posted a shader there that can fix this and allow you to use Linear color space, just use UI/Rive Linear instead of the Legacy Shader once you put that shader in your project

ardiwii avatar Apr 14 '25 09:04 ardiwii

I just found out the Rive Canvas Renderer has this Custom Material field which does exactly what the suggestions here tells us to do. So we do not need to add any custom code: Image

sandolkakos avatar May 27 '25 15:05 sandolkakos

note that if you want to also display it in Editor with the linear space correction you can override the default shader directly in the inspector (debug mode) for the Raw Image ... note that unless you make a small change in the code it will override it if you don't want to switch it again at runtime: RiveCanvasRenderer.cs line 153: if (DisplayImage != null && m_customMaterial != null)

ErikBehar avatar Aug 01 '25 22:08 ErikBehar