如何创建一个简单的像素颜色着色器,它采用纹理,应用诸如 mask 之类的东西:
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"));
?
最佳答案
为什么不呢?这是一种常见的做法。But... you might not want to do a shader to only modify a texture.
查看Graphics.Blit。它基本上绘制了一个应用了 Material (包括着色器)的四边形。因此,您可以使用着色器来修改纹理。但纹理必须是RenderTexture。
它会是这样的:
var mat = new Material(Shader.Find("My Shader"));
var output = new RenderTexture(...);
Graphics.Blit(sourceTexture, output, mat);
在这种情况下,sourceTexture 将绑定(bind)到My Shader 的 _MainTex。
关于c# - 如何从 Unity 3d Shaderlab 中的像素着色器返回纹理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13147652/