Hi.
I want to create holes in terrain. So i searched cross the google and finded two solutions whis are not optimal.
First solution i finded is showed at this [Video][1].
When i add more then four textures i get only black texture. (At the first photo)
So i tried find other solution.
[Here][2] i copy shader code ant get the same issue like @Buckaroo-Banzai answered. (At second photo).
I don't know how to clear textures alpha channels. Or this can be the same issue like first. Only different is how the textures are displayed . At the first solution the textures are black and at the second solutions textures are transparent.
How looks first solution:
![alt text][3] How looks second solution:
![alt text][4] [1]: https://www.youtube.com/watch?v=uxXEV91xsSc [2]: https://answers.unity.com/questions/1162779/unity-5-transparent-terrain-shader.html [3]: /storage/temp/120320-version1.jpg [4]: /storage/temp/120319-version2.jpg
Examples of codes:
At first i used this shader:
Shader "Custom/CustomDepthShader(Terrain)" { 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)", 2D) = "white" {} [HideInInspector] _Color ("Main Color", Color) = (1,1,1,1) } CGINCLUDE #pragma surface surf Lambert vertex:SplatmapVert finalcolor:SplatmapFinalColor finalprepass:SplatmapFinalPrepass finalgbuffer:SplatmapFinalGBuffer noinstancing #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 = weight; } ENDCG Category { Tags { "Queue" = "Geometry+100" "RenderType" = "Opaque" } // 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" }
Second is this code:
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" }
I give here codes if anybody have the same issue. Can help only when i successfully solved it. **Anybody know how to solve? I tried it almost two days and i do almost nothing progress.**
*Thank you all.*
When i add more then four textures i get only black texture. (At the first photo)
So i tried find other solution.
[Here][2] i copy shader code ant get the same issue like @Buckaroo-Banzai answered. (At second photo).
I don't know how to clear textures alpha channels. Or this can be the same issue like first. Only different is how the textures are displayed . At the first solution the textures are black and at the second solutions textures are transparent.
How looks first solution:
![alt text][3] How looks second solution:
![alt text][4] [1]: https://www.youtube.com/watch?v=uxXEV91xsSc [2]: https://answers.unity.com/questions/1162779/unity-5-transparent-terrain-shader.html [3]: /storage/temp/120320-version1.jpg [4]: /storage/temp/120319-version2.jpg
Examples of codes:
At first i used this shader:
Shader "Custom/CustomDepthShader(Terrain)" { 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)", 2D) = "white" {} [HideInInspector] _Color ("Main Color", Color) = (1,1,1,1) } CGINCLUDE #pragma surface surf Lambert vertex:SplatmapVert finalcolor:SplatmapFinalColor finalprepass:SplatmapFinalPrepass finalgbuffer:SplatmapFinalGBuffer noinstancing #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 = weight; } ENDCG Category { Tags { "Queue" = "Geometry+100" "RenderType" = "Opaque" } // 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" }
Second is this code:
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" }
I give here codes if anybody have the same issue. Can help only when i successfully solved it. **Anybody know how to solve? I tried it almost two days and i do almost nothing progress.**
*Thank you all.*