Search Unity

[Question] Dynamically drawing/updating normal maps at runtime.

Discussion in 'Editor & General Support' started by SomeTallGy, May 25, 2014.

  1. SomeTallGy

    SomeTallGy

    Joined:
    Jan 3, 2014
    Posts:
    18
    Hi Folks, first time posting on the Unity boards. I have done some searching on this topic and found a few ideas with render textures as well as some nifty things with Camera.RenderWithShader - however, every problem is different and I couldn't really get a clear direction on how to do the following at runtime:

    Per these 2 screenshots:
    $Screen Shot 2014-05-25 at 1.09.48 PM.png (Before)
    $Screen Shot 2014-05-25 at 1.09.16 PM.png (After)

    Basically, I am trying to create a normal-texture based hex grid for a strategy game. I achieved the result pasting the hex normals in photoshop: $Screen Shot 2014-05-25 at 1.18.28 PM.png

    However, I want to achieve this result dynamically during runtime.

    Does anyone have a clear cut explanation on how to do this?
    FYI: I am still a beginner with Unity3D but I am starting to grasp at the basics of shader writing and C#.

    Thanks in advance!
     
  2. SomeTallGy

    SomeTallGy

    Joined:
    Jan 3, 2014
    Posts:
    18
    Maybe memorial day weekend wasn't the prime time to ask this question :p Still hoping that that someone can point me in the right direction.
     
  3. MakeCodeNow

    MakeCodeNow

    Joined:
    Feb 14, 2014
    Posts:
    1,246
    Unless you are targeting a really low-power GPU, I'd recommend doing that combination a runtime inside a custom shader. Basically, make a new surface shader that can take two normal maps. Read both and blend them however you see fit and return the blended normal as the output normal for Unity to use in lighting calcs. It looks like the 2nd normal map will use scaled UVs, but that's just an implementation detail.
     
  4. SomeTallGy

    SomeTallGy

    Joined:
    Jan 3, 2014
    Posts:
    18
    MakeCodeNow - Thank you for your reply!

    So.. make a custom shader to receive another normal map of the hex shapes. Check.

    However, my question is more specifically on if such normal maps can be drawn and created at runtime - in other words, I want to use unity to create a hexagon grid normal map by taking a render of a sequence of 3D shapes and then inserting that normal map into the custom shader.

    I believe the closest example of this I can think of is baking light maps; but instead I want to bake in a normal map.
    Is this possible?

    Thanks.
     
  5. MakeCodeNow

    MakeCodeNow

    Joined:
    Feb 14, 2014
    Posts:
    1,246
    Yeah, totally possible. The easiest thing to do would be to write a shader that outputs normal data as a color. Then render your scene with this shader applied to your objects, capture the results into a Texture, and, bam, new normal map!
     
unityunity