Home Technical Talk

Unity Lightmapper question

MALicivs
polycounter lvl 15
Offline / Send Message
MALicivs polycounter lvl 15
Hey guys!

I have an issue here with unity3 maybe someone can help me out.

I have two groups of meshes in the same scene, and I want separate lightmaps for each one of them. I select one group and do bake selected, but when I select the second group and do bake selected unity obviously overwrites the previous lightmap. Is there any way I can do this properly? Some groupId kind of thing I can issue to each of the meshes so they go into different lightmaps?

cheers!

Replies

  • thomasmahler
    Options
    Offline / Send Message
    thomasmahler polycounter lvl 14
    Not at the moment. It's fucking stupid, but you just have to bake everything in one big pass.
  • commander_keen
    Options
    Offline / Send Message
    commander_keen polycounter lvl 18
    Why do you need to do that? It should be possible to make a script to save the lightmap(s) after baking and then reassign them after baking the other set.
  • MALicivs
    Options
    Offline / Send Message
    MALicivs polycounter lvl 15
    humm, that would be a problem because it didn't seem to be a way of assign the lightmaps to specific meshes, at least without using scripting, and unfortunately I'm not a scripter, BUT, yesterday I found a method that may be able to solve that.
    Basically under lightmapping-maps we can define the array size, which is the number of lightmaps we want, and after that select each object and go to lightmapping-object and define the lightmap index which is the number of the lightmap you want that object to go into. Also you have to check lock atlas under bake.

    This poses a problem with cloned objects though, because it seem to be placing cloned objects in the same uv space, and even if you set the index to be different it will send them to the same lightmap, but I still need to do some testing on this first.

    Also, the feature scale in lightmap under lightmapping-object doesn't seem to be affecting anything in the end result, the object ends up having the same size in the uv space despite using different values. Need some testing on this too though, and I'll get back at you guys when I have something certain.

    cheers!
  • thomasmahler
    Options
    Offline / Send Message
    thomasmahler polycounter lvl 14
    That'll make thigns a bit easier, but we have duplicated meshes and props all over the place... The whole implementation is just a little stupid right now, it costs a LOT of time to get this one, good GI pass that works for everything and not being able to just bake in separate passes is... GANRFHGHHG!

    Also, Unity really needs some more control globally over the lightmaps. At least let us change the exposure - it's nice that I can bring the maps into photoshop, but it'd be so much fater just being able to have a few sliders and tweak in realtime.
  • MALicivs
    Options
    Offline / Send Message
    MALicivs polycounter lvl 15
    There should be a way to just bake the selected items with all the lights that are affecting them, and then select some more and bake those too... It doesn't seem to be that complicated to do such a thing either, considering the tech.

    Anyway, about the control you have over Beast, if you go here they explain how you can define custom setting for it using an xml file. It seems to let you have a bit more control over it, even though I haven't looked at it indept yet.
  • wannabeartist
    Options
    Offline / Send Message
    wannabeartist polycounter lvl 8
    I have been having the same problem,

    It seems like the much advertised lightmapping feature is a bit unfinished, at least usability-wise...

    Have you guys had any problems with normal maps when using Beast? Sometimes it just blows away all normal map detail the second it gets the light maps done!
  • MALicivs
    Options
    Offline / Send Message
    MALicivs polycounter lvl 15
    I don't think the lightmaps in unity3 support normal maps :\
  • wannabeartist
    Options
    Offline / Send Message
    wannabeartist polycounter lvl 8
    Sure they do, or at least work with them...sort of...

    I just asked about this in Unity's forum and found out that apparently you need to have deferred rendering on for the lightmaps and normal maps to play nicely together.

    I just have the Pro trial, but I guess it's better to rely on third party light mapping with the free version.
  • commander_keen
    Options
    Offline / Send Message
    commander_keen polycounter lvl 18
    Yes, the default lightmap rendering requires deferred lighting(pro) to show normal maps and view dependent lighting effects like specular. What game engine lets you specify what objects get put on what lightmaps? This is done automatically in pretty much every engine, I still dont see why this is necessary, but as I said it should be possible with a bit of scripting.
  • MALicivs
    Options
    Offline / Send Message
    MALicivs polycounter lvl 15
    because I don't want the engine to put two objects that are very far from each other in the scene, in the same lightmap, since it would be loading the entire lightmap for just a little object.
  • bugo
    Options
    Offline / Send Message
    bugo polycounter lvl 17
    I would consider importing the light maps done from Maya/Max if the objects are in the same spot.
    Still a pain
  • commander_keen
    Options
    Offline / Send Message
    commander_keen polycounter lvl 18
    Im sure it optimizes that for you. Of course if you have enough space to fit everything on one map it will do that, I think the xml config file lets you set the max lightmap resolution though, which would break it up into more chunks. Why are you worried about texture memory? Its generally not a problem on pc's these days.
  • bugo
    Options
    Offline / Send Message
    bugo polycounter lvl 17
    i think he's worried about the size of the background meshes with the meshes that are close, and unity doesnt separate inbetween them, so its creating a huge map for what is not really needed. Is that it MALicivs?
  • cupsster
    Options
    Offline / Send Message
    cupsster polycounter lvl 11
    Assigning into lightmap is based on lightmap texel density you define for each object. You can lover texel density for meshes far away where you don't need such density. Beast will pack and scale UV chunks based on unwrap settings you define when you importing your geometry and texel density. About assigning objects to specific lightmap I'm not sure but here is script which enable you to set maximum lightmap size from editor.. Don't forget to change maximum lightmap size in inspector also ;)
    MaxAtlasSize.cs > Place it in "Editor" folder
    using UnityEditor;
    
    public class MaxAtlasSize : EditorWindow
    {
    	int[] kSizeValues = { 512, 1024, 2048, 4096 };
    	string[] kSizeStrings = { "512", "1024", "2048", "4096" };
    
    	void OnGUI()
    	{
    		LightmapEditorSettings.maxAtlasHeight = EditorGUILayout.IntPopup("Max Atlas Size", LightmapEditorSettings.maxAtlasHeight, kSizeStrings, kSizeValues);
    		LightmapEditorSettings.maxAtlasWidth = LightmapEditorSettings.maxAtlasHeight;
    	}
    
    	[MenuItem("Utilities/Max Atlas Size")]
    	static void Init()
    	{
    		EditorWindow window = EditorWindow.GetWindow(typeof(MaxAtlasSize));
    		window.Show();
    	}
    }
    

    Hope this helps.. :)
  • MALicivs
    Options
    Offline / Send Message
    MALicivs polycounter lvl 15
    Im sure it optimizes that for you. Of course if you have enough space to fit everything on one map it will do that, I think the xml config file lets you set the max lightmap resolution though, which would break it up into more chunks. Why are you worried about texture memory? Its generally not a problem on pc's these days.

    well it might be a problem when you are creating content for web, and your target audience has a huge range of computer specs possibilities.
    Having smaller textures would indeed help attenuate the issue, but still, call me a control freak, but I really rather have full control over the whole process.

    bugo: bringing them from max would solve the whole issue, but it is way too time costly in comparison to baking the lightmaps in unity.
    i think he's worried about the size of the background meshes with the meshes that are close,
    err no, not really, that usually is not an issue because you can set the resolution you want each object to have in the lightmap.


    what I have is two scenarios, and when the player is inside one, he isn't able to see the other one, so if you are in scenario A and because of one little table for example, you are loading an entire lightmap from scenario B it is absurd. now imagine that happens with a few more objects, and instead of loading 1 or 2 2048 lightmaps inside a room, you are loading 4 or 5 filled with unused information. It's a waste I don't like to have.

    cupsster: cheers mate, that can be useful!
Sign In or Register to comment.