Author Topic: Change Shader Property  (Read 4995 times)

hungweng

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Change Shader Property
« on: May 30, 2013, 01:34:46 AM »
Hi,

    I have some properties on the material used by the Sprite that I would like to change by code, but I am not sure where to get the material used by the sprite.
    The sprite.material returns the sharedMaterial but that would change all the sprite used by the same material which is not what I want.
    How should i implement this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Change Shader Property
« Reply #1 on: May 30, 2013, 03:01:56 PM »
You can't modify materials per-sprite. There is only one material -- on the atlas. That's how everything is able to get batched into one draw call.

hungweng

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Change Shader Property
« Reply #2 on: May 30, 2013, 09:33:44 PM »
Thanks ArenMook

What I have is a HSV shader that can do the Hue shifting, and the UISprite is actually a spriteAnimation using an atlas on its own.
Instead of having the artist to produce different textures for different color variation of the sprites, I thought I can save the product size by using the shader

So I guess if I really need to use different materials I'll have to duplicate both the UIAtlas prefab and the material in the editor and create sprites using the duplicated atlas...
I know it's going to have an extra drawcall but currently the drawcall is still very low so I guess it won't affect the performance for our game...at least not much

galuodo

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 65
    • View Profile
Re: Change Shader Property
« Reply #3 on: May 31, 2013, 12:02:14 AM »
I have an alternative solution, and now is optimizing. :)

hungweng

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Change Shader Property
« Reply #4 on: June 02, 2013, 08:50:51 PM »
Hello Galuodo,

    Is it possible to share the alternative solution of yours or perhaps some hints please? Thanks!

galuodo

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 65
    • View Profile
Re: Change Shader Property
« Reply #5 on: June 02, 2013, 09:20:35 PM »
use UITexture