shader练习-vertphone

Shader "VertPhone"
{
    Properties
    {
        _MainTex( "颜色贴图", 2D ) = "white"{}
        _Specular( "高光颜色", Color) = (1, 1, 1, 1)
        _Gloss( "光泽度", Range(1,10)) = 4
        _SpecularPow( "高光强度", Range(0,1)) = 1
    }

    SubShader{
        Tags{ "RenderType" = "Opaque"}
        Pass{
            Tags{ "LightMode" = "ForwardBase" }

            CGPROGRAM

                #pragma vertex vert
                #pragma fragment frag

                #pragma multi_compile_fwdbase
                #pragma multi_compile_fog
                #include "UnityCG.cginc"
                #include "Lighting.cginc"

                uniform sampler2D _MainTex;
                uniform fixed4 _Specular;
                uniform half _Gloss;
                uniform half _SpecularPow;
                
                struct v2f{
                    half4 pos :SV_POSITION;
                    half3 worldPos : TEXCOORD0;
                    half2 uv  :TEXCOORD1;
                    half3 normalWorld:TEXCOORD2;
                    UNITY_FOG_COORDS(3)
                };

                v2f vert( appdata_full v)
                {
                    v2f o;
                    o.pos = UnityObjectToClipPos( v.vertex );
                    o.worldPos = mul( unity_ObjectToWorld, v.vertex).xyz;
                    o.uv = v.texcoord;
                    o.normalWorld = normalize( mul( unity_ObjectToWorld, v.normal) );
                    UNITY_TRANSFER_FOG(o,o.pos);
                    return o;
                }

                fixed4 frag( v2f i):SV_Target
                {
                    fixed4 basecolor = tex2D(_MainTex, i.uv);
                    fixed3 ambient = UNITY_LIGHTMODEL_AMBIENT * basecolor;
                    half3 lightdir = normalize( _WorldSpaceLightPos0.xyz );
                    fixed3 diffuse = saturate( dot( normalize( i.normalWorld ) , lightdir ) )* _LightColor0.rgb * basecolor;
                    half3 r = normalize( reflect( -lightdir, i.normalWorld ) );
                    half3 view = normalize( _WorldSpaceCameraPos.xyz-i.worldPos.xyz );
                    fixed3 specular = _SpecularPow * _LightColor0.rgb * _Specular * pow( max(0, dot( r, view )), _Gloss );
                    fixed4 c = fixed4( ambient + diffuse + specular, 1.0);
                    UNITY_APPLY_FOG(i.fogCoord, c);
                    return c;
                }
            ENDCG
        }
    }

}

  

 

转载于:https://www.cnblogs.com/marcher/p/10713077.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值