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

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
    @Demostenes - I think the only difference is the compression. The shader is meant to unpack a normal map so I would import as normal map.

    @quickfingers - It shouldn't have been down too long, I hope you got a chance to download it. P.S. - your website and projects look great!
     
    Last edited: Oct 23, 2010
  2. 3dDude

    3dDude

    Joined:
    Jul 4, 2010
    Posts:
    1,067
    hey chris any updates on parallax mapping yet?

    thanks
     
  3. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    @3dDude - I'm actually working on different feature at the moment (which I may also release) but parallax will be finished in the next 2 weeks for sure and I'll update everyone.
     
  4. Demostenes

    Demostenes

    Joined:
    Sep 10, 2010
    Posts:
    1,106
    Well, i am not quite sure:

    http://img801.imageshack.us/img801/7366/bumpvsnormal.jpg

    First is without bump. Second is imported as normal map and third is as texture.
    Compression can be checked separately fo each type and it have very minor efects on quality.
     
    Last edited: Oct 23, 2010
  5. 3dDude

    3dDude

    Joined:
    Jul 4, 2010
    Posts:
    1,067
    Awesome looking forward to trying it!
     
  6. Westmark

    Westmark

    Joined:
    Nov 1, 2009
    Posts:
    187
    Any news on this one? :)
     
  7. LamentConfig

    LamentConfig

    Joined:
    Sep 28, 2010
    Posts:
    292
    Well, I've got this up running in my test version of SpaceOreMiner (not uploaded yet, quite a large graphical overhaul going on atm :) ) - it makes such a huge difference to the look and feel of the terrain. No idea why this wasn't included as default in unity as the difference is vast .. thanks for the great work :) Was so simple to get working and most importantly : its might purdy :D
     
  8. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    It would be pretty rad if you added a normal map for the base map (the one it fades too at distances). This would allow you to get away with having the pixel error much, much lower while retaining the appearance of detail!

    You can grab the normal map itself from Terrain.terrainData.GetNormals() or whatever.
     
  9. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    Hey guys,

    I'm going to be working on the parallax this week, so expect an update this weekend. Also, keep in mind these releases are for our game's needs - I wish I could fulfill some of the feature requests I've been getting for the tools and stuff, but I gotta keep moving forward with the game :)

    And thanks for the feedback!
     
  10. Samsson

    Samsson

    Joined:
    Oct 12, 2010
    Posts:
    165
    A BIG thanks to you chris, it was a miss into unity.
    I'm really waiting for parallax mapping.
     
  11. Hans

    Hans

    Joined:
    Feb 20, 2007
    Posts:
    422
    great tool, will come in very handy.
    also the river tool - in the download were is the "Unzip and import "PublicRiverTool.unitypackage" into your project." there is no such file in the download?

    thanks

    Hans
     
  12. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    @Hans - You don't have to import anything, just copy the folder that you unzip directly into the assets folder of your project
     
  13. Hans

    Hans

    Joined:
    Feb 20, 2007
    Posts:
    422
    Hello Chris

    ah ok :)

    Thanks for the quick reply :)
     
  14. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    Diddled with the shader a bit to do this. I need to find a different way of doing though - the limitation is visible between rock/grass :|

     
  15. Artimese

    Artimese

    Joined:
    Nov 22, 2009
    Posts:
    794
    A great tool however you cant see all the specularity bump at certain angles, so for example for rain, it doesnt look right because you only see the water (specularity) at certain angles. Is there a way to fix that where you can see all the specularity on the whole terrain no matter what angle your at?
     
  16. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    You'd probably want a headlight for rain. Or use reflectivity/cubemap. I just played Modern Warfare2 and started playing Arcania, both of which have really brilliant rain effects that make the ground look wet and mushy, with visible waterflow on inclines.
     
  17. Westmark

    Westmark

    Joined:
    Nov 1, 2009
    Posts:
    187
    sorry... I'm curious :p what is the other feature you're working on? :p
     
  18. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
  19. Westmark

    Westmark

    Joined:
    Nov 1, 2009
    Posts:
    187
    yeah i saw that :p but he said that he was working on another thing too... that he might release too :)
     
  20. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    Well it's not exactly a missing feature - but for our game we decided we needed a better shadow solution. Something that worked on the grass and details and was stable (doesn't distort when moving camera). I designed a pretty cool system that I'm going to be working on more next week - should be faster, use less memory, and be higher quality.

    Our team has quite a few planned releases in the future so it's best just to follow us:

    @sixtimesnothing - Sándor
    @_chris_morris - Me
     
  21. Artimese

    Artimese

    Joined:
    Nov 22, 2009
    Posts:
    794
    Uhm what do you mean by a headlight, or use reflectivitiy/cubemap, ive never used those shaders before.
     
  22. Migueljb

    Migueljb

    Joined:
    Feb 27, 2008
    Posts:
    562
    Hey Chris,

    First off thanks for sharing such a great script works and looks great.

    I noticed in deferred rendering the specular gets all white and it only does this in deferred rendering which pretty much you have to use to use the get the best out of unity's lighting features. Also on terrain sometimes in some angles the bumpmapping disappears as well. Is this a lightmap issue or something else? Not really sure what's causing that to happen or how to fix that. Hopefully you've seen these probs and already fixed these problems. Thanks.

    -Miguel
     
  23. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    @Miguel - The shader does work in deferred lighting - lower the specular values if it's too white. If you're using lightmapping make sure it's on dual lightmaps and that your light source is set to "Auto". Lastly, make sure the terrain's base map distance is turned up.

    @Duke - Be sure to let us know if you get that working. Would be a great addition.

    @ Artimese - It is the nature of specular reflections to be view angle dependent. If you want a rain soaked ground you'd have to add new functionality to the shader.
     
  24. Artimese

    Artimese

    Joined:
    Nov 22, 2009
    Posts:
    794
    Where would i go about adding a new function to the shader, ive never wrote my own shaders before.
     
  25. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    You're better off chasing this in the ShaderLab forum. I'm new to shaders too, but I opened this one and it all looked fairly familiar so I just tried stuff out :)
     
  26. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    Ok, done.






    Throw this above the vert method:
    Code (csharp):
    1.  
    2. float overlayBlend (float value1, float value2, float opacity)
    3. {
    4.     float blend = value1 < 0.5 ? 2 * value1 * value2 : 1 - 2 * (1 - value1) * (1 - value2);
    5.    
    6.     return lerp(value1, blend, opacity);
    7. }
    8.  
    9. half4 filterMask (half4 mask, float2 uv, float amount)
    10. {
    11.     half r = overlayBlend(mask.r + mask.g + mask.b + mask.a, tex2D (_Splat2, uv).a, amount);
    12.     half g = overlayBlend(mask.g + mask.b + mask.a, tex2D (_Splat2, uv).a, amount);
    13.     half b = overlayBlend(mask.b + mask.a, tex2D (_Splat2, uv).a, amount);
    14.     half a = overlayBlend(mask.a, tex2D (_Splat2, uv).a, amount);
    15.  
    16.     r = r - g;
    17.     g = g - b;
    18.     b = b - a;
    19.  
    20.     return half4(r, g, b, a);
    21. }
    22.  
    ...and this is the surf shader. Feel free to alter/comment/post better code ;)

    Code (csharp):
    1.  
    2.         void surf (Input IN, inout SurfaceOutput o)
    3.         {
    4.             half4 splat_control = filterMask(tex2D(_Control, IN.uv_Control), IN.uv_Splat2, 1);
    5.             half3 col;
    6.  
    7.             // 4 splats, normals, and specular settings
    8.             col += splat_control.r * tex2D (_Splat0, IN.uv_Splat0).rgb;
    9.             col += splat_control.g * tex2D (_Splat1, IN.uv_Splat1).rgb;
    10.             col += splat_control.b * tex2D (_Splat2, IN.uv_Splat2).rgb;
    11.             col += splat_control.a * tex2D (_Splat3, IN.uv_Splat3).rgb;
    12.  
    13.             o.Normal += splat_control.r * UnpackNormal(tex2D(_BumpMap0, IN.uv_Splat0));
    14.             o.Normal += splat_control.g * UnpackNormal(tex2D(_BumpMap1, IN.uv_Splat1));
    15.             o.Normal += splat_control.b * UnpackNormal(tex2D(_BumpMap2, IN.uv_Splat2));
    16.             o.Normal += splat_control.a * UnpackNormal(tex2D(_BumpMap3, IN.uv_Splat3));
    17.  
    18.             // Bug? Gloss is Spec, Spec is Gloss!
    19.             o.Gloss += _Spec0 * splat_control.r;
    20.             o.Gloss += _Spec1 * splat_control.g;
    21.             o.Gloss += _Spec2 * splat_control.b;
    22.             o.Gloss += _Spec3 * splat_control.a;       
    23.  
    24.             o.Specular += 0.4 * splat_control.r;
    25.             o.Specular += 0.4 * splat_control.g;
    26.             o.Specular += 0.4 * splat_control.b;
    27.             o.Specular += 0.4 * splat_control.a;
    28.  
    29.             o.Albedo = col;
    30.             o.Alpha = 0.0;
    31.         }
    32.  
    At the moment the blend texture is using the alpha of Splat2. I'll change it later to use a separate texture.
     
    Last edited: Nov 4, 2010
  27. Westmark

    Westmark

    Joined:
    Nov 1, 2009
    Posts:
    187
    That is super cool :D
     
  28. Westmark

    Westmark

    Joined:
    Nov 1, 2009
    Posts:
    187
    "Throw this above the vert method:"

    Where is the vert method?

    Is that inside the vertex program?

    No matter where i paste i keep getting errors :/

    Edit:

    Ok i think i got it working now :) at least no more errors.
    Just pasted it directly above the surf :)
     
    Last edited: Nov 4, 2010
  29. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    @Duke - nice work!
     
  30. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    Alright guys, here's an update on the parallax. The effect is finished, I just need to fully integrate it with the script.

    I'm heading out of town for a couple of days and when I get back I'm going to make a new topic releasing the shader. Here's a quick look:

    http://oi54.tinypic.com/1zwykrb.jpg
     
  31. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Cool. We are waiting ...
     
  32. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    Quick update: Our team encountered a bug that only showed itself in a build version, and it is now fixed - you can download it from the same link in the blog from the first post.

    Thanks!
     
  33. purpleduck

    purpleduck

    Joined:
    Oct 22, 2010
    Posts:
    11
    Thanks for your remarkable work Chris!

    In particular the implementation of cone relief mapping is something beyond my expectations which I've been waiting for for some time. Somebody else made a cone relief shader but it wasn't working with Unity's lighting. Gonna test yours extensively!
     
  34. dakasha

    dakasha

    Joined:
    Nov 20, 2010
    Posts:
    29
    hmm since the parallax mapping was so slow for me i decided to use this.. It works great but i have one problem.

    The terrain always has a "base brightness" it seems. Even without a light it is way to bright (like early morning for lack of better explanation)

    Is there a way to make things actually dark?
     
  35. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    Even with no normal maps? Also, make sure you're using 3.1 as it fixes some tangent stuff on some video cards.
     
  36. dakasha

    dakasha

    Joined:
    Nov 20, 2010
    Posts:
    29
    Yeah even with no normal maps. It's basically impossible to create a nighttime scene it seems. And yes I'm using 3.1
     
  37. aspide

    aspide

    Joined:
    Nov 16, 2009
    Posts:
    54
    Something strange is happening here, I've installed correctly (i suppose) the files but it works fine only in deferred rendering and not in forward. In forward rendering the bump mapping seems not being applied. Either iI'm doing something terribly wrong or is there maybe a bug ? Anyone else have had this problem before ?
     
  38. Demostenes

    Demostenes

    Joined:
    Sep 10, 2010
    Posts:
    1,106
    Do you have normal map flagged as normal map? Some shaders in unity are making material too bright, until you put normal map flagged as normal map.
     
  39. dakasha

    dakasha

    Joined:
    Nov 20, 2010
    Posts:
    29
    yeah they are flagged as such. I may just be doing something wrong/stupid though. Ill check something out when i get back on it
     
  40. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    @Demostenes - the specular setting might be doing this, try lowering it and seeing if it resolves the issue
     
  41. sh0v0r

    sh0v0r

    Joined:
    Nov 29, 2010
    Posts:
    325
    This is really cool thankyou so much!

    Should the specular work with a Directional Sun light, my sun directional light doesn't seem to be creating any specular highlights.

    Also what should the values be for spec?
    I'm using 1 anything higher and it becomes too shiny
     
    Last edited: Dec 23, 2010
  42. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    Specular highlights are kind of a tricky thing to see sometimes, but yes they should be there. They are dependent on the camera angle, so if you have a hard time seeing them, try moving around and trying to find the correct angle from the camera to the surface to the sun.
     
  43. sh0v0r

    sh0v0r

    Joined:
    Nov 29, 2010
    Posts:
    325
    Thanks for the response Chris, I'm aware of how specular works with respect to the light source and the camera angle.

    What I found is that after adding an additional directional light to the scene they suddenly appeared.

    I noticed some strange things were I had to add 2 directional lights to the scene for them to show up.

    This would require me to reduce the intensity as they doubled up on each other, removing one of them would make the specular disappear.

    Incase you're interested, you can see how I am using it in my project here www.shovsoft.com

    Thanks again for sharing this man its really cool!
     
  44. sh0v0r

    sh0v0r

    Joined:
    Nov 29, 2010
    Posts:
    325
    One extra question...

    Does the specular just use the normal map or does it use the alpha channel from the diffuse map in the tile?
     
  45. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    First of all, fantastic project - really interesting!

    I'm not sure why a single light wouldn't produce specular highlights. The specular component is calculated inside Unity's surface shader functionality using the normal map, so there isn't much I can think of on my end to troubleshoot it - I also can't seem to reproduce it. Just a shot in the dark, but make sure the normal map is flagged as such in the inspector for the texture. Sometimes just leaving it as a texture map produces strange results.

    Anyway, I hope you get the functionality you need out of it one way or another - good luck with the project, it's really impressive
     
  46. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,878
    Would it be somehow possible to use projectors only effect 1 texture?
    There is a tag "IgnoreProjector"="True", but it then ignores projectors for the whole thing.

    Or another solution for me might be adding a 5th texture to be used as detail texture but how would i use it to blend with 1 of the splats only?
     
  47. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Hi Chris!

    Awesome work figuring this out. I've optimized the script and shader a bit for our use here, and since you've shared your code freely I'll follow suit: http://www.nextrevision.com/dotc/terrainnmap.zip

    Notable changes:
    - Removed the terrain size and tiling parameters -- normal maps typically always align with diffuse maps, so there is little use for additional shader uniforms.
    - Specular component is now assumed to be in the Normal Map's Alpha channel.
    - Material shininess component can now be controlled (for each texture set).
    - Eliminated the 'if' condition in the shader. Arithmetical operations tend to be faster, especially on older cards.
    - Optimized the shader.
    - The script doesn't need to be attached to the terrain anymore -- it can go onto a configuration game object if desired.

    Note: Normal maps used with my modified script must NOT be marked as "Normal Map". They should be truecolor textures instead. Also, I've removed the 'Update' function for efficiency's sake, so changes made while the game is running will not take effect.

     
  48. forgottenmindset

    forgottenmindset

    Joined:
    Dec 3, 2009
    Posts:
    72
    Hey this is really cool, but I'm using unity 3.1 free and it seems to be working, except I get, some dark artifacts, but mainly pure white sploches everywhere there's direct light shining. It doesn't matter how amplified the lighting is, and I've been tweeking my bump map every which way to no change.

    Basically if there's direct lighting then it's pure white and black dots like the grass uv i made for it.

    Is there some tweak I can do? or is it because I'm using the free version?
     
  49. forgottenmindset

    forgottenmindset

    Joined:
    Dec 3, 2009
    Posts:
    72
    ok I take it back, it was just because I didn't reload the level, sometimes it autoreloads the bump texture, sometimes it won't...

    thanks!

    any word on making a paralax version?
     
  50. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259