Under review

Lightmap support for Custom Lighting Shader

CosmosTBear 10 years ago updated by Demian Ford 2 years ago 20
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 :)
any update on this topic?
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?

I've always dreamt of winning BIG in the lottery. I surfed the internet for help to win the lottery massively and I was directed to the DR Amber website. I had a chat with him about what I needed and he assured me that his spell will make me become a lottery winner. He got back to me after 3 days with the numbers that I needed to play the lottery and told me to believe in myself. I felt enveloped by the control of the spell. I took his words and played the Mega Millions Lottery. Two days later, I was sent an email that I've won the sum of 107 Million Dollars. I was shocked and couldn't believe what my eyes were seeing. Immediately I was given the cash prize, I stopped working. I want to say a very big thank you to DR Amber for helping people like us who really need help. Now I know that there's absolutely nothing too hard for DR Amber to do. To get in touch with him, email : [ amberlottotemple@yahoo.com ] or click his webpage URL___ amberlottotemple.com