Search Unity

Lightmap Family Mod Help :)

Discussion in 'Shaders' started by [donzen], Oct 26, 2009.

  1. [donzen]

    [donzen]

    Joined:
    Oct 26, 2009
    Posts:
    7
    Hi guys,
    this is my first post on the forum :).
    Is there any way for the lightmap not to affect the illumination, but just modulate over the base texture?

    Thanks. :)
     
  2. bloodtiger10

    bloodtiger10

    Joined:
    Nov 9, 2008
    Posts:
    619
    do you mean bake?

    and welcome to the forums.
     
  3. [donzen]

    [donzen]

    Joined:
    Oct 26, 2009
    Posts:
    7
    I would like to modify the LightMap Shaders Family for have an effect similar to the Multiply blending mode of Photoshop, without affect the illumination on the mesh. The mesh should be lit by real light in the scene. In other words, I want multiply a baked occlusion (generated with a secondary uv) on the color, mantain the parameters of the LightMap Shaders Family (specular,normal diffuse, normal specular, and so on).
     
  4. bloodtiger10

    bloodtiger10

    Joined:
    Nov 9, 2008
    Posts:
    619
    you can merge shaders together that are on the wiki to make that, you'll have to do them yourself but it is possible.
     
  5. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    That's all a lightmap is. A multiply with the texture. It doesn't actually generate light or anything.
     
  6. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Lightmaps do modulate the base colour. With a lightmapped shader, you will get:
    Code (csharp):
    1. result = lightmap*base + dynamicLights*base
    Essentially, the lightmap is treated as an extra, pre-computed light. How does what you want differ from this?
     
  7. [donzen]

    [donzen]

    Joined:
    Oct 26, 2009
    Posts:
    7
    Thanks to all for the replies.
    I try to explain better what i want to obtain.

    For example in Unity there are the builtin "Specular" and "Bumped Specular".

    How can I modify the shaders for modulate my occlusion (secondary uv) over the main texture?
     
  8. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    The Lightmapped shaders all use the second UV set for the light map texture. Just put your occlusion map in there. If you want bump and/or specular from the base texture, use Lightmapped/Specular or Lightmapped/Bumped Specular.

    If you're having trouble with the second UV set, it could be that it's not importing properly.
     
  9. [donzen]

    [donzen]

    Joined:
    Oct 26, 2009
    Posts:
    7
    If i turn off a PP light the mesh became like self illuminated, because, infact, lightmap affect che illumination on the mesh.
    I don't want the "lightmap effect"...forget lightmap family for now :).

    I would like simply multiply the occlusion color on the main texture color , in the specular and bumped specular shaders.

    Something like this:

    Code (csharp):
    1.  
    2.             SetTexture [_MainTex] { Combine texture * primary DOUBLE}
    3.             SetTexture [_MultiTex] { combine texture * previous}
    4.  
    but in don't now how to integrate it in the specular and bumped specular shader.

    Bye.
     
  10. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Ok, from the code you've written it sounds like you want to use the occlusion map to modulate the lighting results, not just multiply it with the main texture. That is indeed different from light mapping, as it affects other lighting rather than just behaving as an additional light.

    You'll have to modify a number of passes to do that, although I'm still not sure why you'd want to do it. Occlusion maps are of ambient occlusion, meaning that they shouldn't affect direct lighting. If you've got a bright light in a tight corner, it should still light the corner.
     
  11. [donzen]

    [donzen]

    Joined:
    Oct 26, 2009
    Posts:
    7
    Occlusion maps are of ambient occlusion, meaning that they shouldn't affect direct lighting. If you've got a bright light in a tight corner, it should still light the corner.[/quote]

    I use it for the self occlusion effect.

    Conceptually i want a shader similar to the decal shader but with come differences:

    - the decal use the second uv
    - can use rgba specular (A for gloss)
    - can use bump (normal map)
    - cast and receive shadows

    I'm not a programmer but i thing is possibile to do.

    Thanks for alla replies.
     
  12. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    What do you mean by self occlusion?
     
  13. [donzen]

    [donzen]

    Joined:
    Oct 26, 2009
    Posts:
    7
    Only the occlusion generated by an object on himself.
     
  14. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Can you explain how your self-occlusion is different from a light map that contains ambient lighting and accounts for occlusion caused by the object itself, i.e. baked ambient lighting with ambient occlusion?
     
  15. [donzen]

    [donzen]

    Joined:
    Oct 26, 2009
    Posts:
    7
    Forget anyting...

    Anyway... Maybe I dont' explain the situation at my best, my english is too bad :D

    What i need is a Bumped Specular shader + Decal (decal on secondary uv).

    Someone can help me to insert the Decal Code in a Bumped Specular shader (I'm not a programmer)?

    Thanks.
     
  16. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Ok, I had a chat with a guy named Erik on IRC who wants to do the same thing you do. We had similar confusion to what you and I have gone through here, but we finally figured it out:

    You crazy artists and your terminology! You were both going on about wanting to use an occlusion map to modulate the base texture before the lighting equation. This didn't make sense, because occlusion maps are for ambient occlusion, and should only affect ambient light. If you modulate all lighting with the occlusion map, you'll have parts of the model that are always in shadow, even if they are in direct light.

    It turns out that what modellers often do is use an occlusion map in place of a "dirt map", which represents grime that has built up in creases of a model. It is generally darker, so it is multiplied with the base texture before lighting. In direct light, dirt is still somewhat dark, so it makes sense in the case where an ambient map doesn't.

    The important thing is that even though they can be generated in the same way, ambient maps and dirt maps are applied differently because they represent very different things.

    Now that I understand what you are after, I'll see about making an appropriate shader in the next week or so.
     
  17. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Ok, here's my first attempt. I don't actually have any 2-UV models handy so I'm not sure if it handles the second UV set properly at all. Let me know how it works.
     

    Attached Files: