简单的光照贴图

Shader "Custom/LightMap"
{
    Properties
    {
        _Color("Base Color", Color) = (1,1,1,1)
        _MainTex("Base(RGB)", 2D) = "white" {}
        _LightMap("LightMap", 2D) = "white" {}
    }
    
    SubShader
    {
        tags{"Queue" = "Transparent" "RenderType" = "Transparent" "IgnoreProjector" = "True"}
        Blend SrcAlpha OneMinusSrcAlpha
        
        Pass
        {
            
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"
            
            float4 _Color;
            sampler2D _MainTex;
            sampler2D _LightMap;
            
            struct v2f
            {
                float4 pos:POSITION;
                float4 uv:TEXCOORD0;
                float2 uvLM:TEXCOORD1;
            };
            
            v2f vert(appdata_full v)
            {
                v2f o;
                o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
                o.uv = v.texcoord;
                o.uvLM = v.texcoord1.xy;
                return o;
            }
            
            half4 frag(v2f i):COLOR
            {    
                half4 c = tex2D(_MainTex , i.uv.xy) * _Color;
                half3 l = 2.0 * tex2D(_LightMap, i.uvLM).rgb;
                //half4 lm= tex2D(_LightMap, i.uvLM);
                //half3 l = 8.0 * lm.a * lm.rgb;
                c.rgb *= l;
                
                return c;
            }
            
            ENDCG
        }
    }
}
一直想把之前工作、学习时记录的文档整理到博客上,一方面温故而知新,一方面和大家一起学习 -程序小白
原文地址:https://www.cnblogs.com/wang-jin-fu/p/8279683.html