Author Topic: Sprite don't use the correct shader once attached to a scrolling panel  (Read 1897 times)

Gaxil

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 7
    • View Profile
Hi,

I'd like to use a special shader for a specific sprite, so I've created an atlas and have assigned my custom material to that Atlas. It's working fine if my sprite is on the root of my interface, but when I try to load my sprite resource and attach it to panel/container (using NGUITools.AddChild), it is displayed using another shader, not the one I wanted.
I've checked with the Show Draw Calls tool to investigate and it is reported to be displayed using my special shader albeit it is clearly not using it.

You can see it on the attached screenshot. On the left, it's using a regular shader, on the right my custom one (working).

Is there anything I should modify or check?

Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
I'm going to venture a guess here and say that your shader expects certain parameters, right? When do you set those parameters and on what material do you set them on? NGUI clones the material. It doesn't use the original material. So if you set something on the original material, cloned materials won't be affected. You need to subscribe to UIWidget.onRender and set the values on the material it passes, not the original one.

P.S. I noticed that you mentioned a scrolling panel. NGUI uses replacement shaders to draw stuff inside panels. Check the difference between the "Unlit - Transparent Colored" and "Unlit - Transparent Colored 1" shaders for example. The former is the original shader, the latter is the 1-panel clipped shader.

Gaxil

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 7
    • View Profile
Perfect! I had already implemented the onRender, it was the replacement shader which was not defined! Thank you very much for the fast help!

By the way, congrats again for your very nice product! I use it intensively since many month now and was never disappointed, really helpful for my app's development! Also great on the performance side, even with hundreds of sliders and stuff going on. I've attached a screenshot with the new curve control working fine now :) Thanks again!