Swapping Lightmaps In Realtime

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ก.ค. 2024
  • Link to example project: birdmaskstudio.itch.io/unity3...
    Link to full video on using Lightmaps: • Lightmapping Done In 9...
    Link to my game Vampire Heist: birdmaskstudio.itch.io/vampir...
    Took a while but here it is, my video on swapping lightmap and probes on specific objects and areas in runtime in the Unity3D engine, hopefully this helps anyone wanting to do this in their games.
    This video is shoot off of another video I did 'Lightmapping Done In 9 Minutes + Switching On and Off In Realtime', if you want a quick crash course of applying lightmaps and post processing effects to make you scene look better check it out.
    Timestamps:
    How It Works - 00:32
    Swapping Lightmaps - 01:00
    Updating Light Probes - 02:00
    The Result - 03:04
    How To Set It Up - 03:25
    Final Word Stick Around - 05:18
    If you liked this video, please give us a like and subscribe and check out my video game releases on my site birdmaskstudio.itch.io/. While I don’t make videos too often, if there is something I do people would like to see, let me know and i’ll see what I can do.
    Thanks for watching and reading down here.
    Twitter; / birdmaskstudio
    Website; www.birdmaskstudio.com/
    Itchio Page; birdmaskstudio.itch.io/
    GameJolt Page; gamejolt.com/@BirdmaskStudio
    Facebook Page; / birdmaskstudio
  • เกม

