Custom lightmap Surface Shader

Hey there,

After couple hours of research and testing, I found the perfect Surface Shader traduction of my old 1.1 Lightmap Shader.
Before, when I used traditional passes, it would be written :

SetTexture [_Selfillum] {
      combine texture +  primary
 } 

SetTexture [_MainTex] {
      combine texture * previous , texture
 }

where _MainTex is your main texture, and _SelfIllum your custom black white lightmap. The more white a zone is, the more self-lit it is, without burning the color or overshooting its lighting (those were the 2 reasons why I didn’t use Emission parameter instead).

So now that Surface Shaders are in, here is how it would be perfectly traduced.
Everything necessary is contained in the surf function :

 void surf (Input IN, inout SurfaceOutput o) {

      half4 _lightmap = tex2D (_Selfillum, IN.uv_MainTex);
      half4 tex = tex2D(_MainTex, IN.uv_MainTex);

          o.Albedo = tex.rgb*(1-_lightmap.rgb);

          o.Emission = tex.rgb*_lightmap.rgb;

          o.Alpha = tex.a;

 }

It’s basically masking the Albedo zones with the Lightmap, as the Emission channel is added over it.

Hope it helps !

edit : I forgot to mention that this Surface Shader should not interfere with Beast lightmaps.

thanks! can you post some pics showing the difference between the old a new surface shader?

Sure ^^

Here, a comparison on a lightly self-lit level :

It’s not very visible here, because the colorburn overshoot effect really expresses itself on highly emissive zones, and when hit by a strong light. The only difference seems to be a smoother feeling overall at the bottom.

Here is a nice proof :

Even dramatically lowering the Emission does no justice, and even messes up the mesh borders which have the same color the same self-light (like the circle on the upper right). It’s because of scene light not reflecting toward the same direction.
Emission is just a color addition to the base lit texture. So basically, putting this (1-_lightmap.rgb) in the base lit layer evens out this addition, creating the correct overall exposure balance.

Hope it helps.


thanks for sharing!