Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by BryanO · Mar 29, 2016 at 07:57 PM · textureterrainalphadisable

Unity 5 Transparent Terrain Shader

This shader does not appear to make the terrain transparent in Unity 5 anyone have a fix?

http://answers.unity3d.com/questions/1077032/terrain-transparency-too-many-text-interpolators.html

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by samrhein1 · Jul 02, 2016 at 02:44 PM

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"
 }
 
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Tesselliot · Jan 18, 2017 at 09:28 AM 0
Share

Hello @samrhein1 I am getting the following error when I create your shader: "Surface shader final color function 'SplatmapFinalColor not found at line 42 (on)." "Surface shader final color function 'SplatmapFinalColor' not found at line 48 (on)." Any ideas? I am using Unity 5.1.4. Thanks!

avatar image KillerNads · Feb 16, 2017 at 02:57 PM 0
Share

@samrhein1 thanks for the shader code! I added this and then changed the material of the terrain. I can paint the transparent texture now onto the terrain and see through it but only when i switch the lights off in the scene. As soon as my lighting comes on then the transparent texture becomes black. The same also happens in the camera view also.

Please can you help?

thanks

avatar image
0

Answer by Buckaroo-Banzai · Jul 22, 2016 at 09:48 AM

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. Unity Terrain Transparent Shader Issue

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


unity-shader-problem.jpg (325.2 kB)
Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image samrhein1 · Jul 22, 2016 at 08:49 PM 0
Share

Banzai - your issue is that $$anonymous$$udRockyAlbedoSpecular.bmp has an alpha channel which you can delete in Photoshop under the "channels" tab.

The above shader is very basic - I just slightly modified the Unity 5 DefaultResourcesExtra/TerrainShaders/Splats/FirstPass.shader (downloaded from https://unity3d.com/get-unity/download/archive). Its main drawback is that it doesn't receive shadows. It would be a great benefit to the community if a more experienced shader programmer could improve it!

avatar image Buckaroo-Banzai · Jul 22, 2016 at 10:27 PM 0
Share

Thanks samrhein1 so much (and bang my head against a wall). Clearly you are right and I was too dumb to see this. I think many Unity user waiting for a buildin solution in this great framework. Think a way is to check textures for an alpha channel before using as a Terrain splat image. But your modified shader is a good and very useful for the most of the 'Cut a hole inside terrain'-Problem. Thank you against and Nest regards.

Banzai

avatar image steveh2112 · Dec 23, 2016 at 03:33 AM 0
Share

can someone please help, i make a custom shader with the above code, i make a material based on a .png with only transparent, i created a new transparent material, i set the shader to the above shader, now what?

when i go to texture i can't select a material, only textures. and no way i can see to select the transparent shader.

thanks

avatar image samrhein1 steveh2112 · Dec 23, 2016 at 09:40 PM 0
Share

You can change the terrain's material under the settings tab of the terrain component. See https://docs.unity3d.com/$$anonymous$$anual/terrain-OtherSettings.html

avatar image MichiealO · Jul 31, 2018 at 09:51 PM 0
Share

I was going to say -- the shader here basically overrides the built-in shader, and changes the first pass. From what I can tell, the first pass only has access to the first 4 splat textures, so if one of these textures have an alpha channel set up, it will alpha the terrain with it. $$anonymous$$y suggestion (in addition to the removal of the alpha channel) is to put any texture that has alpha in the 5+ splat slots. (Terrains can have 12 splats that I have tested...) so just move things around.

avatar image
0

Answer by NathanJSmith · Aug 28, 2018 at 03:44 AM

shader of samrhein1 works, but when I add water (from Unity's standard asset), the water doesn't blend well with terrain. Water bug To fix this, I replaced "Queue" = "Transparent" with "Queue" = "Transparent+1" (or add +1 for Transparent queue). And the problem is solved Solve water bug 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 https://unity3d.com/get-unity/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"
 }


wateronterrainbug.png (127.2 kB)
solvewaterbug.png (124.6 kB)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

58 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Terrain texture with alpha? 1 Answer

How to stop the terrain from being blurry 0 Answers

resolution of textures with camera distance? 0 Answers

Paint terrain texture with scripting 1 Answer

Detect Different Terrain Texture? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges