Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 EricRLA · Aug 06, 2013 at 04:06 PM · guilightinglightmapgui-button

Best way to switch between multiple sets of lightmaps

I have a simple scene with 3 light poles. I have baked out 4 sets of light maps from Vray using IES files (3 sets of light maps for each light being on and a 4th with all 3 lights on). I'm looking for a way to create 4 different GUI buttons to control loading the different sets of light maps to simulate turning the different lights on and off. I have very limited experience with scripting and have seen some different topics on this but I am not sure how to implement them or what would be the best way to do this. Any help would be much appreciated!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by ScottYann · Aug 09, 2013 at 03:22 AM

I have some code that you might be able to adapt to your needs. I wrote a coroutine that downloads an assetbundle that contains lightmaps. The problem I had was lightmaps are scene file specific, so you gotta do some janitorial work to get the mess working when importing your own scenery to the same scene.

 AssetBundle bundle = www.assetBundle;
     GameObject myBackground;
     //print ("originalName " + originalName);
     if (bundle) {
         GameObject background = bundle.Load (originalName, typeof(GameObject)) as GameObject;
     
         //print (background.name);
         myBackground = Instantiate (background, background.transform.position, background.transform.rotation) as GameObject;
         myBackground.SetActive (true);
         myBackground.name = background.name;
 
         if (myBackground.GetComponent<backgroundBehavior> ().LightMapStorage.Length > 0) {
             //print ("got this far");
             int idx = 0; 

             Object[] obj = www.assetBundle.LoadAll ();
             Texture2D[] LMfarTexture;
             Texture2D[] LMnearTexture;
             int numberOfPairs = obj.Length;
     
             LMfarTexture = new Texture2D[numberOfPairs];
     
             foreach (Object o in obj) {
                 if (o.GetType () == typeof(Texture2D)) {
                     if (o.name.Contains ("Lightmap")) {
                         LMfarTexture [idx] = o as Texture2D;
                         idx++;
                     }
                 }
             }
     
             int i = 0;
             LightmapData lmData = new LightmapData ();
             LightmapData[] lmDataSet = new LightmapData [numberOfPairs];
             foreach (Texture texture in LMfarTexture) {
                 lmData = new LightmapData ();
                 lmData.lightmapFar = LMfarTexture [i];
                 lmDataSet [i] = lmData;
                 i++;
             }

         
     
             LightmapSettings.lightmapsMode = LightmapsMode.Single;
             LightmapSettings.lightmaps = lmDataSet;
         
         }


I needed to make a behavior script to deal with the fact that unity was not voluntarily saving my lightmaps as I exported the assetbundle. The "backgroundBehavior" script looks like this:

/////////////// using UnityEngine; using System.Collections;

public class backgroundBehavior : MonoBehaviour { public bool useSunShafts = false; public Material mySkyBoxMaterial; public Vector3 myPosition; public Texture2D[] LightMapStorage;//just a var where we force Unity to save our Lightmaps when we make an asset bundle public bool usingSpaceConstructionSet = false; public Color ambientColor = Color.black;

 // Use this for initialization
 void Start ()
 {
 
 }
 
 void OnEnable ()
 {
     

     
     RenderSettings.ambientLight = ambientColor;
     if (useSunShafts) {
         Camera.main.gameObject.GetComponent<SunShafts> ().enabled = true;    
         Camera.main.gameObject.GetComponent<SunShafts> ().sunTransform = GameObject.Find ("Sun").transform;
     } else {
         if (Camera.main.gameObject.GetComponent<SunShafts> () != null) {
             Camera.main.gameObject.GetComponent<SunShafts> ().enabled = false;
         }
     }
     
     if (usingSpaceConstructionSet) {
         Camera.main.clearFlags = CameraClearFlags.Depth;
         
     } else {
         Camera.main.clearFlags = CameraClearFlags.Skybox;
         RenderSettings.skybox = mySkyBoxMaterial;
     }
     
     
     
     
 }

}

I decided to use single light maps instead of dual. If you want dual you'll have to figure it out on your own as I've never done anything with it.

I hope this helps because this problem had me on a 6 hour google hunt.

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

15 People are following this question.

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

Related Questions

Unity - Stuck in Build 7/11 Light Transport - 1 Job 13 Answers

Why would my baked lights only render for a few seconds? 0 Answers

Can't edit lightmaps. 0 Answers

Lighting Bug/Problem 1 Answer

I have the weirdest lightbaking ever 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