Request: Custom Lightmapping Model Example

The legacy documentation explains that the deferred rendering pipeline applies Dual Lightmaps with custom lighting functions of the following form:

  • half4 Lighting_DualLightmap (SurfaceOutput s, fixed4 totalColor, fixed4 indirectOnlyColor, half indirectFade); This is used for light models that are not view direction dependent (e.g. diffuse).

  • half4 Lighting_DualLightmap (SurfaceOutput s, fixed4 totalColor, fixed4 indirectOnlyColor, half indirectFade, half3 viewDir); This is used for light models that are view direction dependent.

I need to implement a custom lightmapping model that has a very slight deviation from the built-in result. Though I know how to replace the model, I don’t know what the built-in model actually is (how the inputs are combined and what is returned). Could someone from Unity please reply with an example of the 4.6 built-in DualLightmap function?

Thank you.

TL;DR: What is the implementation of Unity 4.6’s LightingBlinnPhong_DualLightmap function? It is lacking from the Lighting.cginc file and is not published as far as I can tell.

I’m having trouble getting any custom lighting model to work for surface shaders in 5.0. Unless I’m screwing something up, nothing is working for me.

Here, I posted what we did for unity 4.5+ and it works perfectly. However, this is broken on Unity 5.

I spent a few days on this and with some help from Unity, I was able to rework things. In a nutshell, I had to basically define my own _GI function.

Start by getting the debug code from a built in shader, copy paste this function found in UnityGlobalIllumination.cginc

inline UnityGI UnityGlobalIllumination (UnityGIInput data, half occlusion, half oneMinusRoughness, half3 normalWorld, bool reflections)

into your shader and give it a new name. That’s where you want to start making mods. Then, any function, like lightmap decoding and calcs, that you need to customize, do the same: Find unity’s version in the shaders, cut/paste then rename the function. Make sure you call your customized lightmap functions from your version of the UnityGlobalIllumination function, then repeat as necessary. It is really tough though and you have to make a small change, test and repeat or you’ll quickly get lost due to minimal error reporting in the editor. It’s just tedious.

I was able to add specular highlights to the Directional lightmaps without having to use Directiona Specular bakes to gain some performance. (albeit with some artifacts in certain spots that aren’t noticeable in our game.)