I wasn’t pleased with the build in lightmap shaders, as they still seem to also accept vertex lighting from within unity? Since I am after maximum perfomance, and also don’t use a single unity light, I wrote a new lightmap shader that doesn’t accept those lights.
Now, I am utterly utterly bad at this. Really. I am an artist and I am having a hard time writing these shaders. I did succeed in the end, after hours of messing, and it works exactly like I want it to work, however, I may have done somethings wrong or in a slow way so it would be nice if someone could give it a look and see if it could be speed up further?
I am really after maximum perfomance. However the looks it gives now has to be preserved. I currently added the lightmap onto the texture twice (I think…) which is the intention, with just 1 pass it looked very dull. So I added it again to make it brighter and cooler. I believe I used two passes for this plus a third pass to add the actual texture? This may be rather slow on old hardware?
Thanks!
Shader "Lightmapped/Diffuse2" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_Color2 ("LM Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
_LightMap ("Lightmap (RGB)", 2D) = "lightmap" { LightmapMode }
}
SubShader {
LOD 300
Tags { "RenderType"="Opaque" }
Blend AppSrcAdd AppDstAdd
Fog { Color [_AddFog] }
// Base pass: lightmap
Pass {
Name "BASE"
Tags {"LightMode" = "Always"}
BindChannels {
Bind "Vertex", vertex
Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
}
SetTexture [_LightMap] { constantColor [_Color] combine texture * constant }
}
// Base pass: lightmap
Pass {
Name "BASE"
Tags {"LightMode" = "Always"}
BindChannels {
Bind "Vertex", vertex
Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
}
SetTexture [_LightMap] { constantColor [_Color2] combine texture * constant }
}
// Second pass: modulate with texture
Pass {
Name "BASE"
Tags {"LightMode" = "Always"}
BindChannels {
Bind "Vertex", vertex
Bind "texcoord", texcoord0 // main uses 1st uv
}
Blend Zero SrcColor
SetTexture [_MainTex] { combine texture }
}
}
Fallback "VertexLit", 1
}