Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Beast lightmap - separating AO data from Light

Discussion in 'General Graphics' started by Zenchuck, Feb 4, 2015.

  1. Zenchuck

    Zenchuck

    Joined:
    Jun 2, 2010
    Posts:
    297
    Is it possible to separate AO from baked lights?I would like to adjust the scene brightness. AO should follow the scene, while lights remain illuminated.

    Anyone face a similar issue and find a solution?

    Ideally I could set the lights in RGB and AO in Alpha.

    I could also bake lights and AO separately but not sure how the auto-packing feature works to assign certain blocks of mesh to certain lightmap textures.

    Thanks
     
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    It may be possible but not without a very big amount of work.
    The current lightmapper and the lightmapping shader do not support such behavior.
    Unity save the Lightmap into HDR files with do not support a alpha channel.
     
  3. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    Possible with a custom shader and lots of manual work. First you bake a lightmap with pure-white ambient, no lights and 1.0 AO intensity and convert the result into 8-bit textures with proper gamma (since 32-bit precision is useless when whole black to white range is used). Second you bake your lighting as usual, with AO disabled.

    Create a shader that would add AO on top, done. Ideally, you would want to remove Unity lightmapping altogether and manage lightmap textures yourself (make sure to duplicate them from the scene folder to decouple them from Beast config and prevent accidental overwrites or removal), applying them through your shader using DecodeLightmap method - that would make your setup completely scene-independent, allowing you to store ligtmapping per object, load prefabs with lightmaps, build procedural worlds out of lightmapped pieces and so on. There are numerous issues though:

    • Say goodbye to static batching, it murders UV2 precision and will make your lightmaps applied incorrectly as even a slightest shift far from decimal point is very noticeable at texel density lightmaps are using
    • You'll have to use unique material per every object type and unique material per every instance of that type if you want those instances to have separate lighting.
    • You absolutely must copy all offset and tiling values from Lightmapping window into your lightmap texture slot, as Beast almost never sets them to 1,1 and 0,0 no matter what settings you are forcing (you can automate this with a properly written editor script, along with other aspects like lightmap duplication and material creation).
    • You properly want to use a custom lighting model if you want the result to be able to interact with dynamic lighting nicely and to use AO properly (ideally something like Jove where it goes in an appropriate separate output and modulates ambient instead of being multiplied by diffuse)
    • Say goodbye to dual lightmapping and support for dynamic objects, it can't be done nicely if you go the route of making both light and AO manually managed textures, decoupling your objects from Beast. Well, it's probably possible, but you'll have to implement it yourself.
    • Atlasing is a pain and object distribution sometimes changes from one bake to another so you'll probably want to set texel density extremely high to force Beast to only ever render one lightmap per object. You can write an editor script to force different baking resolutions and then bake objects separately to somewhat sidestep texel density consistency issue you'll have with that approach (a chair and a big room have very different surface area). Don't forget to manually adjust lightmap import settings if you go x1024+ with lightmap resolution, Unity won't set it to import automatically.
     
    Last edited: Feb 5, 2015
    0tacun likes this.
  4. Zenchuck

    Zenchuck

    Joined:
    Jun 2, 2010
    Posts:
    297
    I have no trouble creating my own lightmaps outside of Unity. The issue is just the ease of use (and time). It is somewhat bulky to export an entire level out of Unity, break it into lightmap zones and then bring it back in again.

    I find everything else about Beast to be really good. I just wish I had more control over what it spits out.

    I was hoping someone might have found a way to export to a different format.
     
  5. PixelMind

    PixelMind

    Joined:
    Aug 16, 2013
    Posts:
    101
    Not sure if it helps, but the lightmap files can be edited in Photoshop. You can then convert them to lower precision if necessary and save them in any Photoshop supported format.

    In order to read the textures correctly, you'll need to write or edit shaders to read from correct UV coordinates which Beast assigns when do a bake. There are forums posts how to do this.
     
  6. Zenchuck

    Zenchuck

    Joined:
    Jun 2, 2010
    Posts:
    297
    So you are saying I could bake an AO pass, then a scene light pass, combine them in Photoshop, and then just bring "unity_Lightmap" in as a regular texture? That would be nice. I mean, it adds an extra step in the workflow but I don't see it being overly time consuming.

    I'll test the idea out.
     
    theANMATOR2b likes this.