利用镜面反射让游戏闪耀起来 - 创建BlinnPhong高光类型

Shader "CustomBlinnPhong"
{
    Properties
    {
        _MainTex("MianTex", 2D) = "white" {}
        _MainTint("MainTint", Color) = (1, 1, 1, 1)
        _SpecularColor("SpecularColor", Color) = (1, 1, 1, 1)
        _SpecPower("SpecPower", Range(0, 30)) = 1
    }

    SubShader
    {
        Tags
        {
            "RenderType" = "Opaque"
        }

        LOD 200

        CGPROGRAM

        #pragma surface surf CustomBlinnPhong

        sampler2D _MainTex;
        float4 _MainTint;
        float4 _SpecularColor;
        float _SpecPower;

        inline half4 LightingCustomBlinnPhong(SurfaceOutput s, fixed3 lightDir, fixed3 viewDir, fixed atten)
        {
            float3 halfVector = normalize(lightDir + viewDir);

            float diff = max(0, dot(s.Normal, lightDir));

            float nh = max(0, dot(s.Normal, halfVector));

            float spec = pow(nh, _SpecPower) * _SpecularColor;

            float4 c; 

            c.rgb = (s.Albedo * diff * _LightColor0.rgb) + (_SpecularColor.rgb * spec * _LightColor0) * (atten * 2);
            c.a = s.Alpha;

            return c;
        }

        struct Input
        {
            float2 uv_MainTex;
        };

        void surf(Input IN, inout SurfaceOutput o)
        {
            fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _MainTint;

            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }
        ENDCG
    }
}

你可能感兴趣的:(读书笔记:《Unity,Shaders,and,Effects,Cookbook》)