顶点Blinn-Phong.Shader

Blinn-Phong:高光的一种,高光范围更大,更亮

Shader "Custom/Light/BlinnPhongLight"{
    Properties{
        _Diffuse("Diffuse", Color) = (1, 1, 1, 1)
        _Specular("Specular", Color) = (1, 1, 1, 1)
        _Gloss("Gloss", Range(1.0, 255)) = 20
    }

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

            CGPROGRAM

            #include "Lighting.cginc"

            #pragma vertex vert
            #pragma fragment frag

            fixed4 _Diffuse;
            fixed4 _Specular;
            float _Gloss;

            struct a2v{
                float4 pos : POSITION;
                float4 normal : NORMAL;
            };

            struct v2f{
                float4 pos : SV_POSITION;
                fixed3 color : COLOR;
            };

            v2f vert(a2v v){
                v2f o;
                o.pos = mul(UNITY_MATRIX_MVP, v.pos);

                fixed3 worldNormal = normalize(mul(v.normal, (float3x3)_World2Object));

                fixed3 worldLightDir = normalize(_WorldSpaceLightPos0.xyz);

                fixed3 diffuse = _LightColor0.rgb * _Diffuse.rgb * max(0, dot(worldNormal, worldLightDir));

                fixed3 viewDir = normalize(_WorldSpaceCameraPos.xyz - mul(_Object2World, v.pos).xyz);

                fixed3 specular = _LightColor0.rgb * _Specular.rgb * pow(max(0, dot(normalize(viewDir + worldLightDir), worldNormal)), _Gloss);

                o.color = UNITY_LIGHTMODEL_AMBIENT.xyz + diffuse + specular;

                return o;
            }

            fixed4 frag(v2f i) : SV_Target{
                return fixed4(i.color, 1.0);
            }

            ENDCG
        }
    }
    Fallback "Specular"
}

话说片段好麻烦呀。。不想写��

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wdsdsdsds/article/details/52383540
文章标签: shader
个人分类: shader Unity
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

顶点Blinn-Phong.Shader

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