如何创建一个简单的像素颜色着色器,说需要一个纹理,应用类似于掩蔽:
half4 color = tex2D(_Texture0, i.uv.xy);
if(distance(color, mask) > _CutOff)
{
return color;
}
else
{
return static_color;
}并返回一个纹理,可以从c#代码以类似于mats[1].SetTexture("_MainTex", mats[0].GetTexture("_MainTex"));的方式传递给下一个着色器。
发布于 2012-11-01 13:21:12
但是..。您可能不希望只修改纹理的着色器。
为什么不行?这是一种常见的做法。
查看Graphics.Blit.它基本上画了一个四边形与材料(包括一个着色器)应用。所以你可以用你的着色器来修改纹理。但纹理必须是RenderTexture。
会是这样的:
var mat = new Material(Shader.Find("My Shader"));
var output = new RenderTexture(...);
Graphics.Blit(sourceTexture, output, mat);在这种情况下,sourceTexture将绑定到_MainTex of My Shader。
https://stackoverflow.com/questions/13147652
复制相似问题