Skip to content

Instantly share code, notes, and snippets.

@keijiro
Created April 27, 2015 09:13
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save keijiro/a939b8d06332ac2f306c to your computer and use it in GitHub Desktop.
Save keijiro/a939b8d06332ac2f306c to your computer and use it in GitHub Desktop.
Lightmapped unlit shader for Unity 5.
Shader "Custom/Lightmapped Unlit"
{
Properties
{
_MainTex ("Base (RGB)", 2D) = "white" {}
}
CGINCLUDE
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 _MainTex_ST;
struct appdata_t
{
float4 position : POSITION;
float2 texcoord0 : TEXCOORD0;
float2 texcoord1 : TEXCOORD1;
};
struct v2f
{
float4 position : SV_POSITION;
float2 texcoord0 : TEXCOORD0;
float2 texcoord1 : TEXCOORD1;
UNITY_FOG_COORDS(2)
};
v2f vert(appdata_t v)
{
v2f o;
o.position = mul(UNITY_MATRIX_MVP, v.position);
o.texcoord0 = TRANSFORM_TEX(v.texcoord0, _MainTex);
o.texcoord1 = v.texcoord1 * unity_LightmapST.xy + unity_LightmapST.zw;
UNITY_TRANSFER_FOG(o, o.position);
return o;
}
fixed4 frag_ldr(v2f i) : SV_Target
{
fixed4 lm = UNITY_SAMPLE_TEX2D(unity_Lightmap, i.texcoord1);
fixed4 col = tex2D(_MainTex, i.texcoord0) * lm * 2.0;
UNITY_APPLY_FOG_COLOR(i.fogCoord, col, (fixed4)0);
return col;
}
fixed4 frag_rgbm(v2f i) : SV_Target
{
half4 lm = UNITY_SAMPLE_TEX2D(unity_Lightmap, i.texcoord1);
fixed4 col = tex2D(_MainTex, i.texcoord0) * lm * lm.a * 8;
UNITY_APPLY_FOG_COLOR(i.fogCoord, col, (fixed4)0);
return col;
}
ENDCG
SubShader
{
Tags { "RenderType"="Opaque" }
Pass
{
Tags { "LightMode" = "VertexLM" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag_ldr
#pragma multi_compile_fog
ENDCG
}
Pass
{
Tags { "LightMode" = "VertexLMRGBM" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag_rgbm
#pragma multi_compile_fog
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment