Adding a shader to a game object

How to add a shader to a game object? a has a shader defined here:

(I'm trying to do the same, and I have some problems): http://answers.unity3d.com/questions/175692/getpixelsetpixels-or-stencil-eraser-brush.html

and 2 texture2D defined in the code and loaded through Resource.Load assigned to the game object. How can I apply a shader to my game object and communicate with 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 which is the main texture and the texture of the stencil?

+4
source share
1 answer

To apply a shader, you need material.

You can create material by clicking "create" in the project view.

If you use the shader code from this link, the shader should be in the shader drop-down list in the inspector when selecting material in the "Custom" section.

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

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

+5
source

Source: https://habr.com/ru/post/1444380/


All Articles