Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Bump maps for built-in terrain

Discussion in 'Made With Unity' started by Chris Morris, Oct 10, 2010.

  1. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259



    I know people have been looking for this so I thought I'd share our solution. It is fully integrated with Unity 3.0′s surface shaders so it reacts correctly with all lights, shadows, etc. Also, this is real bump mapping using a normal map (doesn't just use the alpha channel like previous implementations).

    More details and a download link can be found here: http://sixtimesnothing.wordpress.com/2010/10/10/bump-mapping-for-built-in-unity-terrain/

    NOTE: It also exposes a means of sending textures and values to the built-in shaders, so be sure to let us know what else you guys are able to come up with.

    Double NOTE: The bump mapping won't be visible in the editor since the script needs to run to send info to the shader. Press play and you'll see it.

    Enjoy!

    - Chris
    Six Times Nothing
     
    Last edited: Oct 10, 2010
  2. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,144
    Wow!!! Downloading now and testing. I report my results.
    Thanks dude!
     
  3. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,435
    Looks good. Wish it supported 2.6 though as I'm not going to be able to use 3.0 until some issues are resolved. :(
     
  4. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,144
    I have problems with the base map. If I look the terrain from certain angles the base map looses its bump map ...
     
  5. Evsign

    Evsign

    Joined:
    Oct 10, 2010
    Posts:
    14
    Don't work in my project... I copy all files to my Assets, add script to terrain and add bump maps. No effect((
    Sorry for my English ...
     
  6. Evsign

    Evsign

    Joined:
    Oct 10, 2010
    Posts:
    14
    Sorry, my mistake:) When i push play button, all will be work:)
     
  7. ChaosWWW

    ChaosWWW

    Joined:
    Nov 25, 2009
    Posts:
    469
    I also wish this was for 2.6 but alas, I look forward to this when I make the upgrade :) . This is one of the most sorely missed features in Unity IMO, and I'm glad you finally found a way to implement it.
     
  8. Itchy-Games

    Itchy-Games

    Joined:
    Jul 8, 2009
    Posts:
    218
    works great!!! i think that it will improve a bit more, but it´s a very good start.
     
  9. mikesgames

    mikesgames

    Joined:
    Apr 16, 2010
    Posts:
    1,071
    Thanks Chris!

    Downloading now :)
     
  10. DisTrash

    DisTrash

    Joined:
    Feb 2, 2009
    Posts:
    166
    Can we use it with Unity Free version ? Or only with pro. ?


    Thanks a lot !! ;) ;) ;)
     
  11. Artimese

    Artimese

    Joined:
    Nov 22, 2009
    Posts:
    794
    Omfg Ive been waiting for this feature!!! Thanks so much.
     
  12. 3dDude

    3dDude

    Joined:
    Jul 4, 2010
    Posts:
    1,067
    OMG it works GREAT thats for free :)

    wow!

    thanks

    and have you tried parallax mapping for this script?

    that would be awesome!
     
  13. Evsign

    Evsign

    Joined:
    Oct 10, 2010
    Posts:
    14
    I think, if that can be used local, this will be great!! Because not everywhere on terrain that need.
    (Sorry for my English.)
     
  14. LamentConfig

    LamentConfig

    Joined:
    Sep 28, 2010
    Posts:
    292
    Woah, this is amazing! :) Still tweaking the settings, but let me give you a before and after preview based upon SpaceOreMiner ( not updated the webplayer yet, considering how best to use this :) ).

    Before :
    $rock1-none.jpg

    After :
    $rock2-bumpy.jpg
     
  15. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    Oh, yea that was one thing I forgot to mention - it won't show up in the editor because the terrain script needs to run.

    @elias_t - The shader does not apply itself to the base map, so set the base map distance higher if you want to see it from far distances.

    @bigkahuna - I suspect someone will port this to 2.x since it shows the 2 major problems we've run into which is sending textures to the built-in shaders and approximating the tangents of the terrain which aren't provided in the vertex data.

    @3dDude - We're going to work on our own parallax shader soon. I'm sure someone could implement the built-in parallax with ease but I don't think it looks very good.

    @Evsign - It can be viewed only locally. It doesn't apply itself to the base map so if you want it very local, just set the base map distance low.

    Thanks for the feedback!

    - Chris
    Six Times Nothing
     
    Last edited: Oct 10, 2010
  16. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,144
    @Chris.

    I have the base map distance at 2000. By not applying itself to the base map you mean we should not ad a bumpmap for the basemap?

    I have for all 4 textures a normalmap, but from certain angles the bump seems ok but from others it shows some dark artifacts.

    Here are some screenshots, and thanks again for your effort!
     

    Attached Files:

  17. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    In the shader, try changing the tiling rate of the normal map. It looks like the bumpmap is very large. So in the shader where it shows 4 sections for each texture, find the one that applies to the texture you are seeing that looks like that and multiply the UV until it looks right.

    // multiplied by 100
    o.Normal = splat_control.r * UnpackNormal(tex2D(_BumpMap0, IN.uv_Splat0 * 100));
     
    Last edited: Oct 10, 2010
  18. Evsign

    Evsign

    Joined:
    Oct 10, 2010
    Posts:
    14
    I mean not just that. I mean, what would this shader was used not on all terrain, but only in the right places. For example, in one place of my terrain i have the texture of stone, and in another place I have the texture of grass. And I need that to this shader has been applied only in the place where lies the texture of the stone
     
  19. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    @Evsign - Yes, for the textures you don't want bump maps on, just leave "None" in the bump map texture in the terrain script. And remember, the 4 slots line up with the 4 terrain textures respectively.
     
  20. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,144
    Ok Chris. thank you for replying.

    But having the tiling changed didn't resolved it. The basemap is 1024x1024 and the normalmap the same. When it shows, the tiling seems correct, but when it's not showing you can see the artifacts:

    could it be that we can't have the terrain lightmapped?
     

    Attached Files:

  21. Evsign

    Evsign

    Joined:
    Oct 10, 2010
    Posts:
    14
    Wow!! Thanks! I don't understand it at first:)
    If there was opportunity to choose a shader that would be Super:) For example, for first texture - bump, for second - diffuse
     
  22. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    @elias_t - It may be that you are using single lightmapping instead of dual lightmapping. Also make sure your light source is "Auto" and not "Baked Only".

    Dual lightmaps are required for any specular or normal mapping

    Read about dual lightmapping here:
     
    Last edited: Oct 10, 2010
  23. Evsign

    Evsign

    Joined:
    Oct 10, 2010
    Posts:
    14
    I hurried:(
    Does not apply bump for second texture, and there were some strange spots resembling a shadow :( Maybe I'm doing something wrong...
     

    Attached Files:

  24. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    @Evsign - just noticing the screenshot isn't in play mode, maybe the bump hasn't been sent to the shader yet? If that isn't the problem, it may be a tiling issue and you'll need to tile the UV coordinates in the shader. In your case, do this only for the normal map for the second texture.

    E.G.

    // multiplied by 100
    o.Normal = splat_control.g * UnpackNormal(tex2D(_BumpMap1, IN.uv_Splat0 * 100));
     
    Last edited: Oct 10, 2010
  25. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,144
    Chris. Unfortunately, I am using dual lightmaps, deferred rendering and the light source is set to auto. I played with changing the uv tiling, changing textures and normalmaps , but always with the same result. Perhaps do the normalmaps have to be in a very specific format?
     
  26. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,589
    hi chris.
    sounds like very great news. but i just have tested it with the bootcamp demo and got pretty weird shadow artifacts on the terrain.
    look at the image attached: there should be any shadows on the terrain at all…

    lars
     

    Attached Files:

  27. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    Thanks for the feedback guys!

    This was developed and tested specifically for our game, so it helps a lot when you guys find exceptions. I think I have found the bug that you guys have run into, and I'm fixing it at the moment. I'll keep you guys updated, should be a fix by tonight.

    - Chris
    Six Times Nothing
     
  28. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    Alright guys, I found the bug. The new version is more explicit about UV coordinates, and requires you to input the tile size for each terrain texture.

    Re-download from the same link and tell me if that fixed the problem



    - Chris
    Six Times Nothing
     

    Attached Files:

    Last edited: Oct 11, 2010
  29. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,144
    Thanks Chris. It works ok now.
    Thanks again!
     
  30. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,589
    works perfectly now! many thanks,

    lars
     
  31. Evsign

    Evsign

    Joined:
    Oct 10, 2010
    Posts:
    14
    Maybe I'm stupid, but after re-download it does not working ((
     

    Attached Files:

  32. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,144
    You have your tiling set to 0.
     
  33. Disaster

    Disaster

    Joined:
    Oct 31, 2009
    Posts:
    43
    Why this wasn't included in Unity 3.0 I don't know, it seems almost fundamental.
     
  34. Evsign

    Evsign

    Joined:
    Oct 10, 2010
    Posts:
    14
    Changing this setting does not help:( I tried different values, but without effect... Please Help!:)
     
  35. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    @Evsign - hmm... if you want you can send me a .unitypackage and I'll take a look.
     
  36. Evsign

    Evsign

    Joined:
    Oct 10, 2010
    Posts:
    14
    Yes, I want:) Thanks in advance. That package without standards assets
     

    Attached Files:

  37. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    @Evsign - ok, download the newest. Should be fixed now, thanks for the feedback
     
  38. Evsign

    Evsign

    Joined:
    Oct 10, 2010
    Posts:
    14
    waiting for the result:)
     
  39. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    Here's your project back, fixed. I removed the extra camera and set the tiling rate - it needs to be the same as the texture (in this case 15)
     

    Attached Files:

  40. DocSWAB

    DocSWAB

    Joined:
    Aug 28, 2006
    Posts:
    615
    Ooh, this looks so cool! But I have an 8 splat terrain -- any pointers on making this work with 2 passes for terrain shading? Even if it could be made to have the bump slots point to the 2nd splat map instead of the first, that would work for the splats I want to bump...
     
  41. Evsign

    Evsign

    Joined:
    Oct 10, 2010
    Posts:
    14
    Thanks, it work:) But after adding the bump to the second texture, obtained it (tile is 15)
     

    Attached Files:

  42. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    @DocSWAB - You'd have to get a bit creative. Just off the top of my head, you could use the unused alpha channel in your textures to indicate whether they are first or second pass textures and use a second set of 4 bumps accordingly. Something like:

    if(tex2D(_Splat0, texCoord).a < 0.5)
    o.Normal = this bump
    else
    o.Normal = second pass bump
     
    Last edited: Oct 12, 2010
  43. unity_sg

    unity_sg

    Joined:
    Sep 14, 2010
    Posts:
    95
    Hi, thanks for sharing ;)
    Very nice and usefull work !

    I want to ask you if it's possible to have more than 3 bumps (4 per example) ?
     
  44. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    @seb7000 - The script allows for 4 bump maps and if you need any more you can use a trick like I showed in the post above yours.
     
  45. DocSWAB

    DocSWAB

    Joined:
    Aug 28, 2006
    Posts:
    615
    Thanks Chris. Being very inexperienced with shaders, I may or may not be able to dig into this, but I'll put in on the list of experiments to try!
     
  46. vincenzoalbery

    vincenzoalbery

    Joined:
    Jul 13, 2010
    Posts:
    27
    It is great!

    Regards
     
  47. impheris

    impheris

    Joined:
    Dec 30, 2009
    Posts:
    352
    not work for me :( so many errors
     
  48. Quickfingers

    Quickfingers

    Joined:
    Aug 29, 2009
    Posts:
    264
    hey chris, tried to download this today but site was timing out :( hope you can fix really want to try this out
     
  49. Demostenes

    Demostenes

    Joined:
    Sep 10, 2010
    Posts:
    1,106
    Amazing job! I really dont understand, why this isn´t in unity by default.
     
  50. Demostenes

    Demostenes

    Joined:
    Sep 10, 2010
    Posts:
    1,106
    Normal map should be imported as texture, or as normal map? Both works, but in different way and i am not sure, what is correct output....