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
3
Question by flaco3d · Feb 23, 2011 at 10:05 PM · lightmapswitchreplace

How I can change lightmaps at runtime?

I have an interior scene of a house, and i need to remove furniture with their generated lightmaps at runtime, and replace it with a set of lightmaps baked previously without furniture?

Thanks in advance.

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 Ereptor · Jun 11, 2013 at 06:57 AM 0
Share

Is there a simpler way to do this for objects that are either lit or not lit? Once a lightmap is baked onto an object, how can it be accessed and disabled? (For instance, by a button or axis input?)

I am trying to achieve a spotlight effect (saved in lightmap data) that is only active while an object is selected, otherwise it is unlit.

avatar image Smireles Ereptor · Jun 11, 2013 at 11:58 PM 0
Share

First of all, you shouldn't post questions as Answers. I do not want to sound like a jerk, but there are some protocols that we should follow to keep this awesome tool working as it should:

Video Tutorial for Answers in Unity3d

Second, to achieve what you are ai$$anonymous$$g to do, you have to be aware that every static object in your scene will have a set of Atlas values, you can see those values in your Lightmap window, under Objects/Render tab.

If you do not want to go too much into details, I could suggest you to change the lightmap index value of your desired Render mesh:

 Renderer.lightmapIndex

avatar image Ereptor Ereptor · Jun 12, 2013 at 06:41 AM 0
Share

Oops, sorry. I did not realize this would create a second answer. I see the lightmap renderer for what I'm dealing with now. Also the Atlas (listing this as Lightmap Index 0).

The code that ended up working was something like:

void On$$anonymous$$ouseOver{ renderer.lightmapIndex = 0; }

void On$$anonymous$$ouseExit{ renderer.lightmapIndex = 255; }

Sorry again and thanks for the help!

3 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by liszto · Dec 05, 2012 at 12:20 PM

There is another way to do this. You can change lightmapData at runtime and it's an interesting way that I use in one of my project.

You can do something like this : http://pastebin.com/AqwmSCNE

The lightmapData array is the array which stack all the lightmaps used in your level and you can change them when you want.

For example if you need to change the sun orientation and you want that your lightmap change to you can reset this array with your new lightmaps. All your lightmaps must be baked before btw.

When I want do this, I bake all the lightmaps that I need and I bake them with the same number of lightmaps to avoid all problems with offset and tilling on your meshes.

Indeed, if you baked your lightmaps and if the final lightmaps number is not the same you can have different offset and tilling for every mesh in your scene. So one lightmap will be correctly displayed whereas another one maybe not.

If you need more explanations, don't hesitate I can give you more details ;)

Edit : little script to do this simply ==> http://pastebin.com/23FdBnRU

Comment
Add comment · Show 6 · 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
avatar image anilgautam · Dec 05, 2012 at 12:23 PM 0
Share

Thanks liszto

Can you give me a two lines of script which I can use for my project two just swapping only two lightmaps. I dont want to use array

avatar image Smireles · Jun 06, 2013 at 03:04 PM 0
Share

Oops! Google Chrome could not find pastebin.com RIP pastebin.com...

Anyone with some examples or suggestions?

avatar image liszto · Jun 06, 2013 at 04:54 PM 0
Share

$$anonymous$$y pastebin are limited in time. I will paste it again soon if you need them ;).

avatar image Smireles · Jun 06, 2013 at 05:01 PM 0
Share

I would love it!! Thanks liszto :)

avatar image liszto · Jun 07, 2013 at 05:49 AM 1
Share

It's weird cause on my computer the previous links works :

http://pastebin.com/GayDUvQU (try again with this)

There is an example here too : http://answers.unity3d.com/questions/359301/access-use-lightmap-property-using-script.html

Show more comments
avatar image
1

Answer by efge · Feb 23, 2011 at 10:13 PM

You could define several materials with different lightmaps and change them at runtime. Look at the example here: Renderer.material

Or you could change the texture for the shader. (You have to find the texture name inside the shader, e.g. "_LightMap".)
Here is the example: SetTexture

Comment
Add comment · Show 2 · 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
avatar image tomekkie2 · Jun 28, 2012 at 10:20 PM 0
Share

Does that work on the shaders other than Legacy Shaders /Lightmapped in Unity3d 3.xx ?? I can not get that to work.

avatar image anilgautam · Dec 05, 2012 at 06:15 AM 0
Share

Does that work in case of unity terrain

avatar image
0

Answer by SuperUltraHyper · Mar 15, 2016 at 01:50 PM

Try this:

 using UnityEngine;
 
 public class TransferLightmap : MonoBehaviour {
 
     public Renderer sourceObject;
     public Renderer targetObject;
 
     void Start () {
         targetObject.lightmapIndex = sourceObject.lightmapIndex;
         targetObject.lightmapScaleOffset = sourceObject.lightmapScaleOffset;
 
         targetObject.material.SetTexture("_LightMap", sourceObject.material.GetTexture("_LightMap"));
     }
 }
 
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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

changing lightmaps with javascript / saving multiple lightmaps to lightmap array 1 Answer

SOLVED - String replace % with " in C# 1 Answer

switchable lightmaps 1 Answer

How can I change the lookout of an object? 0 Answers

Beast Lightmapping, Baking texture step ( past GI calculations) 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