Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by KeithDuck · Jun 24, 2016 at 10:48 PM · bakinglightmaps

How to switch lightmaps in a scene in Unity 5.3.5

I am try to switch from day to night in a scene in Unity that uses lightmaps.

I tried this

 LightmapData[] lightmapData;
 
     void Start (){
         lightmapData = new LightmapData[1];
     }
 
 
     #region Publics
     public void SetToDay(){
         lightmapData[0] = new LightmapData();
         lightmapData[0].lightmapFar = Resources.Load( "Level3/Lightmap-0_comp_light", typeof(Texture2D)) as Texture2D;
         LightmapSettings.lightmaps = lightmapData;
     }
 
     public void SetToNight(){
         lightmapData[0] = new LightmapData();
         lightmapData[0].lightmapFar = Resources.Load( "Level3Night/Lightmap-0_comp_light", typeof(Texture2D)) as Texture2D;
         LightmapSettings.lightmaps = lightmapData;
 
     }

Anyone get switching between two different lightmaps to work in Unity 5?

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Eudaimonium · Jun 26, 2016 at 12:30 AM 0
Share

I don't see how can you share same lightmaps between day and night. That would be completely different lighting, no?

For my purposes I've simply duplicated a scene. The objects such as houses or walls remain the same. Terrain asset is automatically shared when you duplicated the scene asset. I've assigned new lights and skybox to the scenes manually. When you edit some piece of scene, for example buildings or trees, simply copy "CTRL-C" an element, switch scene, delete existing and paste "CTRL-V" new one. Lightbake both scenes. Voila.

alt text

alt text

unitynight.jpg (327.1 kB)
unityday.jpg (456.3 kB)
avatar image leventalpsal Eudaimonium · Dec 01, 2016 at 12:57 PM 0
Share

He doesn't try to share the same lightmap, on the contrary, he wants to use the same scene for day and night, with a lightmap for day and another lightmap for night. When the game switches from day to night, lightmap setting should be switched to night lightmap.

This is exactly what I'm trying to achieve. Anyone succeeded doing this on Unity 5.3+ ??
(The code $$anonymous$$eithDuck shared would probably work on Unity 4.x)

avatar image tomekkie2 · Dec 04, 2016 at 03:39 PM 0
Share

I wrote a simple script and tutorial for this in this post: https://forum.unity3d.com/threads/how-to-create-lightmap-for-day-and-for-night-and-switch-them-in-runtime.319920/#post-2873800

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tomekkie2 · Dec 01, 2016 at 06:30 PM

Suppose you have scene L1, bake lightmaps in it, then duplicate it, name the duplicate scene as "L2", setup new lighting and bake the L2 scene. Unity will create folder L2 containing the lightmaps for the L2 scene. Then create a Resources folder and move the L2 folder to it.

Then the script with function to swap the lightmaps could look very similar to one in the initial question, just like below:

 using UnityEngine;
 using System.Collections;
 
 public class LightmapsSwap : MonoBehaviour {
     void Start () {
         SwapLightmaps();
     }
 
     void SwapLightmaps () {
         LightmapData[] sceneLightmaps = LightmapSettings.lightmaps;
         foreach (LightmapData lmd in sceneLightmaps)
         {
             lmd.lightmapFar = Resources.Load("L2/" + lmd.lightmapFar.name) as Texture2D;
             lmd.lightmapNear = Resources.Load("L2/" + lmd.lightmapNear.name) as Texture2D;
         }
         LightmapSettings.lightmaps = sceneLightmaps;
     }
 }

If these were just normal textures, you wouldn't have to move them to "Resources" and use Resources.Load; you could just use the WWW class.

I have tested it and it works.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to unwrap for light mapping 1 Answer

Lightmaps baking problem 3 Answers

SWAPPING BAKED LIGHTMAPS 0 Answers

Server for baking lights \w Enlighten 0 Answers

realtime light breaks baked GI 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges