Unity3D Shader描边效果

 

Shader "Custom/RimColor" {
    Properties {
        _MainTex ("Base (RGB)", 2D) = "white" {}
        _RimColor("Rim Color", Color) = (1,1,1,1)
        _RimRang("Rim Range",range(0,1)) = 0.1
    }

    SubShader {

        
        Pass
        {
        Cull Front

        Tags { "Queue" = "Geometry-1" }

        CGPROGRAM

        #include "UnityCG.cginc"

        struct v2f
        {
            float4 vertex:POSITION;
        };

        float4 _RimColor;
        float _RimRang;

        v2f vert(appdata_base  v)
        {
            v2f o;
            fixed4 vertex = v.vertex;
            vertex.xyz+=v.normal.xyz*_RimRang;
            
            o.vertex = mul(UNITY_MATRIX_MVP,vertex);    

            return o;
        }

        fixed4 frag (v2f IN):COLOR
        {    
            return _RimColor;
        }

        #pragma vertex vert
        #pragma fragment frag

        ENDCG
        }

        Pass
        {
        
        CGPROGRAM

            #include "UnityCG.cginc"

            struct v2f
            {
                float4 vertex:POSITION;
                float2 uv:TEXCOORD0;
            };

            sampler2D _MainTex;

            v2f vert(appdata_base  v)
            {
                v2f o;
                o.uv = v.texcoord;
                o.vertex = mul(UNITY_MATRIX_MVP,v.vertex);
            
                return o;
            }

            fixed4 frag (v2f IN):COLOR
            {
                
                fixed4  c =  tex2D(_MainTex, IN.uv);

                return c;
            }

            #pragma vertex vert
            #pragma fragment frag

        ENDCG
        }
    } 
    FallBack "Diffuse"
}

 

posted @ 2017-09-20 14:49  MrBlue  阅读(3562)  评论(0编辑  收藏  举报