Author Topic: FinalAlpha of UI2DSprite in SoftClip Panel  (Read 6455 times)

DarkMagicCK

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 20
    • View Profile
FinalAlpha of UI2DSprite in SoftClip Panel
« on: August 29, 2016, 03:41:23 AM »
Hello,

How can get an UI2DSprite's finalAlpha?
In my case, I add an addon mesh renderer for my GUI element, and want to sync the renderer's material's shader _Color.a with sprite's alpha, while UIPanel can not clip other renderers.

But I can only get finalApha=1, even if the sprite is soft clipped by UIPanel.

So how can I get that sprite's real final alpha?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: FinalAlpha of UI2DSprite in SoftClip Panel
« Reply #1 on: August 30, 2016, 09:21:27 PM »
What's the "final alpha" of a sprite where half of it is inside the panel and half is outside? Half the pixels will have one value, half -- another.

Soft clipping happens in the fragment shader on the GPU. You can check UIPanel.IsVisible(pos), but doing it for every single pixel of an image would be unrealistic at best. You need to write a shader that would do the clipping inside, much like I've done with the UI shaders.

DarkMagicCK

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 20
    • View Profile
Re: FinalAlpha of UI2DSprite in SoftClip Panel
« Reply #2 on: August 31, 2016, 04:35:51 AM »
Thanks, I finally decided to calculate the relation between widget's transform position and UIPanel's border, and set alpha according to that.