2

How to create a simple pixel color shader that say takes a texture, applyes something like masking:

half4 color = tex2D(_Texture0, i.uv.xy);
if(distance(color, mask) > _CutOff)
{
    return color;
}
else
{
return static_color;
}

in and returns a texture that can be passed to next shader from c# code in a way like mats[1].SetTexture("_MainTex", mats[0].GetTexture("_MainTex"));?

CC Inc
  • 5,842
  • 3
  • 33
  • 64
myWallJSON
  • 9,110
  • 22
  • 78
  • 149
  • Have you tried the Unity help forum? That's quite a specific question you got there. But... you might not want to do a shader to only modify a texture. – LightStriker Oct 30 '12 at 21:52

1 Answers1

4

But... you might not want to do a shader to only modify a texture.

Why not? It is a common practice.

Check out Graphics.Blit. It basically draws a quad with material (including a shader) applied. So you could use your shader to modify a texture. But the texture has to be RenderTexture.

It would be like this:

var mat = new Material(Shader.Find("My Shader"));
var output = new RenderTexture(...);
Graphics.Blit(sourceTexture, output, mat);

sourceTexture in this case will be bound to _MainTex of My Shader.

Valentin Simonov
  • 1,768
  • 10
  • 14