+1
Fixed

Alpha Clip & Lightmap generate incorrect shadows

rcalt2vt 10 years ago updated by Freya Holmér (Developer) 10 years ago 11
I'm still on 4.2.2f so some of this might not still be an issue for 4.3.X and I understand that it may or may not be fixed.

Using the provided Vegetation shader example:
  1. Edit shader > Enable Lightmap support > Compile
  2. Shader Compile Errors:
    1. Shader error in 'Shader Forge/Examples/ClipAndTransmission': Program 'vert', unexpected #endif (compiling for d3d11) at line 17
  3. Edit shader > Disable OpenGL > Compile
  4. Shader Compile Warnings:
    1. Shader warning in 'Shader Forge/Examples/ClipAndTransmission': Program 'vert', unexpected #endif (compiling for d3d11) at line 17
    2. Shader warning in 'Shader Forge/Examples/ClipAndTransmission': Program 'vert', implicit truncation of vector type (compiling for d3d11) at line 38
    3. Shader warning in 'Shader Forge/Examples/ClipAndTransmission': GLSL preprocess error: Unmatched #endif at line 132
  5. Set object using Vegetation shader and ground shadow will cast on to Static > Bake Lightmap (Single Lightmap)
  6. Bake Lightmap Error:
    1. Material doesn't have a texture property '_MainTex'
  7. Edit shader > Rename "Diffuse" property to "MainTex" > Compile > Bake Lightmap (Single Lightmap)
At this point, the Lightmap finally bakes without any errors thrown, however the shadow for this object is incorrect as it bakes the asset as if it was entirely opaque instead of alpha clip as seen in the attached image.

Image 118

Answer

Answer
Fixed
Can be solved with Robert Briscoe's response below
This is actually a part of a bigger problem! It looks like turning on lightmapping will break your shaders if you're using transmission or light wrapping, which this shader does. I also noticed that the light probe data will be used even when lightmapped, so this turned into several issues in one.
(I also moved this from helpdesk to the main forum, marked as a bug)
Tricky. Are you able to get this to work with Unity's built-in shaders?
Yes using the built in Transparent / Cutout / Diffuse shader:

Interesting! (I'm researching why SF doesn't do this at the moment)
Just a thought that popped into my head, but could it be due to the way that SF writes to the depth buffer? IE: doesn't take alpha clip into account, I posted some findings about this in this bug:
http://shaderforge.userecho.com/topic/305397-doubl...
It does take depth into account in all passes available, but I'm suspecting Unity is adding some sort of pass that I haven't accounted for
I just wanted to let you know that the first compile error has now been fixed in 0.19 :)
I rand into this problem a while back and it turned out that it was because Beast only bakes alpha masked shadows for shaders placed in the /Transparent/ Folder. It's a pain in the arse, and i'm not sure if it can be fixed through SF.

One thing that would be nice to add in regards to Lightmapping and SF shaders though is the addition of Transmissive Color. 

More info on this here: http://answers.unity3d.com/questions/49537/can-transparent-textures-be-lightmapped.html?sort=oldest
Awesome, thanks robert.briscoe, that did the trick for the shadows!

Might need an alert in SF or something to tell users this.
The Beast implementation seems more and more hacked in. Unity could use a proper lightmapping solution, this is just an interface design nightmare.

I will have to add a console to SF that displays warnings like this
Answer
Fixed
Can be solved with Robert Briscoe's response below
What about adding an option to set Transmissive Color in SF for Lightmaps? Perhaps it could just detect a colour node plugged into the transmission input in the editor and use that?