Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Argiris on March 21, 2017, 06:02:31 AM

Title: Alpha Mask with NGUI
Post by: Argiris on March 21, 2017, 06:02:31 AM
Hello.

We'd like to use Alpha Mask (https://www.assetstore.unity3d.com/en/#!/content/29764) with NGUI.

When I wrote to the plugin's creators some months back, they said it only supports the official Unity Sprites and UI.

They proposed we take look at the Alpha Mask source and try replacing Sprite with NGUI's UISprite. If UISprite uses the same shaders as Unity, it should work.
If not, we could replace the names of the shaders in the Alpha Mask source, and then it should definitely work.

Is there anyone who has already made Alpha Mask work with NGUI and would be willing to share their solution?

Thank you in advance,
Argiris
Title: Re: Alpha Mask with NGUI
Post by: ArenMook on March 21, 2017, 04:43:00 PM
NGUI already supports alpha masking via panels. Create a panel, make it clipped using a texture.

If you want to mask specific sprites, that's easy too. Enable secondary UVs on the panel. Specify a custom material on your sprite, referencing your new custom shader. In your shader use secondary UVs to sample the mask texture.
Title: Re: Alpha Mask with NGUI
Post by: Argiris on March 21, 2017, 05:00:41 PM
Hi Michael.

Thank you for your reply.

We're making a game where we essentially need to cut holes on dark surface,
to reveal a bright surface underneath it, in order to simulate a spotlight effect.

The holes will be sprites made of blurred circles and a bitmap font at its center.
Each sprite will move and rotate, and maybe even shrink/get enlarged in real-time.

(https://dl.dropboxusercontent.com/u/399814/ACB/Dynamic%20Masking.jpg)

At the end of each round, the circles and their contents will be reset.
We need to create new "spotlights" programmatically, at will.

Is this something that NGUI supports already?

Thank you,
Argiris
Title: Re: Alpha Mask with NGUI
Post by: ArenMook on March 21, 2017, 05:06:13 PM
Create an off-screen camera that draws your black & white dynami mask. Write a shader as I suggested using UV2 to sample the mask. Assign the custom shader to the material used by the bright surface sprite, and you'll have what you need.
Title: Re: Alpha Mask with NGUI
Post by: Argiris on March 21, 2017, 05:14:53 PM
Thank you for the swift reply, Michael! :)

We'll have a look and see how it goes.
Title: Re: Alpha Mask with NGUI
Post by: devi on September 27, 2017, 04:55:34 AM
Hello.

Where i can enable secondary UVs on the panel?
Title: Re: Alpha Mask with NGUI
Post by: ArenMook on October 07, 2017, 06:10:05 AM
You answered your own question, devi. On the panel.