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"),"");
}

 

 

 

7.相机替换shader

上一篇:Unity EventSystem之美


下一篇:Unity shader 护盾shield的简单实现