[SOLVED] Some objects being ignored by the lightmapper

Hi,

I’m trying to bake a directional light in my game but it does not work. Models are lighted but shadows are missing and cropped. Here is a simple sample project which demonstrates the issues: https://playcanvas.com/project/657507/overview/lightmaps

There is 1 baked light, 2 boxes and 1 plane which acts as a ground. The boxes and the plane are lightmapped and the boxes cast shadows to lightmaps. But as you can see shadows are not displayed correctly. If I add another box to the scene which is more far away from the center of the scene, its shadow is not displayed at all.

Can anyone help me with this please? Do lightmaps work, because it looks like they are not.

Hi @NokFrt,

When you say shadows are missing and cropped for an object placed far away, could you try increasing the distance in the shadows settings?

I think that all shadow settings are the same for lightmapped lights so most likely the default setting is too small for you test scene.

The “distance” parameter affects even the lightmapped lights, but it affects them very strangely: In the sample project the boxes are very close to the camera, the light’s shadow “distance” is 16 (which is more than enough for dynamic shadows) and The lightmapped shadows are cropped. Even if I set the “distance” to 64, they are still wrong. Sometimes (for example in my game) the best value for the shadow distance is 0, with different value, the shadows disappear much sooner.

Here is another example how strangle is “distance” parameter affects lightmapped shadows:

As you can see the box on the right has wrong shadow but the box in the distance has correct shadow. (the distance parameter is set to 16).

Where is your light entity positioned in this screengrab?

I am trying to replicate what you get but it seems to be working for me. Make sure when you make any change that affects lighting somehow to reload your app or have auto-rebake checked. So lightmaps are generated again.

The light’s position is 0x4x0, but I think it shouldn’t matter where the directional light is positioned because it’s just a directional light. Here is the project: https://playcanvas.com/project/657738/overview/test . I moved the box even more to the distance and its shadow is still visible but the shadow of the right box (which is very close to the camera) is cropped.

Lightmaps are generated at the start of the application, auto-rebake rebaks the light only in the editor.

I understand how light’s shadow distance affects normal dynamic lights, but why it also affects lightmapped lights? They should be baked into a lightmap of lightmapped entity which receives the shadows.

Here is another example:

The light’s shadow distance is 64. First box has position -3.5x0.5x0 and the second box has position 3.5x0.5x0. Shadow of the first box is completely missing.

Project: https://playcanvas.com/project/657746/overview/test2

The shadows distance is calculated from the position in the 3D world of your light/lights, not from the camera’s. So you will have to take that into account when doing your lights setup/positioning.

Playcanvas runtime lightmaps is a cool feature to have, though I don’t feel it is meant as a replacement for a full featured standalone renderer that can do global illumination / indirect lighting / skybox lighting etc.

For your example, if you increase the shadows distance from 16 to 22 the shadow clipping will stop. I don’t know why there is such a difference between realtime and lightmapped shadows.

You could try submitting an issue about that on the github repo, in case there is a bug or to clarify what is going on.

Ok, thank you. I submit an issue on github because there is definitely a bug.

I think shadows distance is calculated from the position of the camera not from the position of the light. You can have a large scene with just one directional light and you will see shadows even if you are really far from the light - the camera’s distance matters.

Yes the camera distance matters, since it will render shadowmaps when the camera is in range to the light (or to the object in case of directional lights).

Directional lights have a distance property to calculate the distance from objects at which shadowmaps will be rendered (or to put it in another way if objects will be included in the rendered shadowmap).

I’m new to this and I’m trying to understand. A directional light shines everywhere with the same power, so I guess its position doesn’t matter only the direction is important. The light has “Distance” parameter and this parameter detemines how far you will see shadows from the position of the camera. For example the distance parameter is set to 16 and I will see shadows even if the camera’s position is for example 200x4x150 and the light’s position is -1000x1000x1000.

You are correct that the directional light shines everywhere, but that is true only for its color (light) factor.

Shadowmaps can’t have an unlimited resolution (due to GPU/VRAM restrictions) so somehow we have to instruct the application on how to approach directional lights with shadows.

The shadows will be rendered for an object (and not the directional light pos) as soon as the camera is close to that object, defined by the shadows distance property. You will notice that the smaller this value the better quality shadows you get, where the bigger this value the more blurry the shadows look.

The reason for this is because the shadowmap has always the same resolution (width/height) but the amount of area it covers gets bigger as the shadow distance increases (imagine a texture getting stretched, less pixels per meter/unit).

For spot/point lights that property is missing and a range property is added to the light that controls the area that is affect by this light.

Thanks for the explanation. So does the directional light’s position matter or not? I think it doesn’t.

For the directional type of light no, you are correct, only for spot and point lights.

Ok, thank you. I just wanted to be sure.

1 Like

So we believe we have fixed the issue some some objects not baking into the lightmap when they should (see the original GH issue and PR).

2 Likes

That’s great news. Thanks a lot :slight_smile:

1 Like