Shader "AP01/L08/OldSchoolPlus" {
    Properties {
        _BaseCol    ("Primary color",      Color)          = (0.5.0.5.0.5.1.0)
        _LightCol   ("Color of light",      Color)          = (1.0.1.0.1.0.1.0)
        _SpecPow    ("High light power".Range(1.90=))30
        _Occlusion  ("AO map".2D)             = "white" {}
        _EnvInt     ("Ambient light Intensity".Range(0.1=))0.2
        _EnvUpCol   ("Ambient zenith color", Color)          = (1.0.1.0.1.0.1.0)
        _EnvSideCol ("Ambient level color", Color)          = (0.5.0.5.0.5.1.0)
        _EnvDownCol ("Ambient Surface color", Color)          = (0.0.0.0.0.0.0.0)
    }
    SubShader {
        Tags {
            "RenderType"="Opaque"
        }
        Pass {
            Name "FORWARD"
            Tags {
                "LightMode"="ForwardBase"
            }


            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"
            // Append project-related include files
            #include "AutoLight.cginc"
            #include "Lighting.cginc"
            #pragma multi_compile_fwdbase_fullshadows
            #pragmaThe target of 3.0
            // Enter parameters
            uniform float3 _BaseCol;
            uniform float3 _LightCol;
            uniform float _SpecPow;
            uniform sampler2D _Occlusion;
            uniform float _EnvInt;
            uniform float3 _EnvUpCol;
            uniform float3 _EnvSideCol;
            uniform float3 _EnvDownCol;
            // Input structure
            struct VertexInput {
                float4 vertex   : POSITION;   // 开 始 信息
                float4 normal   : NORMAL;     // Open your bookmarks
                float2 uv0      : TEXCOORD0;  // open your eyes
            };
            // Output structure
            struct VertexOutput {
                float4 pos    : SV_POSITION;  // Clipping space vertex positions
                float2 uv0      : TEXCOORD0;    // UV0
                float4 posWS    : TEXCOORD1;    // World space vertex position
                float3 nDirWS   : TEXCOORD2;    // World space normal direction
                LIGHTING_COORDS(3.4)            // Projection correlation
            };
            // Input structure >>> Vertex Shader>>> output structure
            VertexOutput vert (VertexInput v) {
                VertexOutput o = (VertexOutput)0;                   // Create an output structure
                    o.pos = UnityObjectToClipPos( v.vertex );       // Change vertex position OS>CS
                    o.uv0 = v.uv0;                                  / / pass the UV
                    o.posWS = mul(unity_ObjectToWorld, v.vertex);   // Change vertex position OS>WS
                    o.nDirWS = UnityObjectToWorldNormal(v.normal);  // change normal direction OS>WS
                    TRANSFER_VERTEX_TO_FRAGMENT(o)                  // Projection correlation
                return o;                                           // Returns the output structure
            }
            // Output structure >>> pixels
            float4 frag(VertexOutput i) : COLOR {
                // Prepare the vector
                float3 nDir = normalize(i.nDirWS);
                float3 lDir = _WorldSpaceLightPos0.xyz;
                float3 vDir = normalize(_WorldSpaceCameraPos.xyz - i.posWS.xyz);
                float3 rDir = reflect(-lDir, nDir);

                // Prepare the dot product result
                float ndotl = dot(nDir, lDir);
                float vdotr = dot(vDir, rDir);

                // Lighting model (direct lighting part)
                float shadow = LIGHT_ATTENUATION(i);        // Get the projection
                float lambert = max(0.0, ndotl);
                float phong = pow(max(0.0, vdotr), _SpecPow);
                float3 dirLighting = (_BaseCol * lambert + phong) * _LightCol * shadow;

                // Lighting model (ambient lighting section)
                float upMask = max(0.0, nDir.g);                // Get the upward-facing part mask
                float downMask = max(0.0, -nDir.g);             // Get the downward part mask
                float sideMask = 1.0 - upMask - downMask;       // Get the side part mask
                // Blend ambient colors
                float3 envCol = _EnvUpCol * upMask + _EnvSideCol * sideMask + _EnvDownCol * downMask;
                float occlusion = tex2D(_Occlusion, i.uv0);         // Sample Occlusion map
                float3 envLighting = envCol * _EnvInt * occlusion;  // Calculate ambient lighting

                // Return the result
                float3 finalRGB = dirLighting + envLighting;
                return float4(finalRGB, 1.0);
            }
            ENDCG
        }
    }
    FallBack "Diffuse"
}
Copy the code