laurenth-personal / lightmap-switching-tool

Tool that allows switching different baked lightmap sets on a unity scene at runtime.
MIT License
657 stars 88 forks source link

Lightmap Static Batching Issue #21

Closed raychevallier closed 5 years ago

raychevallier commented 5 years ago

Hello, I am using your Lightmap Tool because Unity doesn't utilize Culling Masks when it comes to baking GI.

My Scenario using your Litemap Switching Tool: I am using one single scene to hold both indoor and outdoor environments. My player is outside part of the game and can enter caves and then exit again to the same outdoor environment. When player is outdoors I load the outdoor lightmaps and when in caves I load the cave lighting Lightmaps.

Here is where I run into problems. I am using static batching because this game is for mobile and I am trying to optimize it. Static batching is interfering with your lightmap tool. The UV2 cordinates get out of whack. But if I don't static batch it works great.

Here is how I am baking my scene. I am baking the lightmaps in sections so I end up with two sets of lightmaps. Outdoor and Cave. I don't need cave lighting lightmaps on my outdoor enviroment so when I bake the cave lighting I turn off all outdoor game objects and then bake(so only cave gameobjecst are baked). I then bake the same for the outdoor gameobjects and turn off all cave gameobjects. If I didn't do this my amount of lightmaps would double for lightmaps that will never be seen.

So I now have two set of lightmaps. Outdoor and Cave.

For whatever reason when Static Batching is On the outdoor lightmaps UV2 coordinates are not correct. But the cave UV2 coordinates seem to be fine.

My outdoor enviroment is much larger than the cave enviroment. Don't know if that is causing an issue?

Thanks for any help.

raychevallier commented 5 years ago

Update to Original Post: I changed the "lighting Scenario Scenes" order in the Level Lightmap Data Inspector and the lightmaps UV's worked correctly. I only have two different lighting scenarios so I just reversed the order. I personally do not understand why but it worked. As an experiment I switched back to the original Scenario order and it went back to the initial problem of incorrect lighting UV's.

laurenth-personal commented 5 years ago

Hi, Thanks for taking the time to report all of this. The switching tool changes per meshrenderer the lightmap index scale and offset. That is not possible to do after objects get batched together. It is best when the lightmap index scale and offset don't change between the 2 lighting scenarios, so you switch the lightmap but each object is located at the same space in that lightmap.

The reason why you have more lightmaps using the tool is because it generates 2 full set of lightmaps, even the outdoor will get its lightmap generated with the indoor lighting. The thing in your case is that you are not trying to switch between 2 lighting scenarios but rather switching from an environment to another. There might be a simpler way to do that.

Are there moments where you can see the outdoor from the cave ? do you have a seam in your lightmaps ? A simpler solution could be to move the cave under the ground for instance, box it up with black cubes, generate lighting, and then move it to the correct location before you play. An even simpler solution could be to have a black plane that blocks the lighting from outside, and that you delete before you play.

It's a bit hard to guess what could work for you without seeing the project but I hope this helps.

laurenth-personal commented 5 years ago

If you have a different set of objects enabled for each bake, that will give you different lightmap index / scale and offset that cannot be changed with static batching. One way to solve that is to keep all objects for both bakes, assign different lightmap parameters (using baked tag >documentation) to the cave objects and the outdoors objects so they are not in the same lightmap, and after the bake resize the unnecessary lightmaps to a really small size.

raychevallier commented 5 years ago

Thanks for the reply. Took me awhile to get back to you because I moved onto another issue. But now I am back trying to resolve this one.

Regarding your response: A simpler solution could be to move the cave under the ground for instance, box it up with black cubes, generate lighting, and then move it to the correct location before you play. An even simpler solution could be to have a black plane that blocks the lighting from outside, and that you delete before you play.

I have tried both of these tricks but I get leaking light from the outside. I have boxed up the cave completely with a cube and it still gets about 30% brighter when I bake with the outside directional lights on. I have read this is an issue with Unity.

If there is no fix for leaking lights I have no choice but to go with different lightmaps.

Thanks, Raymond

On Tue, Aug 7, 2018 at 2:09 AM Laurent notifications@github.com wrote:

