• 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 /
  • Help Room /
avatar image
0
Question by BTCallahan · May 07, 2016 at 10:46 PM · shaderterrainshaderlabterrain shader

After upgrading to version 5.3.4f1, my terrain shader no longer works

Originally I wrote this shader because the terrain "follows" the player and I did not know of a way to access the "painting" data, so I would have the shader use the world position to determine the colors of the control texture (I use a different method to handle the displacement of the map), and use the channels of the control texture as masks for the other textures. It worked perfectly until I upgraded to the latest version. After doing so I found that my custom terrain shader was no longer working correctly. No matter which texture channel I use, I still get the same result: the shader only uses the last texture, a triplaner combination of _ExtraTex5 and _ExtraTex5h. The import settings for the control texture have were not changed.

 Shader "Custom/CombinedTerrainShader" {
     Properties {
         _GlobalTextureScale ("Global Texture Scale", Range(0.0001, 10)) = 1
         _TextureScale ("Texture Scale", Range(0.0001, 1)) = 1
         _TriplanarBlendSharpness ("Blend Sharpness", Range(0.1, 10)) = 1
         _Control ("Mixing Texture", 2D) = "white" {}
         _ExtraTex1 ("Grass", 2D) = "black" {}
         _ExtraTex2 ("Sand", 2D) = "green" {}
         _ExtraTex3 ("Light Seabed Top", 2D) = "yellow" {}
         _ExtraTex3h ("Light Seabed Side", 2D) = "yellow" {}        
         _ExtraTex4 ("Seabed Top", 2D) = "red" {}
         _ExtraTex4h ("Seabed Side", 2D) = "red" {}
         _ExtraTex5 ("Crevice Top", 2D) = "blue" {}
         _ExtraTex5h ("Crevice Side", 2D) = "blue" {}
         //_Glossiness ("Smoothness", Range(0,1)) = 0.5
         
         _MainTex ("Basemap RGB", 2D) = "white" {}
 
     }
     SubShader {
         
         //Name "Vertex Deform"
         Tags {"Queue" = "Geometry-100" "RenderType"="Opaque"}
         LOD 200
             
         CGPROGRAM
         // Physically based Standard lighting model, and enable shadows on all light types
         #pragma surface surf Lambert vertex:vert
 
         //#include "AutoLight.cginc"
         #include "UnityPBSLighting.cginc"
 
             // Use shader model 3.0 target, to get nicer looking lighting
         #pragma target 3.0
 
         sampler2D _Control;
 
         sampler2D _ExtraTex1;
         sampler2D _ExtraTex2;
         sampler2D _ExtraTex3;
         sampler2D _ExtraTex3h;
         sampler2D _ExtraTex4;
         sampler2D _ExtraTex4h;
         sampler2D _ExtraTex5;
         sampler2D _ExtraTex5h;
             
         float _TextureScale;
         float _TriplanarBlendSharpness;
 
         float _GlobalTextureScale;
 
         struct Input {
             float2 uv_Control;
             float3 worldPos;
             float3 worldNormal;
         };            
         
         void vert (inout appdata_full v) {
         
             float3 worldPos = mul(_Object2World, v.vertex).xyz * _GlobalTextureScale;
         }
 
         fixed3 mixTextures(half2 yuv, half2 xuv, half2 zuv, sampler2D sampleVert, sampler2D sampleHorz, half3 blendWeights){
             fixed3 yDiff = tex2D (sampleHorz, yuv);
             fixed3 xDiff = tex2D (sampleVert, xuv);
             fixed3 zDiff = tex2D (sampleHorz, zuv);
 
             return xDiff * blendWeights.x + yDiff * blendWeights.y + zDiff * blendWeights.z;
         }
 
         void surf (Input IN, inout SurfaceOutput o) {
             // Find our UVs for each axis based on world position of the fragment.
             half2 yUV = IN.worldPos.xz * _TextureScale;
             half2 xUV = IN.worldPos.zy * _TextureScale;
             half2 zUV = IN.worldPos.xy * _TextureScale;
             
             half2 gloYUV = IN.worldPos.xz * _GlobalTextureScale;
             // Now do texture samples from our diffuse map with each of the 3 UV set's we've just made.
 
             // Get the absolute value of the world normal.
             // Put the blend weights to the power of BlendSharpness, the higher the value, 
             // the sharper the transition between the planar maps will be.
                 
             fixed3 blendWeights = pow (abs(IN.worldNormal), _TriplanarBlendSharpness);
                 
             // Divide our blend mask by the sum of it's components, this will make x+y+z=1
                 
             blendWeights = blendWeights / (blendWeights.x + blendWeights.y + blendWeights.z);
                 
             // Finally, blend together all three samples based on the blend mask.
                 
             //o.Albedo = xDiff * blendWeights.x + yDiff * blendWeights.y + zDiff * blendWeights.z;
             
             fixed4 mixTex = tex2D (_Control, gloYUV);
                 
             fixed3 tex1 = tex2D (_ExtraTex1, yUV);
             fixed3 tex2 = tex2D (_ExtraTex2, yUV);
                 
             fixed3 tex3 = mixTextures(yUV, xUV, zUV, _ExtraTex3, _ExtraTex3h, blendWeights);
                 
             fixed3 tex4 = mixTextures(yUV, xUV, zUV, _ExtraTex4, _ExtraTex4h, blendWeights);
                 
             fixed3 tex5 = mixTextures(yUV, xUV, zUV, _ExtraTex5, _ExtraTex5h, blendWeights);
             
             float gloss = lerp(lerp(0, clamp(IN.worldPos.y, 0, 0.1) * 2.5,  mixTex.a), 0, mixTex.g);
 
             fixed3 c1 = lerp(tex1, tex2, mixTex.a);
             fixed3 c2 = lerp(c1, tex3, mixTex.g);
             fixed3 c3 = lerp(c2, tex4, mixTex.r);
 
             fixed3 c = lerp(c3, tex5, mixTex.b);
             //c = lerp(tex1, tex2, 0.5);
             //tex1 = grass, tex2 = sand, tex3 = seabed, tex4 = deep seabed, tex5 = rocks
             //fixed3 c = lerp(lerp(lerp(lerp(tex1, tex2, mixTex.a), tex3, mixTex.g), tex4, mixTex.r), tex5, mixTex.b);
             
             o.Albedo = c.rgb;
             o.Alpha = 1;
         }        
         ENDCG
     }
     
     FallBack "Diffuse"
 }
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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

74 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 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

Custom Shader Giving Unexpected token error for period ' . ' 1 Answer

Shader Help : Add emission to my shader. 2 Answers

How create a material silhouette? 0 Answers

Unity 5 Custom Terrian Shader appears blurry. 1 Answer

Unity 5 Shader ignore self occlusion 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges