Search Unity

Directional lightmap not giving me the results I expect

Discussion in 'Editor & General Support' started by TwiiK, May 1, 2012.

  1. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    I'm struggling a bit with the directional lightmap.

    Examples:

    Looking at my sun (the only light in the scene) and getting no specular hightlight in front of me:


    Looking straight down and seeing a highlight seemingly unrelated to any light source:


    What's this? My lightmapped shadow looks like paint of some sort because of the weird specular:


    It's not mentioned in the docs and I haven't had any luck finding examples of it actually working.

    I also have no clue how to get specular highlights on dynamic objects like my player without ruining the great lighting I have from light probes.
     
    Last edited: May 1, 2012
  2. roydon

    roydon

    Joined:
    May 2, 2012
    Posts:
    5
    I am also having this problem. It seems that when you are facing a particular direction your shadows look good but then you switch to the opposite direction and that same shadow becomes brighter than the non-shadow areas. This only happens when I am using a specular material.

    Looking at an object from one direction and getting correct shadowing
    $shadow.jpg

    Looking at the same object from another direction and getting brighter shadow than non-shadow area.
    $spec.jpg

    Is this a bug with directional lightmaps or are we doing something wrong?
     
  3. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    What are the limitations?

    Here's a scene without directional lightmaps:


    Here's the same scene with:


    Is 1 specular the limit? Where is it coming from? Seems pretty random.
     
  4. roydon

    roydon

    Joined:
    May 2, 2012
    Posts:
    5
    I have noticed that my problem only happens when I have more than one point light in my scene. I am using two point lights atm and it seems like when unity is deciding where to put specular is doesn't correctly determine areas where the two lights overlap each other.

    Perhaps it is the case that directional lightmaps only work with one light?

    That would explain why you only seem to be getting one specular Twiik. I think it is perhaps averaging the position of multiple lights into one. While annoying I would happily accept an averaged specular position if only there was no artifacts like I am getting (the overly bright spec areas on shadows).

    Here is another example of the weird spec I am getting.

    $silveryspec.jpg

    Another interesting thing I have noticed is that if your diffuse texture map doesn't have an alpha channel the artifacts are noticeably worse. At certain angles your entire shadow area becomes very bright.
     
  5. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    I have just one directional light, the sun, in my initial examples.
     
  6. roydon

    roydon

    Joined:
    May 2, 2012
    Posts:
    5
    Yeah actually I have done some tests and it happens even with one light, point light or directional light.

    My current solution to get rid of my artifacts is to open up the colorscale map in photoshop and make the entire map grey. This removes the weird artifacts but also the directional information from the specular. So now I have specular but its not coming from the right direction.

    It would be good to get someone from Unity commenting on this. If this is a bug I can make a test scene and send it in.
     
  7. Chukker156

    Chukker156

    Joined:
    Oct 4, 2012
    Posts:
    8
    I have seen these kinds of artifacts after baking directional lightmaps if the object in question is using normal maps that have UV folding in UV channel 1. This is too bad, as it means if you want a clean directional lightmap bake, you can't fold UVs and will be forced to be wasteful with texture space.
     
  8. Chukker156

    Chukker156

    Joined:
    Oct 4, 2012
    Posts:
    8
    To respond to my own bug, it is possible to get better results with directional lightmap bakes if the buggy mesh has its Tangent setting changed to "Import" from the default "Calculate" (assuming it's geometry looks proper with normal maps in the authoring software).
     
  9. Kuba

    Kuba

    Moderator

    Joined:
    Jan 13, 2009
    Posts:
    416
    Hey guys,

    The color lightmap stores roughly the same information as the single lightmap would. The scale lightmap stores the information on how much of that color was contributed to from each of the 3 directions of the basis (same as Basis for Radiosity Normal Mapping).

    The direction from which the light comes is well defined only in the area that is heavily influenced by one light. Areas (like the one closer to the camera in your screenshot) have the three lights affecting it almost uniformly, hence the spec seems to be coming from a light that is the average (position- and color-wise). This is a somewhat expected limitation of the technique.


    They should of course work with multiple lights, but see the comment to TwiiK above.

    The specular in the shadow should be modulated by the diffuse lighting (not exactly correct, but this is what we do in deferred anyway). It doesn't seem to be the case for you, so please submit a bug report and post the case number here.

    A bug report would be appreciated!

    Cheers!
     
  10. Kuba

    Kuba

    Moderator

    Joined:
    Jan 13, 2009
    Posts:
    416
    What do you mean by UV folding? The unique UVs for lightmapping?

    First you should verify if your model looks correctly with normal maps and realtime lighting. Whether "Import" is better than "Calculate" depends on the model. If you have an example where "Calculate" is doing a bad job, please submit a bug report with the model in question.
     
  11. Leo-Bounce

    Leo-Bounce

    Joined:
    Mar 2, 2011
    Posts:
    12