Terrain Transparency

I try to get the Terrain Transparency Shader to work.

http://wiki.unity3d.com/index.php/TerrainTransparency

I added the this line of code (because of some errors)
#pragma target 4.0

I assigned a Material with this shader to the Terrain, but there is no transparency.

What do I wrong?

Solved!

add following line:

#pragma surface surf Lambert Standard alpha

The Shader now looks like this:

Shader "Nature/Terrain/Diffuse"
{
    Properties
    {
        [HideInInspector] _Control ("Control (RGBA)", 2D) = "red" {}
        [HideInInspector] _Splat3 ("Layer 3 (A)", 2D) = "white" {}
        [HideInInspector] _Splat2 ("Layer 2 (B)", 2D) = "white" {}
        [HideInInspector] _Splat1 ("Layer 1 (G)", 2D) = "white" {}
        [HideInInspector] _Splat0 ("Layer 0 (R)", 2D) = "white" {}
        //Used in fallback on old cards & base map
        [HideInInspector] _MainTex ("BaseMap (RGB)", 2D) = "white" {}
        [HideInInspector] _Color ("Main Color", Color) = (1,1,1,1)
    }

    SubShader
    {
        Tags
        {
            "SplatCount" = "4"
            "Queue" = "Geometry-100"          
            "RenderType" = "Opaque"
        }
        Blend SrcAlpha OneMinusSrcAlpha
        CGPROGRAM
        #pragma surface surf Lambert Standard alpha
        #pragma target 4.0
        struct Input
        {
            float2 uv_Control : TEXCOORD0;
            float2 uv_Splat0 : TEXCOORD1;
            float2 uv_Splat1 : TEXCOORD2;
            float2 uv_Splat2 : TEXCOORD3;
            float2 uv_Splat3 : TEXCOORD4;
        };

        sampler2D _Control;
        sampler2D _Splat0,_Splat1,_Splat2,_Splat3;

        void surf (Input IN, inout SurfaceOutput o)
        {  
            fixed4 splat_control = tex2D (_Control, IN.uv_Control);
            fixed4 firstSplat = tex2D (_Splat0, IN.uv_Splat0);
            fixed3 col;
            col = splat_control.r * tex2D (_Splat0, IN.uv_Splat0).rgb;
            col += splat_control.g * tex2D (_Splat1, IN.uv_Splat1).rgb;
            col += splat_control.b * tex2D (_Splat2, IN.uv_Splat2).rgb;
            col += splat_control.a * tex2D (_Splat3, IN.uv_Splat3).rgb;
            o.Albedo = col;
            o.Alpha = 1;
            if(tex2D(_Splat0, IN.uv_Splat0).a == 0)
                o.Alpha = 1 - splat_control.r;
            else if(tex2D(_Splat1, IN.uv_Splat1).a == 0)
                o.Alpha = 1 - splat_control.g;
            else if(tex2D(_Splat2, IN.uv_Splat2).a == 0)
                o.Alpha = 1 - splat_control.b;
            else if(tex2D(_Splat3, IN.uv_Splat3).a == 0)
                o.Alpha = 1 - splat_control.a;
        }
        ENDCG
    }

    Dependency "AddPassShader" = "Hidden/TerrainEngine/Splatmap/Lightmap-AddPass"
    Dependency "BaseMapShader" = "Diffuse"

    //Fallback to Diffuse
    Fallback "Diffuse"
}

I was trying to use this shader but it came out that it makes some artifacts - I can see object through my terrain in scene but its hidden in game mode.
I am using Unity 2017, I’ve created new material with this shader and added it to a terrain, than I have added transparent texture to it but its not working properly, did I miss something ?

Hi,
well I have the same effect. Its the same if you use the “Build In Legacy Diffuse” Material settings of the terrain.
Maybe the above shader uses the legacy base shader.

Maybe look at the build in shader and play around with the dependency shader.

I cant test this because I’m a little bit busy because of our current project. I’m sorry!
If you find a solution please let me know.

Kind regards,
Spy Shifty

Hello !
it do’esn’t work at all for me…
I’ve created a shader, putted you code into,
in unity i get this : [quote]
Shader warning in ‘Nature/Terrain/Diffuse’: Unrecognized #pragma surface directive: standard at line 26
[/quote]

i’ve created a completely transparent bmp with a black alpha, and checked alpha is transparency in the inspector

And the painted “transparent” appears white

Do you have an idea of what’s wrong ?
Thanks