Search Unity

Farfarer is a genius: triplanar projection on built-in terrain

Discussion in 'Made With Unity' started by PrimeDerektive, Dec 1, 2011.

  1. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    Last edited: Dec 7, 2011
    Kos-Dvornik and rakkarage like this.
  2. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    And now....where is the shader? I mean it will be shared or not?
     
  3. RandAlThor

    RandAlThor

    Joined:
    Dec 2, 2007
    Posts:
    1,293
    I like it and want to know more too.
     
  4. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
  5. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Oh wow...thanks man...you too Farfarer :).....
     
  6. Rush-Rage-Games

    Rush-Rage-Games

    Joined:
    Sep 9, 2010
    Posts:
    1,997
    Nice!

    Thanks for sharing!
     
  7. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    oh...it didn't support lightmap and ambient light?
     
  8. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Balls, I forgot ambient light :p

    I'll add that in, watch this space.
     
  9. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,208
    Looks very good. Any thoughts on combining this with the other shaders that add bump-mapping to terrain?
     
  10. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    It is actually already... both bump and specular maps.
     
  11. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
  12. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    @Farfarer : Why not using surface shader instead rather than vert-frag?
     
  13. Blacklight

    Blacklight

    Joined:
    Dec 6, 2009
    Posts:
    1,241
    Someone give that man a medal!
     
  14. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Btw...how many texture limit for terrain actually, is it only 4 layer (with difuse,bump,spec map in every layer)?
     
  15. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    rea:

    'Cause Surface Shaders suck for complex stuff.

    Also, yes 4 distinct layers with bump/spec/gloss/normal. Controlled by the terrain's regular painting system.
     
  16. Ben-Massey

    Ben-Massey

    Joined:
    Jun 13, 2011
    Posts:
    581
    Will definitely be checking this out, thanks!
     
  17. schizzore

    schizzore

    Joined:
    Oct 17, 2011
    Posts:
    14
    im sorry, i dont get it clearly, instead of using single texture for the terrains, this package allow us to use Parallax Shader to the terrain?
    and also, is it able to intergrate with http://insidious.pt/#amplify
     
  18. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Updated package - now converted to a surface shader so it'll handle lightmaps and such like;

    http://www.farfarer.com/temp/triPlanarTexture.unitypackage

    schizzore;
    No parallax shaders.
    No virtual texturing, either. For that you'll have to use a bespoke mesh, rather than a Unity Terrain.
     
  19. schizzore

    schizzore

    Joined:
    Oct 17, 2011
    Posts:
    14
    sorry for my lazyness, after reading now i know, this is a great package, thanks for sharing
     
  20. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Updated with up to 8 textures blending together.

    Each texture has it's own tiling parameter now, too - rather than one for all of them.

    Custom script inspector added to make things a little easier to set up.

    http://www.farfarer.com/temp/triPlanarTexture.unitypackage


    By the way, if anyone knows how to directly access the terrain's materials, I'd be much obliged. At the moment it's all global varialbes so it will only work properly with a single set of 8 textures (across as many different terrains as you want).

    If I could get to the material it uses, I could set it up to have a fully custom set on each terrain object.
     
    Last edited: Dec 7, 2011
  21. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
  22. fremachuca

    fremachuca

    Joined:
    Oct 13, 2010
    Posts:
    26
    going to try it out right away!
     
  23. fremachuca

    fremachuca

    Joined:
    Oct 13, 2010
    Posts:
    26
    i got something wrong going on. this is what i get after i unpacked the package.







    if i move the camera far from the terrain it looks fine.
    if i start getting closer with the camera, as soon as the resolution of the terrain goes up, these black areas appear.
    and one of the textures becomes a gray color.
    *it seems to black out totally surfaces that are parallel to the camera. (like in the last image)

    some info:
    my terrain is
    100x100 in width
    50 height
    1024 detail, base map and height resolution
    512 control
    8 detail per patch
     
    Last edited: Dec 7, 2011
  24. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Doesn`t look much healthier here. I get a flat colour where the texture should be. Does this pack require Pro?

    EDIT, nope, i just need to raise the texture tiling. Default 0.1 is a bit too small. Really great script :)
     
    Last edited by a moderator: Dec 7, 2011
  25. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Won't require Pro.

    Not sure what's wrong, it works fine here. I'll look into it tomorrow.

    Sorry dudes - will fix asap.
     
  26. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,913
    I had to delete any textures already applied to my own terrain. Try that.
     
  27. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Hmmm... it doesn't modify the textures applied to the terrain already.

    It picks 'em out to show you them in the inspector, but it doesn't do anything with them.

    Very strange.
     
  28. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    I have toyed a bit around and found a few more issues. Just in case you have some spare time left :)

    First one is obviously a projection issue. Some of my faces receives a by a too flat angle disorted UV mapping. See picture. Is there a way to adjust the projection angle? Or is this a limit of the method?

    Second one is that it doesn`t want to work with more than four textures really. See picture 2. As you can see, the fifth texture does not display. And i get a black seam where it should blend.

    Third thing i noticed is that it has an update problem. I need to click at the terrain that the changings gets applied. Which leads me to issue four. At one point it stops updating. No more changings possible.

    I have also a question about the Specular / glossy part. There is no specular map applied. But my terrain is showing specular effects than there would be a white image applied. Means full power. Shouldn`t the specular effect be zero without a specular map?

    I hope i don`t bug you too much :)
     
  29. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    The default spec/normal stuff is now fixed.

    The update thing... I'm not entirely sure about. I'll look into it.

    The black border around the 5-8 texture layer I'll look into, too. It's (I think) something to do with the spec/gloss being multiplied out based on the blending and resulting in really darkly lit areas around the blend.

    Texture stretching may well be a limitation of the method. I've not come across anything that's too bad but it could be the order I'm blending stuff back together.

    I'll get an update out in a few hours - can't work on it 'til my lunch break :)
     
  30. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Take your time. It`s done when it`s done :)
     
  31. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Mostly it's all sorted except the strange dark border on the second pass (layers 4-7). Not sure how/if I can get around it without some odd side effects. It'll need some extensive twiddling :p

    I've also discovered I screwed up the tangent space when improving the blending so I've fixed all that up now and shading/highlights should work correctly again.
     
  32. Enzign

    Enzign

    Joined:
    Aug 20, 2010
    Posts:
    169
    This is a sweet script Farfarer. Very impressive. :)
     
  33. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Package has been updated.

    Now applies default textures if you don't supply a normal or spec texture.

    The blending issue is still there between the first 4 and second 4 textures... I can't get rid of it completely but I've tried to minimise the effect as much as I can.

    Tri-Planar Terrain

    If you want a cheaper version that only does diffuse maps (but no blending artifacts between first and second 4), get it here;
    Tri-Planar Terrain (Diffuse Only)
     
    Last edited: Dec 9, 2011
  34. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Yeah, Farfarers daily builds :D
     
  35. fremachuca

    fremachuca

    Joined:
    Oct 13, 2010
    Posts:
    26
    first of all, thanks for this awesome shader! cant wait to use it for real!

    now to the problem.
    downloaded the latest version, created a new project and opened the scene that comes with the package.
    played around with it a bit to try to find out whats up with these black areas.

    it creates this black area on any polygon that is facing -X ( in a 180 degree range)
    if the map is flat (all polygons facing +Y) no black areas appear


    basemap dist. set to 2000


    basemap dist. set to 0
    **pictures with ambient light only

    so a couple of details:

    this black area is not affected by lights (lighting, shadows, rotation)
    its not affected by ambient light or fog
    it doesn't matter if u have textures or not (deleted all 4 textures that come with the scene)
    as soon as i delete the script and shader folders, it comes back to normal.
     
    Last edited: Dec 10, 2011
  36. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    I'm stumped, works fine on my PC.

    Have you tried hitting Play and see if they go away?
     
  37. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    Are you on a Mac, frem? I remember a similar issue with werewraiths tri planar shaders on macs for whatever reason.
     
  38. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    @framachuca Did you maybe forgott to set normal map and tiling under normal/specular maps?
     
  39. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Those values should default out, janpec.

    It looks to me like some kind of graphics card issue :/
     
  40. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Just opened the default scene on my Macbook Pro and got to agree, Farfarer is a genius! :)
     
  41. chadchat

    chadchat

    Joined:
    Apr 5, 2008
    Posts:
    154
    I'm getting the black on my macbook pro
     
  42. fremachuca

    fremachuca

    Joined:
    Oct 13, 2010
    Posts:
    26
    yeah, im on a macbook pro. my graphic card is a geforce 8600m gt 128mb.
    the black areas continue even after hitting play. ;(
     
  43. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    Some people had the same exact issue with werewraiths triplanar shader on older MacBooks, I doubt that is a coincidence
     
  44. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Ergh, I'm not sure what to do about that. I've not got any Apple things to test on.

    How was the other triplanar stuff fixed on Mac? Anyone know?
     
  45. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    He didn't, he just has on the asset store description "only for windows", hehe.
     
  46. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Oh, that's cheap, heh.

    I may have to take the same approach.

    I'll look into it more later, really gotta get back to my own stuff for the time being.
     
  47. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    No issues on my Macbook Pro, but it has the old ATI X1600 graphics board which may be why.
     
  48. fremachuca

    fremachuca

    Joined:
    Oct 13, 2010
    Posts:
    26
    so maybe its something with mac + geforce?

    hope u find a way to get around this little problem! only being able to use the shader on windows will definitely limit
    its use, specially on a multiplatform engine like unity!
     
  49. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Out of curiosity - does the same thing happen if you try it with the "diffuse only" version?

    There's not a lot I can do to fix this as I have no Macs to test it on :/
     
  50. fremachuca

    fremachuca

    Joined:
    Oct 13, 2010
    Posts:
    26
    on my macbook pro with geforce graphic card, the black areas appear even if using the diffuse only package.

    now, i tried both packages on my mac pro with a ATI radeon card, and NO black areas!

    so maybe its really something with geforce cards + mac?

    ill try to test the shader out on some other macs, and see if i get any new results.