Hello Guest

Author Topic: Shader Alpha Change  (Read 12002 times)

gearworks

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Shader Alpha Change
« on: April 19, 2012, 05:00:11 am »
I am using aperture cutscene editor with your cool tool to make cartoon-like animations.
It is working smoothly but I have found that I can not modify alpha (via the cutsceneeditor) on the custom shaders that come with the 2dtoolkit :/

If I change the shader to some build-in unity shader fx. transparent diffuse it works but I get a "Shader wants normals, but the mesh doesn't have them" warning. I am not terribly strong in materials, shaders and rendering but I realize this is because 2d doesn't need normals the same way 3d does to render highlights etc. and that the mesh and shader is less complex(?).

It seems like the cutscene editor is working how it should and that I need to give it a shader/material it can communicate with.
Can you advice on a good approach on how to do that?

tnx



This is the function cutscene editor uses to set the alpha:

Code: [Select]
function SetChannelA(value:float) {
SetupMaterial();
if (!material) return;
if (!material.HasProperty(propertyName)) return;
var c:Color = material.GetColor(propertyName);
c.a = value;
material.SetColor(propertyName,c);
}

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Shader Alpha Change
« Reply #1 on: April 19, 2012, 07:48:06 am »
You can either use the tinted shaders from here - http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,48.0.html

Or set up the sprites to generate normals in sprite collection settings, then you'll be free to use whatever shader you like.

The problem with either approach is the change will be global, and you will need a unique material for each sprite (you'd need a unique material on any objects you animate this way too).

The best way to deal with this is to modify the cutscene editor, if you have the source, to directly modify the .color property in the tk2dSprite component.

gearworks

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Shader Alpha Change
« Reply #2 on: April 20, 2012, 08:06:03 am »
Thanks a lot for you answer.

I'll see if it is feasible to mod the cutscene editor.

I am not sure I completely follow this however:
Quote
...you will need a unique material for each sprite (you'd need a unique material on any objects you animate this way too).
...because my knowledge of shaders and materials is so basic. I will need to change the materials on all the things I need alpha change on off course. With a lot extra complexity and worse performance as a sideeffect? If yes that should be enough to deter me :)

Can you recommend some place to go to pick up on shaders/materials that is better than unity's own guide?


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Shader Alpha Change
« Reply #3 on: April 20, 2012, 10:23:57 am »
So basically, the color parameter the cutscene editor changes is a property of the material. I.e. all objects / sprites using this material will automatically be affected as the material is shared between them. if you want to then change 2 sprites independently using material parameters, they will need unique copies. (which will break all forms of batching too, and performance will suffer, a lot)

Thats why the 2D Toolkit sprites use vertex colors to store color / alpha per sprite. That way you still share the material, but change the alpha property in the mesh (indirectly, through the accessors).



I'm not sure what would be best to recommend for shaders within Unity. The combiner syntax which the 2D Toolkit shaders use is specific to Unity - this is intentional to support older devices and hardware.

If you want to learn about hlsl/glsl/cg there are TONS of tutorials online - they will all be very relevant to how the cg shaders work in Unity.