// Upgrade NOTE: commented out 'float4 unity_LightmapST', a built-in variable // Upgrade NOTE: commented out 'sampler2D unity_Lightmap', a built-in variable
// Upgrade NOTE: replaced tex2D unity_Lightmap with UNITY_SAMPLE_TEX2D
Shader "Test/FragmentLightmap" { Properties { _MainTex ("Texture", 2D) = "white" {} _Tile01("Lightmap R(U) Tiling", Range(-0.01, 0.01)) = 0 _Tile02("Lightmap R(V) Tiling", Range(-0.01, 0.01)) = 0 _Tile03("Lightmap G(U) Tiling", Range(-0.01, 0.01)) = 0 _Tile04("Lightmap G(V) Tiling", Range(-0.01, 0.01)) = 0 _Tile05("Lightmap B(U) Tiling", Range(-0.01, 0.01)) = 0 _Tile06("Lightmap B(V) Tiling", Range(-0.01, 0.01)) = 0 }
SubShader {
Tags { "RenderType"="Opaque" } LOD 100
Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag // make fog work #pragma multi_compile_fog #pragma multi_compile _ LIGHTMAP_ON // multi compie로 분기를 걸지 않을 경우 적용 shader는 무조건 Lightmap 적용을 받는다.(index를 어떻게 가져오는지는 아직 못봄) #include "UnityCG.cginc" struct vertexInput { float4 vertex : POSITION; float2 uv : TEXCOORD0; float2 uv2 : TEXCOORD1; // float4 tangent : TANGENT; // float3 normal : NORMAL; // fixed4 color : COLOR; UNITY_VERTEX_INPUT_INSTANCE_ID };
struct vertexOutput // or appdata_full { float4 vertex : SV_POSITION; float2 uv : TEXCOORD0; float2 uv2 : TEXCOORD1; //fixed4 color : COLOR; UNITY_FOG_COORDS(2) };
sampler2D _MainTex; float4 _MainTex_ST; // sampler2D unity_Lightmap; // float4 unity_LightmapST; // 유니티 버젼업으로, built-in으로 변경 float _Tile01; float _Tile02; float _Tile03; float _Tile04; float _Tile05; float _Tile06; vertexOutput vert(vertexInput v) { vertexOutput o; o.vertex = UnityObjectToClipPos(v.vertex); //o.uv = TRANSFORM_TEX(v.uv.xy, _MainTex); o.uv = (v.uv.xy * _MainTex_ST.xy) + float2(_MainTex_ST.z, _MainTex_ST.w); o.uv2 = v.uv2.xy * unity_LightmapST.xy + unity_LightmapST.zw; UNITY_TRANSFER_FOG(o,o.vertex);
return o; }
fixed4 frag (vertexOutput i) : SV_Target { fixed4 col = tex2D(_MainTex, i.uv); #ifdef LIGHTMAP_ON //col.rgb *= (DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, i.uv2.xy))) ;
col.rgb *= fixed3(
(UNITY_SAMPLE_TEX2D(unity_Lightmap, float2(i.uv2.x + _Tile01, i.uv2.y + _Tile02)).r), (UNITY_SAMPLE_TEX2D(unity_Lightmap, float2(i.uv2.x + _Tile03, i.uv2.y + _Tile04)).g), (UNITY_SAMPLE_TEX2D(unity_Lightmap, float2(i.uv2.x + _Tile05, i.uv2.y + _Tile06)).b));
#endif
// apply fog UNITY_APPLY_FOG(i.fogCoord, col); return col; } ENDCG } } }
|