Hello Guest

Author Topic: Change 2dTk shader of sprite at runtime  (Read 4481 times)

spudubi

  • Newbie
  • *
  • Posts: 2
    • View Profile
Change 2dTk shader of sprite at runtime
« on: January 16, 2014, 11:17:12 am »
Hi,

My Sprite Collection uses a material with the 2dTk "BlendVertexColor" shader. I'm creating sprites from that collection at runtime like this:

Code: [Select]
tk2dSpriteCollectionData spriteCollection = Resources.Load("HexTilesData", typeof(tk2dSpriteCollectionData)) as tk2dSpriteCollectionData;
tk2dSprite tileSprite = tk2dSprite.AddComponent(goTemp,spriteCollection, "hexBorder");

Now I'm trying to change the shader of one sprite at runtime to the 2dTk shader "AdditiveVertexColor" like this:

Code: [Select]
selectedHexTile.sprite.renderer.material.shader = Shader.Find("AdditiveVertexColor");
But it doesn't work. The Sprite will be rendered in solid pink  :). I guess that's because Unity can't find the "AdditiveVertexColor" shader. I tried to put the shader in a Resources folder but that didn't worked either.

What is the right way to change the shader?
« Last Edit: January 16, 2014, 11:38:34 am by spudubi »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Change 2dTk shader of sprite at runtime
« Reply #1 on: January 16, 2014, 11:39:41 am »
1. it needs to be in resources
2. the name is "tk2d/AdditiveVertexColor"

spudubi

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Change 2dTk shader of sprite at runtime
« Reply #2 on: January 16, 2014, 11:49:17 am »
Wow, thanks for your fast reply!

Now it works!

Is this method the best method (performance wise) to change the render style of a sprite to additive rendering during runtime?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Change 2dTk shader of sprite at runtime
« Reply #3 on: January 16, 2014, 04:25:13 pm »
Probably? There aren't any other ways of changing to additive when rendering as far as I can tell.