7.相机替换shader
作者:互联网
原文:
https://zhuanlan.zhihu.com/p/51080323
shader代码:
Shader "Custom/ReplaceShader"
{
Properties
{
}
SubShader
{
Tags { "RenderType"="ReplaceType" }
pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
struct appdata
{
float4 vertex:POSITION;
float2 texcoord:TEXCOORD;
};
struct v2f
{
float4 pos:SV_POSITION;
float2 uv:TEXCOORD;
};
v2f vert(appdata i)
{
v2f o;
o.pos = UnityObjectToClipPos(i.vertex);
o.uv = i.texcoord;
return o;
}
float4 frag(v2f i):SV_TARGET
{
fixed2 c= i.uv;
fixed col = frac(c.x+c.y);
if(col > 0.5)
{return 1;}
else{return 0;}
}
ENDCG
}
}
FallBack "Diffuse"
}
C#代码:
public void replace()
{
Camera.main.SetReplacementShader(Shader.Find("Custom/ReplaceShader"), "RenderType");
}
public void reset()
{
Camera.main.SetReplacementShader(Shader.Find("Standard"),"");
}
标签:return,uv,vertex,shader,Shader,相机,v2f,float4,替换 来源: https://blog.csdn.net/qq_35179648/article/details/113826896