Search Unity

Beast, day and night

Discussion in 'Editor & General Support' started by Peter Hou, Oct 12, 2010.

  1. Peter Hou

    Peter Hou

    Joined:
    Oct 12, 2010
    Posts:
    66
    Hi community members :)

    This is my first post. I'm currently evaluating the trial version of Unity 3 for use in realtime application development and visualization.
    Working with the Beast lightmapper is really great, but I'm slightly confused about the workflow required to achieve the results needed in visualization. For example, it's quite common to do different times of day and in other engines I would just switch lightmaps on my objects. With Beast, the lightmaps appear in a folder, but I don't see any maps assigned in the materials that are used. What are my options to have different sets of lightmaps and switch between them in Unity? Do I need to create a new level for each time of day?

    Also, I was wondering if there are plans to develop a daylight simulation system in Unity with input similar to the daylight system in 3ds Max?

    Thanks for your time.
     
  2. DocSWAB

    DocSWAB

    Joined:
    Aug 28, 2006
    Posts:
    615
    I'm working on adding times of day to WolfQuest. Here's what I figured out, based on some tips from the community. I plan to turn this into an editor script, but for now it's a manual workflow:

    1. Set up your realtime lighting for the time of day you want to represent.
    2. Bake your lightmaps.
    3. Rename the lightmap folder (which will be next to the scene file in the Project) to represent the time of day and move it to the Resources folder.
    4. Change your lighting again.
    5. Bake again.
    6. Save your lightmaps off to the side again.

    Now you need a script to load the desired lightmaps into the LightmapSettings class. Basically create an array of LightmapData objects and load each lightmap textures from Resources using Resources.Load. When that array is applight to LightmapSettings.lightmaps, you get that set of lightmaps.

    Using this approach, you don't have to apply a lightmap to every single renderer in your scene, because the pointers in the lightmap array have already been created by the bake.

    You will also need to save the real-time light settings in some sort of object and apply them to the light to go with the lightmap.
     
  3. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    DocSWAB are you aware of a method to bake only single lightmaps with just the ambient occlusion so that the models receive shadows?This way you could be able to have a day and night cycle.
     
  4. DocSWAB

    DocSWAB

    Joined:
    Aug 28, 2006
    Posts:
    615
    @elias_t:
    That sounds like a clever possibility but I haven't investigated it. I was proud of myself to have gotten this far, given how new Beast is in Unity.
     
  5. Peter Hou

    Peter Hou

    Joined:
    Oct 12, 2010
    Posts:
    66
    Thank you very much for the reply, DocSWAB.
     
  6. Mingo

    Mingo

    Joined:
    Nov 14, 2010
    Posts:
    39
    I'm also interested in this topic, and can't seem to find any clear answers.

    Our project requires a simple day/night cycle with no rotation of the directional light, just a change in intensity. The skybox is blended from day to night graphics through a shader. Is there any way to take advantage of Beast in such a setup, or will we have to resort to dynamic lights? Multiple lightmaps won't help (I assume), as we need a gradual fade of the lighting and not an instant switch from day to night.
     
    Last edited: Nov 16, 2010
  7. DocSWAB

    DocSWAB

    Joined:
    Aug 28, 2006
    Posts:
    615
    What I'm thinking of trying to do is to turn off lightmapping (set the lights to real time only) and do a fade between lighting settings, then reinstate the new lightmap.

    However this will probably have performance impacts, to may not be able to be triggered all the time (such as when there's intense action).

    @Mingo -- would you care to share your skybox blending shader?
     
  8. Mingo

    Mingo

    Joined:
    Nov 14, 2010
    Posts:
    39
    Oh, it's just a modified version of the old one I found on the wiki by Aras Pranckevicius. I'm from an Unreal Engine background, so writing materials/shaders manually is something that I'm only just getting into. The only things I changed (I think) were:

    Code (csharp):
    1. Tags { "Queue"="Background" "RenderType"="Background" }
    and
    Code (csharp):
    1. ZWrite Off
    ... this stopped the skybox from rendering over the top of everything else, and may not be the correct way to fix this. The problem itself might only be due to our game using two main cameras for the player's view or deferred rendering, etc.

    These "hacks" that involve switching lightmaps don't sound like the right answer to me, unless it's possible to blend between two of them in the same way that this skybox shader does. Even if that is possible, if the light has only changed in intensity and not direction, it's a massive waste of processing time (to generate two sets) and disk space (to store them).

    I don't know the details of how lightmapping works in-engine, but assuming they're just treated as textures internally then why is there no way to simply increase/decrease the "brightness" of them during runtime to simulate changes in light intensity? I don't see any scripting commands for this, nor any way to add this as an option to the built-in shaders. Is it possible to add a dynamic directional light to a lightmapped scene and have it "add" to the existing lightmap? For example, you'd map the scene at night and then manipulate the intensity with this dynamic light (set to cast no shadows). Can we access the lightmap textures at all, and manually change their pixels in memory?

    Assuming none of this is possible, how about a post-process shader to just darken or lighten the scene to fake the lighting? Am I just rambling, and if so can somebody please just tell me that it's impossible in Unity and to resort to dynamic lights?
     
    Last edited: Nov 16, 2010
  9. DocSWAB

    DocSWAB

    Joined:
    Aug 28, 2006
    Posts:
    615
    Thanks for the shader info.

    It's possible you could accomplish what you want to do by using a Pro image effect filter to simply lighten or darken the entire scene.

    It's also possible you could manipulate the lightmap textures in real time using get/set pixel functions on the textures. Not sure about the performance (would depend on the number of lightmaps and their size), or how that would compare to an image effect, which uses Render Textures
     
  10. brad_ict

    brad_ict

    Joined:
    Sep 14, 2010
    Posts:
    69
    Anybody know of examples out there doing lightmap switching for time of day? DocSWAB: care to share any samples :)

    Thanks,
    brad
     
  11. nbalexis1

    nbalexis1

    Joined:
    Jul 21, 2011
    Posts:
    89
    I have the same problem.And when I change my LightmapSettings.lightmaps it could not rendered correctly, much brighter
    I also tried to set array size to 2 and set every texture manual in editor and change lightmapindex in script, but the same result
     
  12. nbalexis1

    nbalexis1

    Joined:
    Jul 21, 2011
    Posts:
    89
    finally it works when I ONLY change the folder name...
    I shouldn't copy the lightmap to anywhere, the only thing that I could do to store the baked lightmap is change the folder's name
    I guess something else store some where
     
  13. speckracer

    speckracer

    Joined:
    Aug 25, 2011
    Posts:
    1
    nbalexis,
    What did you exactly do to get this to work? I'm also experiencing weird lightmap problems with it being too light.

    Here is my code:

    LightmapData[] myNewLightMapDataArray = LightmapSettings.lightmaps ;

    for (int i = 0; i < LightmapSettings.lightmaps.Length; i++){

    string targetName ="Night/LightmapFar-" +i ;
    myNewLightMapDataArray.lightmapFar = Resources.Load(targetName ) as Texture2D ;

    }
    LightmapSettings.lightmaps = myNewLightMapDataArray;


    OK. I figured out I needed to modify the image type of the textures in the Resources folder from Texture to Image Map. Everything works now.
     
    Last edited: Aug 27, 2011