In my shader everything seems to be working fine except for shadow blending - what am I missing? What am I doing wrong? What other magical MACROS do I need to use?
In default mobile/diffuse shader the “Realtime Shadow Color” in Lighting/Mixed Lighting controls how much dynamic shadows blends with lightmaps. How can I achieve that?
min() returns the minimum values of A and B - A is my shadow which is completly black (0) and B is the lightmap (other values in range of 0-1). That way this function always returns 0 where my shadow is - this has the exactly same effect as previously.
In Mobile/Diffuse the shadow color and transparency depends on the “Realtime Shadow Color” in Lighting-> Mixed Lighting (Subtractive). If I could somehow ‘connect’ this color picker value to my shader I could probably make the min() function work just by setting shadow other values than black - that would result in blending between those values.
You’re right. The way I did it a while back was I had a script that set my own shadow color with Shader.SetGlobalColor and then I’dd add that to atten. But there probably is a way to get the Realtime Shadow Color as well. I just don’t know it from the top of my head.
I’ve looked inside compiled shader variant for Mobile/Diffuse but there are so many magical Unity macros that ‘do stuff’ that I am pulling my hair out to figure this thing out Did you ever tried to make that work?
I’ve figured out that there is a “unity_ShadowColor” variable and it is responsible for “Realtime Shadow Color” color picker in Lighting → Mixed Lighting (Subtractive).
This works almost well. I can use the “Realtime Shadow Color” to change the ‘blackness’ of the shadows in order to blend them. However using this current formula I am adjusting lightmaps too - this isn’t ideal cause in order for shadows to blend I need to push this color rather far resulting in lightmap losing its darkness and changing overall look. Perfect scenario would be - “Realtime Shadow Color” adjusts only the realtime shadow colors and leave lightmaps out of it.
hey gaxx, thank you so much for this shader. this was exactly what i was looking for.
i had issues to get an unlit lightmp shader to support shadows correctly but thanks to you they work exactly like expected! thumbs up!
Edit:
i checked it a little more deeply and it seems to have some issues with the blending between dynamic received shadows and the lightmap baked shadows
EDIT 2:
i fixed the issues that i had with your shader with these changes:
I’ll check your solution as soon as I’ll dig up that thing - it’s been a while since then.
Thanks for reply
EDIT:
Ok, I did check how this changes would affect and yes, this blends same as Mobile/Diffuse! Great that you solved it!
There are problems with this approach in general. In order to blend correctly between lightmap and dynamic shadows, you need to know the correct color for unity_ShadowColor. Too much black and you have overlapping shadows, too much white and your shadow is not visable. Another problem is when you have multiple levels with different lightning scenarios. This value must be controlled for proper blend. This is unpractical approach unfortunately and propably leave to much free space for errors.