This shader does not appear to make the terrain transparent in Unity 5 anyone have a fix?
Try this:
Shader "Custom/TerrainTransparent" {
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" {}
[HideInInspector] _Normal3 ("Normal 3 (A)", 2D) = "bump" {}
[HideInInspector] _Normal2 ("Normal 2 (B)", 2D) = "bump" {}
[HideInInspector] _Normal1 ("Normal 1 (G)", 2D) = "bump" {}
[HideInInspector] _Normal0 ("Normal 0 (R)", 2D) = "bump" {}
// used in fallback on old cards & base map
[HideInInspector] _MainTex ("BaseMap (RGB) Trans (A)", 2D) = "white" {}
[HideInInspector] _Color ("Main Color", Color) = (1,1,1,1)
}
CGINCLUDE
#pragma surface surf Lambert alpha vertex:SplatmapVert finalcolor:SplatmapFinalColor finalprepass:SplatmapFinalPrepass finalgbuffer:SplatmapFinalGBuffer
#pragma multi_compile_fog
#include "TerrainSplatmapCommon.cginc"
void surf(Input IN, inout SurfaceOutput o)
{
half4 splat_control;
half weight;
fixed4 mixedDiffuse;
SplatmapMix(IN, splat_control, weight, mixedDiffuse, o.Normal);
o.Albedo = mixedDiffuse.rgb;
o.Alpha = mixedDiffuse.a;
}
ENDCG
Category {
Tags {
"Queue" = "Transparent"
"RenderType" = "Transparent"
}
// TODO: Seems like "#pragma target 3.0 _TERRAIN_NORMAL_MAP" can't fallback correctly on less capable devices?
// Use two sub-shaders to simulate different features for different targets and still fallback correctly.
SubShader { // for sm3.0+ targets
CGPROGRAM
#pragma target 3.0
#pragma multi_compile __ _TERRAIN_NORMAL_MAP
ENDCG
}
SubShader { // for sm2.0 targets
CGPROGRAM
ENDCG
}
}
Dependency "AddPassShader" = "Hidden/TerrainEngine/Splatmap/Diffuse-AddPass"
Dependency "BaseMapShader" = "Diffuse"
Dependency "Details0" = "Hidden/TerrainEngine/Details/Vertexlit"
Dependency "Details1" = "Hidden/TerrainEngine/Details/WavingDoublePass"
Dependency "Details2" = "Hidden/TerrainEngine/Details/BillboardWavingDoublePass"
Dependency "Tree0" = "Hidden/TerrainEngine/BillboardTree"
Fallback "Diffuse"
}
Hi Guys,
I try this shader (thx to samrhein1) and it’s the best ‘open source’ solution for real transparency on terrain at this point (Someone should be update the Wiki!).
But now “MudRockyAlbedoSpecular” from the Enviroment Asset is partial transparent too!!!
I’ve tried with & without the Normal Map, change order of terrain textures, but the same result.
Someone can give a clue, because I want more focused on the gameplay and not to fiddle with shader programming at the same time?
Main using of this shader will be to hide parts of terrain inside rooms, cellar and/or cave entrance.
Thanks in advance
Banzai
shader of samrhein1 works, but when I add water (from Unity’s standard asset), the water doesn’t blend well with terrain.
To fix this, I replaced "Queue" = "Transparent"
with "Queue" = "Transparent+1"
(or add +1 for Transparent queue).
And the problem is solved
Here is the full shader I used (like I said, I just added +1 for Transparent queue, the original author of the shader is samrhein1, the root original author is Unity: DefaultResourcesExtra/TerrainShaders/Splats/FirstPass.shader (downloaded from Download Archive))
Shader "Terrain/Transparency"
{
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" {}
[HideInInspector] _Normal3 ("Normal 3 (A)", 2D) = "bump" {}
[HideInInspector] _Normal2 ("Normal 2 (B)", 2D) = "bump" {}
[HideInInspector] _Normal1 ("Normal 1 (G)", 2D) = "bump" {}
[HideInInspector] _Normal0 ("Normal 0 (R)", 2D) = "bump" {}
// used in fallback on old cards & base map
[HideInInspector] _MainTex ("BaseMap (RGB) Trans (A)", 2D) = "white" {}
[HideInInspector] _Color ("Main Color", Color) = (1,1,1,1)
}
CGINCLUDE
#pragma surface surf Lambert alpha vertex:SplatmapVert finalcolor:SplatmapFinalColor finalprepass:SplatmapFinalPrepass finalgbuffer:SplatmapFinalGBuffer
#pragma multi_compile_fog
#include "TerrainSplatmapCommon.cginc"
void surf(Input IN, inout SurfaceOutput o)
{
half4 splat_control;
half weight;
fixed4 mixedDiffuse;
SplatmapMix(IN, splat_control, weight, mixedDiffuse, o.Normal);
o.Albedo = mixedDiffuse.rgb;
o.Alpha = mixedDiffuse.a;
}
ENDCG
Category {
Tags {
"Queue" = "Transparent+1"
"RenderType" = "Transparent"
}
// TODO: Seems like "#pragma target 3.0 _TERRAIN_NORMAL_MAP" can't fallback correctly on less capable devices?
// Use two sub-shaders to simulate different features for different targets and still fallback correctly.
SubShader { // for sm3.0+ targets
CGPROGRAM
#pragma target 3.0
#pragma multi_compile __ _TERRAIN_NORMAL_MAP
ENDCG
}
SubShader { // for sm2.0 targets
CGPROGRAM
ENDCG
}
}
Dependency "AddPassShader" = "Hidden/TerrainEngine/Splatmap/Diffuse-AddPass"
Dependency "BaseMapShader" = "Diffuse"
Dependency "Details0" = "Hidden/TerrainEngine/Details/Vertexlit"
Dependency "Details1" = "Hidden/TerrainEngine/Details/WavingDoublePass"
Dependency "Details2" = "Hidden/TerrainEngine/Details/BillboardWavingDoublePass"
Dependency "Tree0" = "Hidden/TerrainEngine/BillboardTree"
Fallback "Diffuse"
}