Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Koropokuruh · Jan 29, 2017 at 11:01 AM · terraincustom-shadercustom shaderterrain shadercustom terrain

Custom Terrain AddPass not working

I've read a gamasutra article (http://www.gamasutra.com/blogs/AndreyMishkinis/20130716/196339/Advanced_Terrain_Texture_Splatting.php), read about creating shaders in unity's documents, read about creating custom terrain shaders (https://alastaira.wordpress.com/2013/12/07/custom-unity-terrain-material-shaders/)... Then after making some shaders I've tried to make my own terrain shader for unity, a texture blending shader (not only splat mapping), and I've come up with a working (not perfect) shader. The problem is, the addpass shader isn't working. It's falling back to the "fallback" shader and even if I take the fallback line off, it still doesn't work, just shows like I'm painting the 4th texture in the terrain.

If anyone can help me find out what is wrong I would be really grateful. Anyone can use the shader if you like it.

The shader is here (did not apply the normals yet, trying to fix the base texture before) :

 Shader "Hidden/Raed Wulf/Terrain/BlendTexture-AddPass" {
     Properties{
         //control splat map
         [HideInInspector] _Control("Control (RGBA)", 2D) = "red" {}
 
         //textures Alpha is height
         [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" {}
 
         //normal maps
         [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)
         
     }
 
     SubShader{
         Tags{
             "SplatCount" = "4"
             "Queue" = "Geometry-99"
             "IgnoreProjector" = "True"
             "RenderType" = "Opaque"
         }
 
         CGPROGRAM
         #pragma surface surf Standard exclude_path:forward decal:add
         #pragma multi_compile_fog
         #pragma target 3.0
         // needs more than 8 texcoords
         #pragma exclude_renderers gles
         #include "UnityPBSLighting.cginc"
         
         // Access the Shaderlab properties
         uniform sampler2D _Control;
         uniform sampler2D _Splat0,_Splat1,_Splat2,_Splat3;
 
         // Surface shader input structure
         struct Input {
             float2 uv_Control : TEXCOORD0;
             float2 uv_Splat0 : TEXCOORD1;
             float2 uv_Splat1 : TEXCOORD2;
             float2 uv_Splat2 : TEXCOORD3;
             float2 uv_Splat3 : TEXCOORD4;
         };
 
         float4 blend(float4 texA, float aA, float4 texB, float aB)
         {
 
             float depth = 0.1;
             float ma = max(texA.a + aA, texB.a + aB) - depth;
 
             float b1 = max(texA.a + aA - ma, 0.0);
             float b2 = max(texB.a + aB - ma, 0.0);
 
             return (texA * b1 + texB * b2) / (b1 + b2);
 
         }
 
             
         // Surface Shader function
         void surf(Input IN, inout SurfaceOutputStandard o) {
             fixed4 tex0 = tex2D(_Splat0, IN.uv_Splat0);
             fixed4 tex1 = tex2D(_Splat1, IN.uv_Splat1);
             fixed4 tex2 = tex2D(_Splat2, IN.uv_Splat2);
             fixed4 tex3 = tex2D(_Splat3, IN.uv_Splat3);
 
             fixed4 splat_control = tex2D(_Control, IN.uv_Control);
             fixed4 col;
 
             col = blend(tex0, splat_control.r, tex1, splat_control.g);
             col = blend(col, splat_control.r + splat_control.g, tex2, splat_control.b);
             col = blend(col, splat_control.r + splat_control.g + splat_control.b, tex3, splat_control.a);
 
             o.Albedo = col.rgb;
             o.Alpha = 0.0;
                         
         }
         ENDCG
     }
 
         Fallback "Hidden/TerrainEngine/Splatmap/Diffuse-AddPass"
         //Fallback off
 }
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

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

TransparentTerrain wiki shader problems 1 Answer

Custom Terrain shader - shader property doesn't update realtime 0 Answers

Is it Possible to have Trees with Billboarded Leaves? 2 Answers

Make a simple tree 1 Answer

Different terrain look in editor and in build application. 0 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