Search Unity

Question about terrain shaders?

Discussion in 'Editor & General Support' started by bigkahuna, Sep 19, 2006.

  1. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    I searched here and the wiki and found some very nice, multi-texture terrain shaders (2 layer, 3 layer and 4 layer). But what I didn't find is a multi-texture shader that also supports bump mapping. Does this exist? Thanks!
     
  2. Alpha-Loup

    Alpha-Loup

    Joined:
    Jun 23, 2006
    Posts:
    797
    I just wanted to post this myself a few days ago :D
     
  3. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Well... aside that you can always write one yourself :roll: Do you want multiple base textures and a single bumpmap on the terrain? Or do you also want to mix multiple bumpmaps?

    Also, keep in mind that a bumpmapped terrain may quickly get very expensive to render. Bump-mapping by definition is per-pixel lighting, and it's much slower than the vertex lit terrain shaders.
     
  4. Alpha-Loup

    Alpha-Loup

    Joined:
    Jun 23, 2006
    Posts:
    797
    Well, my skills as a script kid are well evolving :D

    What i am currently trying to do (thats the reason why i did not post it ;) ), is using a single bump or normal map on a 4 level layerd terrain. I now know how to blend textures using alphas (YEAH!) and my layered shader works already.
    And i will surely get those bumps in... somehow and if necessary with a sledge hammer...

    If i get this one finished, hopefully, i will post it.

    Got any general advice, basic approach or dontdo´s for a complete code-newbie?
     
  5. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    Also just wanted to remind, if the lights don't move in the scene, the bump mapped terrain is pointless and could just be made with normal diffuse texturing.

    -Jon
     
  6. Alpha-Loup

    Alpha-Loup

    Joined:
    Jun 23, 2006
    Posts:
    797
    Yes, sure.

    A better approach is to build some eye-catchers and place them somewhere important instead of doing a complete bump-mapped terrain.
    But there are places in a level where such a shader could be very useful. Caves for example, where the player´s got the only light source.

    And it is a good point to start, when learning how to programm shaders. The code structure isnt that hard to understand (so far...) and you get fast and satisfying results...
     
  7. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    @Jon:
    Not necessarily true - you can use bump maps like detail maps. I've also used bumpmaps for general terrain shading - If you generate a bumpmap of your terrain at 1024x1024 it gets REALLY nice shading no matter if it's actually quite lowpoly.
     
  8. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Never tried to write a shader before so I thought I'd ask before getting started...

    I thought I'd start with a single bumpmap, but would prefer to use multiple bumpmaps so I can tile them over large areas.

    Yes, I realise this. I've got pretty complex (ie. expensive) lighting in my underwater scene: I'm using an animated cookie on a directional light to simulate caustic effects and the user's vehicle has two spot lights they can direct into dark "caves". I'm getting about 45 - 50 fps on my Macintel iMac at max resolution, which I'm guessing means a lesser machine would get half that framerate or less.
     
  9. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770

    Attached Files:

  10. Alpha-Loup

    Alpha-Loup

    Joined:
    Jun 23, 2006
    Posts:
    797
    :D

    Well, thanks Aras! I cant wait to analyze it!

    I love this forum.
     
  11. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    Still trying to understand this. :) The bump map buys you better shading than just vertex shading. I get that. But if the lights are static shouldn't that all be baked into a lightmap?

    Also, is a detail map cheaper than a bump map? Why would you prefer to use a bump map? Thoughts are appreciated.

    Thanks
    -Jon
     
  12. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    WOW :!: Thanks :!:
     
  13. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    For a start, yes, if the lighting is static, there's (almost) no reason to use bumpmaps. There may be some reason to use them, if your terrain is really very-non-flat and bumpmap contains steep areas. In that case a "real bumpmap" will get proper lighting, whereas a baked texture, tiled over the terrain only approximates that (because the same texture is tiled over flat and steep terrain areas).

    Yes, a detail map is cheaper. A lightmap is cheaper. Mostly because both don't require using pixel lights, so you can just use vertex lighting.

    So about the only reason is "correctness" (see above) or per-pixel effects such as light cookies and good looking small point lights near the terrain. In that case you need a pixel lighting shader; and a diffuse+bump is not much more expensive than just per pixel diffuse (a couple of instructions and one more texture to read).