Author Topic: Alpha Mask with NGUI  (Read 2308 times)

Argiris

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 6
    • View Profile
Alpha Mask with NGUI
« on: March 21, 2017, 06:02:31 AM »
Hello.

We'd like to use Alpha Mask 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

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,151
  • Toronto, Canada
    • View Profile
Re: Alpha Mask with NGUI
« Reply #1 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.

Argiris

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Alpha Mask with NGUI
« Reply #2 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.



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

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,151
  • Toronto, Canada
    • View Profile
Re: Alpha Mask with NGUI
« Reply #3 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.

Argiris

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Alpha Mask with NGUI
« Reply #4 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.

devi

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: Alpha Mask with NGUI
« Reply #5 on: September 27, 2017, 04:55:34 AM »
Hello.

Where i can enable secondary UVs on the panel?
« Last Edit: September 27, 2017, 05:08:03 AM by devi »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,151
  • Toronto, Canada
    • View Profile
Re: Alpha Mask with NGUI
« Reply #6 on: October 07, 2017, 06:10:05 AM »
You answered your own question, devi. On the panel.