I’m trying to figure out how to correctly setup a baked directional light which casts shadows and how it works.
Please correct me if I’m wrong:
Shadowmap for baked lights is generated once after I call pc.Lightmapper.bake(). Resolution of the shadow map is equal to pc.LightComponent.shadowResolution (What happens if I have more lights with different shadowResolution. Does engine generate a shadow map for every light in the scene?)
Shadows in shadow map are generated only for object in a particular distance which is somehow detemined by pc.LightCompoment.shadowDistance. According to API docs “shadowDistance” is the distance from the viewpoint beyond which shadows are no longer rendered. This is true for shadows casted by nonbaked lights, but it’s definitely not true for shadows generated by runtime lightmaps. According to my tests position of viewpoint (camera) doesn’t affect shadows casted by baked lights at all. So what exactly is “shadowDistance” for baked lights, from which point is this distance measured?
So, according to my understanding I can use baked lights in a scene with a fixed size, where I’m able to set correct values for “shadowResolution” and “shadowDistance” and the scene is rather small so shadows wouldn’t be so blurry. But if my scene is big or has an unlimited size, I won’t be able to use baked lights. How should I proceed if my scene is big, I want shadows but I can’t use dynamic shadows because they are slow on mobiles? Is there a solution for this problem?
The way the lightMapper works is by looping through the list of all your baked lights and doing light accumulation and shadowmapping using the same methods the realtime renderer uses.
The difference is that shadows aren’t rendered from the active camera’s perspective, but a special camera is used that is placed each time at the center of a calculated bounding box. The engine calculates that so the camera “sees” the rendered models each time.
Here is the relevant piece of code to understand better what’s going on behind the hood:
Both the shadow resolution and shadow distance are still being used and affect the end result, though since it’s a different camera each time, that happens not the same way as when you are using realtime shadows.
For a bigger scene, to get better quality shadows I think the answer would be use more lights. Lightmaps generation might take more time but there isn’t any limit there.