+28
W trakcie analizy

Lightmap support for Custom Lighting Shader

CosmosTBear 11 lat temu Ostatnio zmodyfikowane przez Cindy Byrd 5 dni temu 21
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!
Odpowiedź
W trakcie analizy
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?
+1
IMHO, it should simply be a Decode Lightmap node which adds the following code :
Vertex Input Struct :
#ifdef LIGHTMAP_ON
half4 texcoord1 : TEXCOORD1;
#endif

Frag Input Struct :
#ifdef LIGHTMAP_ON
half2 uv2 : TEXCOORD1;
#endif

Shader Variables :
#ifdef LIGHTMAP_ON
fixed4 unity_LightmapST;
sampler2D unity_Lightmap;
#endif

Vert Function :
#ifdef LIGHTMAP_ON
o.uv2 = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
#endif

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

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

float3 lightmap = float3(1, 1, 1);
#ifdef LIGHTMAP_ON
lightmap = DecodeLightmap(tex2D(unity_Lightmap, i.uv2));
#endif
//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



+1
Any more news on this topic? I'd love to have lightmap functionality on my custom shaders.
+2
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?
-1
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.
+5
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.
+2

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

Contact Dr. Excellent for relationship problems!!

Everything I’m going to suggest for you is what I’ve seen breathe new life into broken marriages for thousands of women in your distressing situation—and what I did to revitalize my own broken marriage. I was heart broken when my husband left me and moved to California to be with another woman. I felt my life was over and my kids thought they would never see their father again. I tried to be strong just for the kids but I could not control the pains that tormented my heart, my heart was filled with sorrows and pains because I was really in love with my husband. I have tried many options but he did not come back, until i met a friend that directed me to Dr. Excellent a spell caster, who helped me to bring back my husband after 11hours. Me and my husband are living happily together again, This man is powerful, Contact Dr. Excellent for any kind of spiritual problems or any kind of spell or relationship problems he is capable of making things right for you with no side effect. Here his contact. Call/WhatsApp him at: +2348084273514 "Or email him at: Excellentspellcaster@gmail. com , His website:https://lovespellonline.godaddysites.com