Ayfel / PrefabLightmapping

Script for saving lightmapping data to prefabs. Used through the Assets tab in Unity. Place your prefbas in the scene with this script at the root. Set up your lighting and in the editor go to Assets->Bake Prefab Lightmaps. After is processed you can now spawn your prefabs in different scenes and they will use the lightmapping from the original scene.
645 stars 90 forks source link

Light probes in Interior scenes #51

Open MadPsyren opened 2 years ago

MadPsyren commented 2 years ago

Hey, Thanks so much for this. It is a life saver so far.

Began playing with the light probes (massive thanks for getting that working!), but had an issue with using them in an interior scene. Since the light probes pick up every light within range, light from one room was contributing to the probes in adjacent rooms.

Got a workaround I think after a bit of experimenting. I'm fairly new to Unity so not sure if this is the best way to do it.

               int layerMask = ~LayerMask.GetMask("Furniture");
               for (int i = 0; i < probeCount; i++)
                {
                    if (!Physics.Linecast(probePositions[i], l.transform.position, layerMask))
                    {
                        SHAddPointLight(probePositions[i], l.transform.position, l.range, l.color, l.intensity, ref bakedProbes[i]);
                    }
                    else
                    {
                        SHAddPointLight(probePositions[i], l.transform.position, l.range, l.color, l.intensity * 0, ref bakedProbes[i]);
                    }
                }

Basically, this checks if the light probe has line of sight with the point light. Also added a layermask so it ignores the furniture in the rooms. This way, the script can check if there is a wall in the way of the point light, and if there is, it reduces the intensity of that point light to zero for the probe. Only lights within the same room will contribute to the probes.

Not noticed any major impact to performance and it looks like it works. Any issues with this solution do you think? Another issue I had was the light probes were too bright, so just divided intensity by 4 and that seems closer. Prob something to do with my lightmap being dark.

And is it possible to add spot lights and area lights maybe? :D

Many thanks again

Ayfel commented 2 years ago

That looks like a good idea for your usecase I think it should be no problem. There should be a better way without having to rely on colliders and if I find it I should add it to the repo. As for other lights I would like to test those and see if it works as well although there might be issues due to their shapes.