Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a shader to a gameobject

How can I add a shader to a game object? a have a shader defined here:

(i am trying to do the same thing and am having some problems): http://answers.unity3d.com/questions/175692/getpixelsetpixels-or-stencil-eraser-brush.html

and 2 texture2D defined in code and loaded through Resource.Load, assigned to a game object. How can I apply the shader to my game object and communicate with the two textures?

As you can see, I have this code in my Shader

_MainTex("Main Texture (rgb)", 2D) = "white" {}
_Color ("Main Color", Color) = (1,1,1,1)
_Stencil("Stencil Texture (a)", 2D) = "white" {}

how can I tell the shader who is Main Texture and Stencil Texture?

like image 928
Alex Avatar asked Nov 06 '12 14:11

Alex


1 Answers

To apply a shader, you need a material.

You can create a material by clicking 'create' in the project view.

If you use the shader code from the given link, the shader should be in the shader dropdown list in the inspector when selecting a material, under Custom.

You can change the main texture or the other properties through code or in the inspector.

See here: http://docs.unity3d.com/Documentation/ScriptReference/Material.SetTexture.html

like image 127
Soeholm Avatar answered Nov 08 '22 17:11

Soeholm