blinphong光照

来源:互联网 发布:网狐6603捕鱼源码 编辑:程序博客网 时间:2024/04/29 17:02
Shader "Custom/BlinPhong" {    Properties {        _MainTex ("Main Tex", 2D) = "white" {}        _MainTint("Diffuse Tint",Color)=(1,1,1,1)        _SpecularColor("Specular Color",Color)=(1,1,1,1)        _SpecPower("Specular Power",Range(0,30))=1    }    SubShader {        Tags { "RenderType"="opaque" }        LOD 200        CGPROGRAM        // Physically based Standard lighting model, and enable shadows on all light types        #pragma surface surf BlinPhong alpha:fade nolighting        // Use shader model 3.0 target, to get nicer looking lighting        #pragma target 3.0        sampler2D _MainTex;        float4 _MainTint;        float4 _SpecularColor;        float _SpecPower;        struct Input {            float2 uv_MainTex;        };        fixed4 LightingBlinPhong(SurfaceOutput s,fixed3 lightDir,half3 viewDir,fixed atten)        {            float NdotL=max(0,dot(s.Normal,lightDir));            //半角向量            float3 halfVector = normalize(lightDir+viewDir);            float NdotH = max(0,dot(s.Normal,halfVector));            float finalSpec = pow(NdotH,_SpecPower)*_SpecularColor;            //计算最终光照            fixed4 c;            c.rgb = (s.Albedo*_LightColor0.rgb*max(0,NdotL)*atten)+(_LightColor0*finalSpec);            c.a = s.Alpha;            return c;        }        void surf (Input IN, inout SurfaceOutput o) {            fixed4 c = tex2D(_MainTex,IN.uv_MainTex);            o.Albedo = c.rgb;            o.Alpha = c.a;        }        ENDCG    }    FallBack "Diffuse"}
0 0
原创粉丝点击