Under review
CosmosTBear 3 years ago • updated by Chun Zhu 11 months ago 19
It would be nice to have a non gray out checkbox for Lightmap support under the lighting tab like with Bling-Phong for the Custom Lighting...
Or maybe a tutorial on how to decode lightmap with custom lighting would be great!
This is a bit of a tricky thing, because it comes down to - how do we want to handle lightmapping?

Should lightmapping simply always be a replacement for light direction and light color, or should they be separate nodes?
IMHO, it should simply be a Decode Lightmap node which adds the following code :
Vertex Input Struct :
half4 texcoord1 : TEXCOORD1;

Frag Input Struct :
half2 uv2 : TEXCOORD1;

Shader Variables :
fixed4 unity_LightmapST;
sampler2D unity_Lightmap;

Vert Function :
o.uv2 = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;

Frag Function :
fixed3 lightmap = DecodeLightmap(tex2D(unity_Lightmap, i.uv2));
// execute whatever you want to do with lightmap here

However, it would have to handle the fact that LIGHTMAP_ON might be false.
actually, it could only be:

float3 lightmap = float3(1, 1, 1);
lightmap = DecodeLightmap(tex2D(unity_Lightmap, i.uv2));
//do whatever

the user could even choose the default color
This would be so useful for doing custom painted shadows in texture maps.
Are there anymore updates on this subject? Not sure how to use the code above. Would be very useful to have light mapping support for custom shaders. Cheers
I've planned to clean up the entire lighting pipeline pretty soon, which, as a side effect, there will be nodes for both lightmap data as well as light probe data
Appreciate the assistance with the example code by the way! 
However, mind that lightmapping is not only a single lightmap decode.

For single lightmaps - yes, that's pretty much it.

But not for dual lightmaps, and not for directional lightmaps.
Dual lightmaps need to handle the blend between direct LM without RT lights, and direct RT lights without direct LM.
Directional lightmaps need to have a separate output for its light direction, which also brings forth a few design issues as well as implementation quirks.

In addition, it needs to handle HDR vs LDR, as well as all of this in deferred rendering in addition to forward rendering

Any more news on this topic? I'd love to have lightmap functionality on my custom shaders.
Not at the moment; I'm still wrapped up in Unite. After Unite, I'll have a look at this :)
Not really, no, and lightmapping got much more complicated as of 5.0 :(
I remember reading a post about how one could get lightmapping to work by naming the nodes correctly. It sounds like this may have changed in the update to 5, however.

Joachim, if it's not too much to ask, would you mind giving a basic run-down of what's changed/why it's more complicated?
The naming restrictions are still there. The problem now is that Unity's pipeline for lightmapping is heavily adapted for PBR specifically, and they've created lots of helper functions and structures that streamline their way of lightmapping things.

The problem arises when you want to do something, well, other than that. Their structures is still what keeps the entire pipeline running and if you want to break that pipeline out, you have to backtrack all of that code and filter everything for what you need. PBR is very, intertwined, in a way, because for instance, you have to have specularity, PBR doesn't make sense without it. But in Shader Forge, you can choose not to use it. But then you want to still access lightmaps built for a PBR pipe.

Another issue is that lightmapping has several types, which require branching, and custom branching is currently not supported in SF. The most complicated one is the directional lightmapping, which needs to run the entire BRDF twice, which SF doesn't support either.
Unless I missing something I really think the Asset store page should be updated to make it clear that Shader Forge doesn't support lightmapped shaders. Many games in production are still using U4 and enabling the lightmap tag breaks the shader.

I really wish that we had known that it didn't work... this is a great disappointment.

WAIT... Not supported? I thought that's my fault that breaks my custom shaders, until I find this post. Any updates will be appreciated.

Mind that this applies only to custom lighting, and the directional specular lightmap mode. Other than that, lightmapping in SF for non-custom-lighting shaders should work.

Hi, I'm following this tutorials about view direction based lighting (http://acegikmo.com/shaderforge/wiki/index.php?title=View-Direction_Based_Lighting) and the final shader looks great in game. Soon I found I can't use baked point light to light up my scene. After your reply, I realize that we may not be able to bake "View Direction Based" shaders in anyway in fact, is that right?