If you have a different set of objects enabled for each bake, that will give you different lightmap index / scale and offset that cannot be changed with static batching. One way to solve that is to keep all objects for both bakes, assign different lightmap parameters (using baked tag

documentation https://docs.unity3d.com/Manual/class-LightmapParameters.html) to the cave objects and the outdoors objects so they are not in the same lightmap, and after the bake resize the unnecessary lightmaps to a really small size.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/laurenth-unity/lightmap-switching-tool/issues/21#issuecomment-410989152, or mute the thread https://github.com/notifications/unsubscribe-auth/AoJZBrjdGTQcqPIKNa4HTwx2irlMc_2Eks5uOVlngaJpZM4VvNpF .

-- Raymond Chevallier Illustrator I Graphic Designer

T: 626-826-4339 E: chevallierdesigns@gmail.com chevallier.illustrator@gmail.com www.raymondchevallier.com http://www.raymondchevallier.com/

laurenth-personal commented 5 years ago

Hi, thanks for your answer. Would you have a link to that unity bug with light leaking ? I could check if there is a fix in flight.

raychevallier commented 5 years ago

Hello,

I attached two images. Not sure if this is considered light leaking or not.

Outside lights are two directional lights.

The Cave is completely enclosed in two boxes. One box with reversed normal's. and a slightly bigger box with regular normal's.

But Light Still Gets In. [image: Cave_Outside Lights ON.jpg] [image: Cave_Outside Lights Off.jpg]

And Here is an Image with NO BOX. This below picture illustrates that the when I have an enclosing box it does block some of the light (compare it with the first image). [image: Cave_NO BOX_Outside Lights ON.jpg]

Thanks for your suggestions. I have read several other posts where people have lights shining through walls. There doesn't seem to be a good fix.

Raymond

On Tue, Aug 14, 2018 at 12:41 AM Laurent notifications@github.com wrote:

Hi, thanks for your answer. Would you have a link to that unity bug with light leaking ? I could check if there is a fix in flight.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/laurenth-unity/lightmap-switching-tool/issues/21#issuecomment-412783387, or mute the thread https://github.com/notifications/unsubscribe-auth/AoJZBmrlJIYdXqNAPio45O1tf8O_UzVAks5uQn9BgaJpZM4VvNpF .

-- Raymond Chevallier Illustrator I Graphic Designer

T: 626-826-4339 E: chevallierdesigns@gmail.com chevallier.illustrator@gmail.com www.raymondchevallier.com http://www.raymondchevallier.com/

raychevallier commented 5 years ago

Update to last email.

Realized the square pillar in center of water and the other grey path to the doorway did not have "receive shadows" on them. But this still does not fix overall issue of the scene getting brighter.

Even added a very thick cubed wall but same results.

Thanks, Raymond

On Tue, Aug 14, 2018 at 8:48 AM Raymond Chevallier < chevallierdesigns@gmail.com> wrote:

Hello,

I attached two images. Not sure if this is considered light leaking or not.

Outside lights are two directional lights.

The Cave is completely enclosed in two boxes. One box with reversed normal's. and a slightly bigger box with regular normal's.

But Light Still Gets In. [image: Cave_Outside Lights ON.jpg] [image: Cave_Outside Lights Off.jpg]

And Here is an Image with NO BOX. This below picture illustrates that the when I have an enclosing box it does block some of the light (compare it with the first image). [image: Cave_NO BOX_Outside Lights ON.jpg]

Thanks for your suggestions. I have read several other posts where people have lights shining through walls. There doesn't seem to be a good fix.

Raymond

On Tue, Aug 14, 2018 at 12:41 AM Laurent notifications@github.com wrote:

Hi, thanks for your answer. Would you have a link to that unity bug with light leaking ? I could check if there is a fix in flight.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/laurenth-unity/lightmap-switching-tool/issues/21#issuecomment-412783387, or mute the thread https://github.com/notifications/unsubscribe-auth/AoJZBmrlJIYdXqNAPio45O1tf8O_UzVAks5uQn9BgaJpZM4VvNpF .

-- Raymond Chevallier Illustrator I Graphic Designer

T: 626-826-4339 E: chevallierdesigns@gmail.com chevallier.illustrator@gmail.com www.raymondchevallier.com http://www.raymondchevallier.com/

-- Raymond Chevallier Illustrator I Graphic Designer

T: 626-826-4339 E: chevallierdesigns@gmail.com chevallier.illustrator@gmail.com www.raymondchevallier.com http://www.raymondchevallier.com/

laurenth-personal commented 5 years ago

Hi Raymond, it looks like your images didn't come through, could you send a google drive link or something like that so I can see them ? Also you mentioned having read about that leaking issue in Unity, could you tell me where ? is that on a forum ? or in the unity bug reports ?

raychevallier commented 5 years ago

Hello Laurent,

I sent you a link to a file on Google Drive. Let me know if it did not go through.

Thanks, Raymond

On Tue, Aug 14, 2018 at 1:59 PM Laurent notifications@github.com wrote:

Hi Raymond, it looks like your images didn't come through, could you send a google drive link or something like that so I can see them ? Also you mentioned having read about that leaking issue in Unity, could you tell me where ? is that on a forum ? or in the unity bug reports ?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/laurenth-unity/lightmap-switching-tool/issues/21#issuecomment-413014189, or mute the thread https://github.com/notifications/unsubscribe-auth/AoJZBmv34DSvlAN8Sj9ZIHEeh8vCaABHks5uQzpFgaJpZM4VvNpF .

-- Raymond Chevallier Illustrator I Graphic Designer

T: 626-826-4339 E: chevallierdesigns@gmail.com chevallier.illustrator@gmail.com www.raymondchevallier.com http://www.raymondchevallier.com/

laurenth-personal commented 5 years ago

Hi Raymond, I am not sure where you sent the link. If you're just replying to github's emails you're probably not seeing this thread as it appears on github. Please check out the github thread : https://github.com/laurenth-unity/lightmap-switching-tool/issues/21