- Home /
Why is shadow strength always full black (1.0) in lightmap?
Hi
Why is it that shadows are always baked as full strength, even though I set the shadow strength on my light to, say, 0.5?
I've tried many permutations of settings and new projects, but always the same result.
The realtime shadow displays correctly, but of course it means they become darker as I leave the shadow-distance area.
This was asked before, but didn't get an answer:
Shadow-strength-doesnt-matter-in-beast-lightmapping
If this is simply how Beast works, is there another way to get paler shadows?
Thanks
Steve
Just to clarify... using Dual Lightmaps with deferred rendering.
Answer by psantoki · Nov 21, 2013 at 08:57 PM
Beast ignores several Unity settings, including shadow strength and even whether or not an object is marked as a shadow caster. In my game we had to physically disable alpha objects before doing a bake to prevent them from polluting the lightmaps. I chalk this up to sloppy Beast integration in the Unity code.
Onto your shadow strength. In a way, one can understand why shadow strength doesn't make sense to a ray tracer: it's job is to collect light, there's no such thing as shadow strength. To get the look of 50% shadow strength in a ray tracer one would have to make shadow casters 50% translucent or add an ambient light to the scene to bring the overall lighting up.
There is no ambient light in Unity*, however (**actually there is! see below*)
Sky Light. There is a Sky Light in the Lightmapping Bake settings. You need at least one bounce to enable this feature. Sky light isn't exactly an ambient light but for outdoor scenes this can bring your lightmap brightness up.
Bounces. Sufficient bounces fills in shadows by virtue of light scattering. Another way to flood more light into the darks of the lightmaps, but again not the same as ambient light.
Just add ambient light in your shader. In your game shaders instead of tapping the lightmap and using those values directly you can add light to fake shadow strength. You can lerp or do a saturate(lmValue + a) in which a is (1 - shadow strength). This is the most visually correct way to match your dynamic light shadow strength, but it costs instructions in the pixel shader so it's less elegant.
In my game we used pairs of weather settings for in-game and lightmap baking (sunset dynamic, sunset lightmap) specifically so we could tune lighting in lightmap bakes to match the dynamic lighting of the game. There are several reasons besides shadow strength to do this, such as Beast making lightmaps that are brighter than the light source itself which mucks up dynamic highlights.
Ah! There IS an ambient light setting in Unity!
It's under Edit > Render Settings > Ambient Light. Before doing a lightmap bake, just set this to 50% grey (100% - shadow strength)
Remember to unset this before running the game, it affects the dynamic lighting too, thus everything in your shadow-distance area will be extra bright. Another reason to have bake/dynamic weather pairs.
Thanks, interesting read. Although I had already tinkered with ambient light settings, it does flatten things a lot. But the idea of tweaking pre- and then post- baking hadn't occurred to me :) I agree that shadow strength wouldn't be part of a physically accurate algorithm, but as practical 'cheat' to get the final look right, I'm surprised it isn't there as an option as it is in some renderers; after all, the shadow areas are mapped in the normal lighting algorithm, it would be as easy post-bake adjustment to lighten those areas a little.
Your answer
Follow this Question
Related Questions
Can transparent textures be lightmapped? 2 Answers
Realtime shadows on lightmapped surfaces 3 Answers
LightMap: No Shaows on ground? 1 Answer
Lightmapped object in Surface-shader 0 Answers
Shadow is cast through multiple objects 0 Answers