码迷,mamicode.com
首页 > 其他好文 > 详细

简单的光照贴图

时间:2018-01-13 18:53:16      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:appdata   2.0   blend   ret   include   str   vlm   ade   log   

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
        }
    }
}

 

简单的光照贴图

标签:appdata   2.0   blend   ret   include   str   vlm   ade   log   

原文地址:https://www.cnblogs.com/wang-jin-fu/p/8279683.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!