Author Topic: How to add NGUI support to a custom shader?  (Read 7583 times)

nguiman

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 30
    • View Profile
How to add NGUI support to a custom shader?
« on: February 27, 2014, 10:14:09 PM »

For my own shaders, how would I add NGUI support for such features as Alpha Clipping (etc.) to them?

kittikun

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 5
  • Posts: 46
    • View Profile
Re: How to add NGUI support to a custom shader?
« Reply #1 on: February 28, 2014, 12:42:33 AM »
What I did was create a new material with a custom shader and assign it to a new UIAtlas

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to add NGUI support to a custom shader?
« Reply #2 on: February 28, 2014, 07:46:42 PM »
Clipping support, assuming that's what you're asking, is done by creating copies of your shader with the appropriate suffix, such as " (SoftClip)". Inside you'll need to add code that uses clipping. Look inside NGUI's shaders for an example.

nguiman

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: How to add NGUI support to a custom shader?
« Reply #3 on: March 01, 2014, 12:02:01 AM »

Thank you, I will certainly have a look at those examples and give it a try.

nguiman

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: How to add NGUI support to a custom shader?
« Reply #4 on: March 04, 2014, 02:04:17 PM »
How would I approach this if I want a GameObject to support alpha clipping of a UIPanel?

My first test involved just making a duplicate of the 'Unlit - Transparent Colored (SoftClip)' adding it to a material, assigning a texture and then applying it to a GameObject residing under a UIPanel. The result is that the GameObject is "invisible" even within the clipping region (x & y) of the UIPanel.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to add NGUI support to a custom shader?
« Reply #5 on: March 05, 2014, 08:16:44 AM »
Those shaders are written to work with UI elements, and won't work with regular game objects. Your best bet is to render the game objects into render textures then draw those render textures like you normally would using NGUI's UITexture.

nguiman

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: How to add NGUI support to a custom shader?
« Reply #6 on: March 05, 2014, 02:09:17 PM »
Thanks, that was my backup plan. If for future versions that feature was added, I'd be appreciative  ;)

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: How to add NGUI support to a custom shader?
« Reply #7 on: March 05, 2014, 02:30:05 PM »
If it's a very fixed screen, you can also have a particular camera for that and have it's viewrect be smaller (matching the UIpanel's clipping rect). It can be a hassle to setup, but it works just fine.