ความคิดเห็น • 42

  • @joshuareeves9985
    @joshuareeves9985 3 ปีที่แล้ว +6

    Well done! Wish Unity had this feature built in. So useful to have multiple performant versions of a level that don't need dynamic lights moving around.

  • @bnjmo
    @bnjmo 3 ปีที่แล้ว +5

    This is gold! Thank you for your great work!

  • @erz3030
    @erz3030 3 ปีที่แล้ว +4

    This is shockingly useful, thanks for the work mate, cheers!

  • @HAXZingTERR0R
    @HAXZingTERR0R 3 ปีที่แล้ว +3

    I was going nuts wondering why my culling mask wasn't working on baked lighting. After some research, culling masks don't work on baked lighting, so I thought about generating two light maps and just switching between them to accomplish what I was trying to do. And that brings me to here... Thank you!

  • @shadmanarko7398
    @shadmanarko7398 4 ปีที่แล้ว

    Thank you very much. I have waited for this video for 1 month

  • @Klash120
    @Klash120 4 ปีที่แล้ว

    Stellar stuff!

  • @Maufdiot
    @Maufdiot 3 ปีที่แล้ว

    Your a legend in my book !

  • @amal_joy_
    @amal_joy_ 3 ปีที่แล้ว

    amazing work.. thank you

  • @MikeTheAnomaly
    @MikeTheAnomaly ปีที่แล้ว

    So helpful!

  • @ColeWithAGoal
    @ColeWithAGoal 2 ปีที่แล้ว

    Awesome, thanks for the share! :)

  • @fabfab408
    @fabfab408 3 ปีที่แล้ว

    Thanks ! that's awesome !

  • @maurofuentes8076
    @maurofuentes8076 3 ปีที่แล้ว

    AWESOME!!!!

  • @petereldredge2329
    @petereldredge2329 4 ปีที่แล้ว +3

    This is fantastic! Thanks so much and for actually teaching the concepts. Are there any restrictions on using/tweaking this code?

    • @BirdmaskStudio
      @BirdmaskStudio  4 ปีที่แล้ว +5

      Thanks! Glad you liked the video. No restrictions on using the code from the example project for your own work.
      I want people to be able to just be able to use this without having to worry about it.

    • @sean8306
      @sean8306 3 ปีที่แล้ว

      Looks awesome! and sorry to ask the same question. But this is completely royalty free and can be used in commercial projects?

  •  3 ปีที่แล้ว

    hello!! thanks a lot for the tool :) would there be any way to just remove the lightmaps but keeping the lightprobe data? doesn't matter if it's at runtime or not.

  • @1wdc
    @1wdc 2 ปีที่แล้ว +1

    I ran into an issue, not sure if I'm the only one but it seems like there's an off by one error in the code. On Line 70 of AlternativeLightsManager it checks if l_dir.Length >= i, then if it is it tries to access l_dir[i], which will return an IndexOutOfRange exception if i == l_dir.Length. I think the check should be l_dir.Length > i for that reason, but it's kind of weird no one else brought it up so maybe I'm doing something wacky (I don't have any directional maps, so l_dir.Length of 0 is returning the error).

  • @schizoscope8703
    @schizoscope8703 2 ปีที่แล้ว

    Thank you very much. It wierd Unity has not this function by default.

    • @Shiffo
      @Shiffo 2 หลายเดือนก่อน

      Isn’t this coming to unity 6 now ?

  • @tufanaydin6340
    @tufanaydin6340 6 หลายเดือนก่อน +1

    You guys are great! but after import it gives this message "Assets\AlternativeLights\Editor\Editor_AlternateBakedLight.cs(147,29): error CS0117: 'Handles' does not contain a definition for 'DrawSphere'"
    using Unity 2022.3.15

    • @huxi26
      @huxi26 4 หลายเดือนก่อน

      replace it with SphereHandleCap

  • @Beikenost
    @Beikenost 2 ปีที่แล้ว +4

    This is perfect and professionally made!
    But i have an issue though;
    I have a building with a lot of static objects.
    Is there a way to group them all up with a parent and only apply the alternate baked light script on a single object instead of every single one?
    EDIT i fixed it (Just edit the "AlternateBakedLight.cs" script):
    Turn the "rend" variable into an array:
    private MeshRenderer[] rend;
    In the start method, do this instead:
    rend = GetComponentsInChildren();
    In the ChangeLightState method, do this instead:
    for (int i = 0; i < rend.Length; i++)
    {
    rend[i].lightmapIndex = currentLightState;
    }
    Finally:
    Place the "AlternateBakedLight.cs" on a empty parent object housing your changable objects.
    Hope this helps. Thanks again for this amazing tool!

    • @ItssVenom
      @ItssVenom 2 ปีที่แล้ว

      This is exactly what I was looking for. Thank you!!

    • @zellator
      @zellator ปีที่แล้ว

      Thanks!! :)

    • @randomstuff6786
      @randomstuff6786 4 หลายเดือนก่อน

      Thank so much!

  • @chicoB001
    @chicoB001 3 ปีที่แล้ว

    Can this work with Bakerys Lightmapping tools in unity?

  • @CHEEZEyCHEEZE
    @CHEEZEyCHEEZE 3 ปีที่แล้ว +2

    I love this. Only issue I see is that my project is currently purple textures and some of the code is giving me errors because DrawSphere is not recognized in 2020.2.3f1. I will try rolling back my project until at least 2019 LTS and see if that fixes some of the issues. Going back to 2019 LTS it fixed some of the issues like depreciated DrawSphere for the GUI. But everything is still missing textures in the sample Scene. It seems that each room is missing "The associated script can not be loaded. Please fix any compile errors and assign a valid script." After reviewing the video I noticed I didn't have ProBuilder installed. That fixed the issue. It is working now. Still getting a null pointer for the two Void Objects for the scripts that are missing there. What were the scripts?

    • @MrSmileyturnsgrumpy
      @MrSmileyturnsgrumpy 2 ปีที่แล้ว +3

      From looking at the project and lil clips of the video, I'm pretty certain the reason you're getting the Magenta Materials and missing scripts is because the sample scene was made with ProBuilder. You should be able to add any old material to the mesh renders no worries.
      Also to fix the deprecated sphere handles, change Handles.DrawSphere to Handles.SphereHandleCapand add EventType.Repaint as a fourth parameter

    • @disdathit
      @disdathit ปีที่แล้ว

      @@MrSmileyturnsgrumpy Hi there and thanks for this! I tried swapping out the references of "Handles.DrawSphere" to "Handles.SphereHandleCap", (in the "Editor_AlternateBakedLight.cs" file), but then got the following error:
      "There is no argument given that corresponds to the required formal parameter 'eventType' of 'Handles.SphereHandleCap(int, Vector3, Quaternion, float, EventType)'
      "
      Any ideas? Also i do not know what adding a fourth parameter means :( I would appreciate any help!

    • @disdathit
      @disdathit ปีที่แล้ว

      @@MrSmileyturnsgrumpy I worked it out! It means, add "EventType.Repaint" as a 4th 'thing' (lol) in the brackets which appear after Handles.DrawSphere / Handles.SphereHandleCap. Thanks for this! Hopefully i can get it working :/

    • @ParallaxDev
      @ParallaxDev ปีที่แล้ว

      @@disdathit its not Handles.DrawSphere anymore thats deprecated, its now Handles.SphereHandleCap and your fourth parameter got rid of the errors!

  • @disdathit
    @disdathit ปีที่แล้ว

    Hey there and thanks very much for this, it's very useful.
    Do you know if it is possible to apply a saved lightmap, to a model which is loaded at runtime?
    I have tried a little test in your scene (and my own). For example, bake a light map onto an object in the scene. I then delete the model/gameobject, then add the gameobject back in to the scene. But unfortunately, the lightmap is no longer affecting the mesh. I assume because the lightmap contains a reference to the specific deleted gameobject. Any ideas if there is a way round this?

    • @BirdmaskStudio
      @BirdmaskStudio  ปีที่แล้ว

      So it's been a while since I've looked at the lightmapping system - I can't say for sure but, if I were to try and find a way to do this I think I would look to shaders.
      My understanding is when unity bakes a scene, it basically makes a 2nd set of UV coordinates (different from the models main UV coordinates used for texture mapping) that it uses to get and overlay the lightmap texture. So if you had a way to;
      1 - Copy the lightmap UV coordinates of the baked version of the object.
      2 - Apply said saved lightmap UV coordinates onto your generated object.
      Then you would just need a custom shader that directly overlaid the lightmap texture onto the object, regardless of whether it was static or not.
      Like I said I've not looked into it so I can't say any of that is doable or would lead anywhere, It's just where I would start. I would like to look at this tool again and add some more features sometimes, like the one you've just mentioned, but in all honestly won't have the time to do that anytime soon.

    • @disdathit
      @disdathit ปีที่แล้ว

      Thanks very much for the reply! And i'm glad you did, because i forgot to reply myself... I've actually found the solution! Here:
      github.com/laurenth-personal/lightmap-switching-tool
      Basically it's a script which you attach to the object you intend to bake. Then, a new option appears in Asset menu (next to file). Click bake from there.
      Then, drag the now baked object into your project files as a prefab. Now whenever you drag this prefab into the scene, it remembers the baked lighting :) Awesome!
      I still have hurdles with my project, but that's my problem! Basically main thing is i don't know how apply saved lightmap to a scene which has none. But i think your project hopefully has that information in there somewhere. I'm going to show it to my developer friend tomorrow to get advice.
      Thanks again! :) Super chuffed you replied.

    • @tanujcherian3911
      @tanujcherian3911 ปีที่แล้ว

      @@disdathit Hey Man....was wondering if the link you posted supports unity 2020 versions and up?

    • @disdathit
      @disdathit ปีที่แล้ว

      @@tanujcherian3911 i believe so yes. Give it a go!

  • @muhammadumair6306
    @muhammadumair6306 4 ปีที่แล้ว

    Is there any overhead of changing lightmaps at runtime for mobile devices? Can we use this tool for mobile devices? I mean real-time changing like switching on and off lights of rooms?

    • @BirdmaskStudio
      @BirdmaskStudio  4 ปีที่แล้ว

      Honestly I don't do much with mobile so I can't really say, the tool is free to use and download if you want to test it out. I can't think of any reason it wouldn't work with mobile, but in case it doesn't and you need an alternative, I talk about using projectors in my other lightmaps video as a way to darken areas in realtime.
      Sorry I couldn't give you any specific info on this, good luck with your work.

  • @3rdAxis
    @3rdAxis ปีที่แล้ว

    I just downloaded the example project and tried loading it up using the asset manager and I'm running into some problems. I get this error in the console : Assets\AlternativeLights\Editor\Editor_AlternateBakedLight.cs(147,29): error CS0117: 'Handles' does not contain a definition for 'DrawSphere' Also I get errors on the _Set Room objects that say the Script is missing. I also uploaded a youtube video to demonstrate the problem. th-cam.com/video/plliv6qqSvo/w-d-xo.html Any help would be much appreciated.

  • @nickolas6060
    @nickolas6060 ปีที่แล้ว

    No reflection probes ??? Hmm

  • @xtoc
    @xtoc ปีที่แล้ว

    Hi,
    I purchased it, but the lightprobes isn't working anymore.
    Could you help me with it?
    I updated it to Handles.SphereHandleCap, but the probes are still not working when using the edit mode.