Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: DarkMagicCK on August 29, 2016, 03:41:23 AM

Title: FinalAlpha of UI2DSprite in SoftClip Panel
Post by: DarkMagicCK 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?
Title: Re: FinalAlpha of UI2DSprite in SoftClip Panel
Post by: ArenMook 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.
Title: Re: FinalAlpha of UI2DSprite in SoftClip Panel
Post by: DarkMagicCK 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.