码迷,mamicode.com
首页 > 编程语言 > 详细

Unity3D 边缘高光Shader

时间:2017-08-30 18:34:40      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:osi   http   turn   matrix   include   base   position   src   return   

技术分享

 

Shader "Custom/NewShader" {
    Properties {
        _MainTex ("Base (RGB)", 2D) = "white" {}
        _RimColor("Rim Color", Color) = (1,1,1,1)
        _RimPower ("Rim power",range(0,5)) = 2//边缘强度
    }
    SubShader {
        Pass
        {
        
        CGPROGRAM

        #include "UnityCG.cginc"

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

        sampler2D _MainTex;
        float4 _RimColor;
        float _RimPower;

        v2f vert(appdata_base  v)
        {
            v2f o;
            o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
            o.uv = v.texcoord;
            float3 worldPos = mul(_Object2World, v.vertex).xyz;
            float3 viewdir = normalize((_WorldSpaceCameraPos - worldPos));
            float3 normal = normalize(mul((float3x3)_Object2World,v.normal));
            
            o.rim.x = 1-saturate(dot(viewdir,normal));

            return o;
        }

        fixed4 frag (v2f IN):COLOR
        {
            fixed4  c = tex2D(_MainTex, IN.uv);
            c.rgb+= pow(IN.rim.x,2)*_RimColor*_RimPower;
            return c;
        }

        #pragma vertex vert
        #pragma fragment frag

        ENDCG
        }
    } 
    FallBack "Diffuse"
}

 

Unity3D 边缘高光Shader

标签:osi   http   turn   matrix   include   base   position   src   return   

原文地址:http://www.cnblogs.com/mrblue/p/7454529.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!