Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Terrain AddPass Turn off alpha blending

Discussion in 'Shaders' started by MathewHenson, Nov 7, 2019.

  1. MathewHenson

    MathewHenson

    Joined:
    Apr 6, 2019
    Posts:
    2
    Hi there

    Is it possible to change the terrain shader's "AddPass.shader" to draw over the existing textures as opposed to using additive blending. Essentially what I want is that the AddPass simply draws over the existing terrain wherever the alpha is 1, and draw nothing when its 0. I've tried removing the "decal:add" option, but this seems to cause issues with the fog calculation. The same happens when I use "decal:blend". The areas seem to go black and are unaffected by fog.

    The reason why I need this is because I have a terrain with many layers and I want the higher layers to be drawn over the lower ones. Because the technique is additive I get areas where the terrain starts going white is some areas. I am generating the alpha splat programmatically. So its possible to get values in the alpha map as such:

    Code (CSharp):
    1. heightmap[x,y, 0]  = 0.1f;
    2. heightmap[x,y, 1]  = 0.1f;
    3. heightmap[x,y, 2]  = 0.1f;
    4. heightmap[x,y, 3]  = 1;  // This can be 1
    5. heightmap[x,y, 4]  = 1; // This can also be 1
    Because index 3 and 4 are both 1, the terrain goes white in those areas.

    terrain.PNG

    As you can see the desert texture in the corner gets stronger as it gets the edge, but also whiter because the alpha values for the underlying textures are also getting strong. I want it so that the desert texture is simply drawn over the other textures as opposed to being added together.

    Is this possible? Many thanks for any insight :)

    This is when I remove the decal option:

    no-decal.PNG
     
  2. glumleaf

    glumleaf

    Joined:
    Jan 30, 2016
    Posts:
    22
    Did you ever figure this out? I'm running into the same issue and this is the only thread I've found that's relevant.
     
  3. joebain

    joebain

    Joined:
    Oct 24, 2014
    Posts:
    44