Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Parallax mapping with built-in Unity terrain

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

Thread Status:
Not open for further replies.
  1. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259


    Image from Dawn of the Tyrant (In-development)



    Hey guys - here's our implementation of relaxed cone step mapping (from GPU Gems 3) with the built-in terrain.

    The parallax effect is applied to the texture as well as the normal map that was integrated earlier.

    Read more and download here: http://sixtimesnothing.wordpress.com/

    Enjoy!

    - Chris
    sixtimesnothing
     
    Last edited: Nov 10, 2010
  2. grfxman

    grfxman

    Joined:
    May 28, 2009
    Posts:
    309
    This looks Amazing Thank You !!
     
  3. puppeteer

    puppeteer

    Joined:
    Sep 15, 2010
    Posts:
    1,282
    Absolutely gorgeous!
    Your work is anything but "six times nothing" :)

    Keep it up.
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Looks rather cool :)

    Perhaps 2 level overdriven, but that might be the idea to show it off :)
     
  5. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Thanks a lot Chris!
     
  6. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Will give this a try, thanks!
     
  7. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,852
    Can we somehow use this for non terrain objects? Does it play properly with lights?
     
  8. LamentConfig

    LamentConfig

    Joined:
    Sep 28, 2010
    Posts:
    292
    Wow - looks like I may be re-doing my terrain again thanks to you guys :)
     
  9. Pulov

    Pulov

    Joined:
    Feb 20, 2010
    Posts:
    824
    Real depth feel. Looks awesome.
     
  10. liverolA

    liverolA

    Joined:
    Feb 10, 2009
    Posts:
    347
    wow,nice one
     
  11. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    Normals are inverted for me, if I whack a plane directly above a tile with the same setup (col, normal), the plane is right, but the terrain isn't. It could just be my card :eek:
     
  12. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    Would it be possible to post the sample set for that wood panel/4 primitives texture, incl. cone map?
     
  13. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,852
    The normals are inverted for me too actually.
     
  14. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    Argh - yea the tangent calculation seems to work for the parallax effect but not for the normals.

    I'll fix this today, tangent calculation in a vertex shader can be tricky :)

    @duke sure - it's attached
     

    Attached Files:

    Last edited: Nov 10, 2010
  15. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    Actually, I think the tangent calculation was correct on second glance.

    Make sure the normal maps you are using are set as "normal map" in the inspector, keeping the parallax map as "texture"
     
    Last edited: Nov 10, 2010
  16. 3dDude

    3dDude

    Joined:
    Jul 4, 2010
    Posts:
    1,067
    hey chris! first this looks AWESOME :O

    just one think ;)

    you said to use xnormal for converting to cone map.

    can you recommend a solution that works on a mac?

    thanks
     
  17. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    @3dDude - You know what, I'm even having a hard time producing good results using xnormal. I haven't been able to produce a usable cone step map yet.

    The algorithm for generating cone step maps is publicly available so it's very possible I might be writing my own converter using Unity so it would work with mac and windows.
     
  18. 3dDude

    3dDude

    Joined:
    Jul 4, 2010
    Posts:
    1,067
    ok thank you for replying so fast!

    I'm look forward to seeing a working converter!
    once again thank you!
     
  19. LumaPxxx

    LumaPxxx

    Joined:
    Oct 3, 2010
    Posts:
    339
    oh,thank you~that is what i need in a long time.
     
  20. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    I got weird results with the stuff that came out of xnormal. Instead, I fed it a normal map with inverted height in the alpha (so the lowest points are white, highest black) which I found by googling cone-maps.

    Also this *may* have been my problem, not at home right now (from 3.1 notes):

    Graphics: fixed tangent vectors not bound correctly with GLSL shaders on some GPUs.
     
    Last edited: Nov 11, 2010
  21. minevr

    minevr

    Joined:
    Mar 4, 2008
    Posts:
    1,018
    Wow..cool.but,no easy..Who can give a demo project.Thanks.
     
  22. Westmark

    Westmark

    Joined:
    Nov 1, 2009
    Posts:
    187
    Really awesome :D

    On a side note, would it be possible to convert your shader to make it work like a normal shader? 'cus the unity built-in parrallax shader sucks. I had a quick look but was too confusing for me with all the links to the splatting and stuff :p
     
  23. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,880
    This parrallax shader doesnt use the already applied splat maps on the terrain right? We have to apply them manually through code?
     
  24. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    @Westmark - I agree, the built-in parallax isn't even really usable. I'll probably write some diffuse shaders soon. Anything I release is announced on my Twitter @_chris_morris and I don't write about what I ate for breakfast, just what I'm working on :)

    @Aubergine - You can paint and use the terrain textures the way you normally would, but you just have to let the shader know what those textures are in the splat slots, and what their tile size is. No extra manual code has to be written.

    Thanks for the feedback guys!
     
  25. Westmark

    Westmark

    Joined:
    Nov 1, 2009
    Posts:
    187
    Ok cool :D

    Edit:

    I've sent you a request on twitter :)
     
    Last edited: Nov 11, 2010
  26. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,880
    It is surely a nice addition and i thank you very much for this.
    One small problem is, when you cast shadows on the parralax terrain, it looks funny with the parrallax depth feeling and straight shadows on it. I dont think you might have a solution for this right?
     
  27. Demostenes

    Demostenes

    Joined:
    Sep 10, 2010
    Posts:
    1,106
    AFAIK this is technically not possible.

    MAYBE somehow modify shader to affect shadows from shadowmap, but not shadow from real light.
     
    Last edited: Nov 11, 2010
  28. Demostenes

    Demostenes

    Joined:
    Sep 10, 2010
    Posts:
    1,106
    I found interesting bug(?), if you place some objects (like painted trees) and you move against them, it looks like the floor is moving beneath them.

    Maybe it is wrongly generated cone map, but i dont know which are correct settings in xnormal.
     
    Last edited: Nov 11, 2010
  29. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    @Demostenes - Yea that sounds like an incorrect cone map. The setting for xnormal should be "relaxed" - but like I said earlier, I still haven't been able to produce a functional map yet. If I can't get it to work I'll be writing my own converter.

    Also, I think it would be a complicated process to get the shadows to offset with the textures. If I can think of a way to do this, I'll share it
     
  30. gamesurgeon

    gamesurgeon

    Joined:
    Oct 11, 2009
    Posts:
    427
    My question is how did you get such a nice GUI? :)

    Definitely the nicest GUI I've ever seen made in Unity.
     
  31. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,880
    I couldnt manage how to apply parallax to only 1 splat map and keep the rest unparallaxed. Can you enlighten me please.

    Even if i put normal and height maps to only 1 slot, the entire terrain is effected by the same maps.

    Which is pretty slow even for my pretty fast computer.
     
  32. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    @gamesurgeon - Our very talented co-founder, Sándor, did all of the UI graphics and functionality.

    @Aubergine - I actually scaled back the shader for our game as well, as 4 parallax in a single pass is quite heavy. What I did to scale it back to just 2 textures is cut out the parallax2 and parallax3 (they are commented as such) bits of code and replaced where the splat properties are set back to what they were with normal mapping. So for splats we don't wan't parallax, this is all we should see for the given splat:

    Code (csharp):
    1.  
    2. // 4 splats, normals, and specular settings
    3. col  += splat_control.b * tex2D (_Splat2, IN.uv_Splat2).rgb;   
    4. o.Normal += splat_control.b * UnpackNormal(tex2D(_BumpMap2, float2(IN.uv_BumpMap.x * (_TerrainX/_Tile2), IN.uv_BumpMap.y * (_TerrainZ/_Tile2))));
    5. o.Gloss += splat_control.b * _Spec2;
    6. o.Specular += splat_control.b * _Spec2;
    7.  
     
  33. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,880
    great, now i have 2 parallax and 2 normal mapped, still alittle bit of heavy though but allright.

    One more question, how can i add a second pass for 4 more splats (total 8) and make these new 4 only show texture color?
     
  34. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    @Aubergine - this is tricky... In a previous thread I suggested perhaps coding the pass number into the unused alpha channel of the texture. Something like this:

    if(tex2d(splat0, texCoord).a >0.5)
    // apply pass 1 splat0 and parallax 0
    else
    // apply pass 2 splat4

    There might be better ways of doing it, but in any case I think it has to be something tricky like this
     
  35. 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!
     
  36. dakasha

    dakasha

    Joined:
    Nov 20, 2010
    Posts:
    29
    ugh is there a short tutorial/description anywhere of how to get this to work correctly including the optimizations?

    I dont think im getting it set up right in the first place but im also getting only 12 fps (with nothing but the terrain and no background logic lol) on my crappy laptop

    great work though :)

    EDIT: ok i got it all working.. but even after removing 2 passes it is slooooooooooooooow on my laptop :(
     
    Last edited: Nov 24, 2010
  37. Demostenes

    Demostenes

    Joined:
    Sep 10, 2010
    Posts:
    1,106
    I have ancient video card (8600gt) and it was working OK, i had some 1k height map, 4 textures, no problem.....
     
  38. dakasha

    dakasha

    Joined:
    Nov 20, 2010
    Posts:
    29
    I have an ATI Radeon HD 3200

    When I add a terrain.. attach the script and the textures my framerate drops from about 350 (what i get without any extra terrains scripts) to about 12 I think (With 2 passes removed)

    I could be wrong on the framerate but it was not over 20. Dunno why its so slow for me. Is my card just absolute crap? Not a hardware guy heh :p
     
  39. Demostenes

    Demostenes

    Joined:
    Sep 10, 2010
    Posts:
    1,106
    HD 3200 is cca 2-3x slower than 8600GT, you can use this site http://www.videocardbenchmark.net/ to have at least some clue, how fast your graphic card approximately is. Anyway 12fps is very little, i had more than 100. Maybe theese old cards does not have some optimalizations for this...
     
  40. dakasha

    dakasha

    Joined:
    Nov 20, 2010
    Posts:
    29
    Hmm well either way Im happy to know that the scripts are feasible(not that i doubted it).. If it can run on a "real" computer then cool.
    And yes I suspect it my be an optimization issue.. Because I'm not simulating anything else
     
  41. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    Parallax mapping is by nature not a super fast shader. To optimize you can lower the step and binary search iterations, and use only 1 or 2 parallax textures (by manually removing the code in the shader - leaving them blank in the script isn't enough).

    On my test machine I can run 2 parallax textures without any drop in FPS at all (8800 GTX)
     
  42. dakasha

    dakasha

    Joined:
    Nov 20, 2010
    Posts:
    29
    Heh not the deal with me :p
    But on a side note.. Is there an alternative to xmapper for creating the cone maps? That program (also) runs WAY to slow and has in fact crashed my machine

    I have a fresh install of windows too :p

    I guess my laptop just isnt the best graphics "rig".
     
  43. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    @DakaSha - (did you mean xnormal?) I'm actually still searching for a good source for generating these maps. Any method is going to be slow, because of the generation process, but I actually haven't found xnormal to be very reliable.

    We are very busy on other aspects of our game, but I will likely write a converter myself when I can find the time. I'll definitely update everyone on that.
     
  44. dakasha

    dakasha

    Joined:
    Nov 20, 2010
    Posts:
    29
    whoops yeah I meant xnormal.

    Ok cool. I'm new to unity but already I really respect your work (I also use your terrain tools). thanks alot :)

    I have about 0 experience with any kind of 3D modeling but wouldnt it be possible/ best to just get the normals and cone maps from a model? When it's an option of course
     
  45. Chris Morris

    Chris Morris

    Joined:
    Dec 19, 2009
    Posts:
    259
    Depending on what the team needs, a modeler usually provides a wide range of different maps. I think in a normal asset pipeline, they will provide you with a displacement map (basically a heightmap) that is the source for creating pretty much any kind of parallax effect. Then depending what the team needs, it can be further converted into a specific format like relaxed cone step.

    p.s. - thanks for the kind words!
     
  46. handsomePATT

    handsomePATT

    Joined:
    Nov 30, 2010
    Posts:
    574
    hey can someone send me this the download link does not work for me. thanks!
     
  47. snoche

    snoche

    Joined:
    Feb 22, 2010
    Posts:
    82
    Thank you very much, do you know how we could control the shininess of th especular? (like with the unity Bumped Specular)
     
  48. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,880
    In the script there are specular variables which you can adjust the shininess.
     
  49. JJJohan_legacy

    JJJohan_legacy

    Joined:
    Dec 24, 2010
    Posts:
    13
    Would anyone be able to assist me in getting xNormal to create a relaxed cone map? I figured out I have to use the 'height to cone map' tool, set it to 'relax' and generate the map from an imported height map.

    However, the problem is it comes out in greyscale, even when saving and appears nothing like the sample materials posted earlier in this thread.


    (note the larger image is cut from Photoshop, not the output)
     
  50. snoche

    snoche

    Joined:
    Feb 22, 2010
    Posts:
    82
    Instead of the normal map you are using, try using a height map (aka displacement map , black and white texture ) on the left and select grey as Height source .
     
Thread Status:
Not open for further replies.