Search Unity

Custom terrain shader with 8 textures -- use AddPass or multiple splatmaps in FirstPass shader?

Discussion in 'Shaders' started by luellasfpg, Aug 7, 2019.

  1. luellasfpg

    luellasfpg

    Joined:
    Jan 23, 2019
    Posts:
    16
    Hi everyone, I'm trying to create a custom terrain shader and from what I understand, you have a Base shader, a FirstPass shader which adds 4 textures to blend onto the terrain, and then an AddPass shaders, each adding an additional 4 textures up to 16 total textures.

    However right now I'm skipping the AddPass shader and I'm using 8 textures directly in the FirstPass shader (image of node graph below). I'm doing 2D texture arrays to sample/store the 8 textures and then 2 splatmaps to blend them. How is this different from using a FirstPass + additional AddPass shaders? Which approach is "better"? Thanks :)
    Annotation 2019-08-07 105538.png
     
  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    4,950
    if "better" means faster: using a single pass should be better as it saves fillrate: each pixel covered by the terrain is only visited once.
    also doing it in a single pass makes things a bit more easy.
    it's been a while since i looked into terrain shading but from what i remember: unity prior to 2018.3. always did a 2nd pass if there were more than 1 splat map assigned to the terrain. in case you address unity < 2018.3. you may want to a) have a really cheap 2nd pass which renders simple white pixels below the terrain as rendered in the 1st pass (so all pixels will be rejected due to depth testing) or b) use the base shader as uber terrain shader doing detail splatting and simple shading using branching.
     
    luellasfpg likes this.
  3. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    894
    I believe part of the reason for the older terrain shaders doing that is to maintain compatibility with shading model <=3.0 APIs (like DX9) that can only support up to 16 samplers and has no texture arrays, of which a few Unity has to reserve for some things like lightmaps, so the process had to be split to multiple passes.

    If you can get away with one pass for your target platforms then all the power to ya, don't have to run your vertex program extra times either then.
     
    luellasfpg likes this.
  4. luellasfpg

    luellasfpg

    Joined:
    Jan 23, 2019
    Posts:
    16
    Thanks! I think I'll stick with my method of doing it then, it's just easier so far and we're targeting shader model 3.5+ anyways :)