材质收到平行光,多个点光源影响

// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
// 材质收到平行光,多个点光源影响
Shader "Custom/TestLightColor0" {

    SubShader {

        Pass{

        Tags{"LightMode"="ForwardBase"}

            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "unitycg.cginc"
            #include "lighting.cginc"
            struct v2f{
                float4 pos:POSITION;
                float3 normal:NORMAL;
                float3 wpos:TEXCOORD0;
            };
            v2f vert(appdata_base v)
            {
                v2f o;
                o.pos=UnityObjectToClipPos(v.vertex);
                o.normal=UnityObjectToWorldNormal(v.normal);
                o.wpos=mul(unity_ObjectToWorld, v.vertex).xyz;
                return o;
            }
            fixed4 frag(v2f IN):COLOR
            {
                float3 N = IN.normal;
                float3 L = normalize(_WorldSpaceLightPos0).xyz;
                float ndotl=saturate(dot(N,L));
                fixed4 col=_LightColor0*ndotl;
                col+=UNITY_LIGHTMODEL_AMBIENT;
                return col;
            }

            ENDCG
        }

        Pass{

            Tags{"LightMode"="ForwardAdd"}

            blend one one
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "unitycg.cginc"
            #include "lighting.cginc"
            struct v2f{
                float4 pos:POSITION;
                float3 normal:NORMAL;
                float3 wpos:TEXCOORD0;
            };
            v2f vert(appdata_tan v)
            {
                v2f o;
                o.pos=UnityObjectToClipPos(v.vertex);
                o.normal=UnityObjectToWorldNormal(v.normal);
                o.wpos=mul(unity_ObjectToWorld, v.vertex).xyz;
                return o;
            }
            fixed4 frag(v2f IN):COLOR
            {
                float3 N = IN.normal;
                float3 L = normalize(_WorldSpaceLightPos0).xyz;
                float ndotl=saturate(dot(N,L));
                float atten=1;
                if(_WorldSpaceLightPos0.w!=0)
                {
                    atten = 1.0/length(_WorldSpaceLightPos0.xyz);
                }

                fixed4 col=_LightColor0*ndotl*atten;
                return col;
            }

            ENDCG
        }
    }
}

你可能感兴趣的:(shader)