Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 ZoraMikau · Aug 06, 2020 at 08:09 PM · shadertextureshader programmingshader writingtiling

Shader Tiling Texture Overlapping between X and Z Axes

Hi everyone

I have a shader (code at the bottom of this) that I'm using for a terrain. It renders a texture on the sides of the terrain (the x and z axes) and between those axes the texture tends to overlap. I want to fix the overlapping and if possible make it so both axis are lined up properly so we don't have misalignment.

I'm extremely new to shaders, so if you share anything an explanation of why it does what it does would be much appreciated!

Here's an example. You can see that on the X and Z axis that everything looks good, but it's where it meets in between that looks bad

alt text

Ideally I'd love for it to work like A Short Hike's does, like this: alt text

And the shader's code. I altered the code slightly to turn the texture on the X axis (as it was rotated there) but the link to where I got the original code is at the top:

 Shader "Custom/CliffTerrainShader"
 // obtained from https://halisavakis.com/my-take-on-shaders-cliff-terrain-shader/
 {
     Properties
     {
         _CliffTexture("Cliff texture", 2D) = "white" {}
         [Normal]_CliffNormal("Cliff normal", 2D) = "bump" {} 
         _CliffNormalStrength("Cliff normal strength", float) = 1
         _CliffSmoothness("Cliff smoothness", Range(0,1)) = 0
         _CliffMetallic("Cliff metallic", Range(0,1)) = 0
     }
     SubShader
     {
         Tags { "RenderType"="Opaque" }
         LOD 200
  
         CGPROGRAM
         // Physically based Standard lighting model, and enable shadows on all light types
         #pragma surface surf Standard fullforwardshadows
  
         // Use shader model 3.0 target, to get nicer looking lighting
         #pragma target 3.0
  
         sampler2D _CliffTexture;
         float4 _CliffTexture_ST;
         sampler2D _CliffNormal;
         float _CliffNormalStrength;
         float _CliffMetallic;
         float _CliffSmoothness;
  
         sampler2D _Control;
  
         // Textures
         sampler2D _Splat0, _Splat1, _Splat2, _Splat3;
         float4 _Splat0_ST, _Splat1_ST, _Splat2_ST, _Splat3_ST;
  
         //Normal Textures
         sampler2D _Normal0, _Normal1, _Normal2, _Normal3;
  
         //Normal scales
         float _NormalScale0, _NormalScale1, _NormalScale2, _NormalScale3;
  
         //Smoothness
         float _Smoothness0, _Smoothness1, _Smoothness2, _Smoothness3;
  
         //Metallic
         float _Metallic0, _Metallic1, _Metallic2, _Metallic3;
  
  
         struct Input
         {
             float2 uv_Control;
             float3 worldPos;
             float3 worldNormal;
             INTERNAL_DATA
         };
  
  
         // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
         // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
         // #pragma instancing_options assumeuniformscaling
         UNITY_INSTANCING_BUFFER_START(Props)
             // put more per-instance properties here
         UNITY_INSTANCING_BUFFER_END(Props)
  
         void surf (Input IN, inout SurfaceOutputStandard o)
         {
             fixed4 splatControl = tex2D(_Control, IN.uv_Control);
             fixed4 col = splatControl.r * tex2D (_Splat0, IN.uv_Control * _Splat0_ST.xy);
             col += splatControl.g * tex2D(_Splat1, IN.uv_Control * _Splat1_ST.xy);
             col += splatControl.b * tex2D (_Splat2, IN.uv_Control * _Splat2_ST.xy);
             col += splatControl.a * tex2D (_Splat3, IN.uv_Control * _Splat3_ST.xy);
              
             o.Normal = splatControl.r * UnpackNormalWithScale(tex2D(_Normal0, IN.uv_Control * _Splat0_ST.xy), _NormalScale0);
             o.Normal += splatControl.g * UnpackNormalWithScale(tex2D(_Normal1, IN.uv_Control * _Splat1_ST.xy), _NormalScale1);
             o.Normal += splatControl.b * UnpackNormalWithScale(tex2D(_Normal2, IN.uv_Control * _Splat2_ST.xy), _NormalScale2);
             o.Normal += splatControl.a * UnpackNormalWithScale(tex2D(_Normal3, IN.uv_Control * _Splat3_ST.xy), _NormalScale3);
  
             o.Smoothness = splatControl.r * _Smoothness0;
             o.Smoothness += splatControl.g * _Smoothness1;
             o.Smoothness += splatControl.b * _Smoothness2;
             o.Smoothness += splatControl.a * _Smoothness3;
  
             o.Metallic = splatControl.r * _Metallic0;
             o.Metallic += splatControl.g * _Metallic1;
             o.Metallic += splatControl.b * _Metallic2;
             o.Metallic += splatControl.a * _Metallic3;
  
             float3 vec = abs(WorldNormalVector (IN, o.Normal));
             float threshold =  smoothstep(0.5, 0.9, abs(dot(vec, float3(0, 1, 0))));
             fixed4 cliffColorXY = tex2D(_CliffTexture, IN.worldPos.xy * _CliffTexture_ST.xy);
             fixed4 cliffColorYZ = tex2D(_CliffTexture, IN.worldPos.zy * _CliffTexture_ST.xy);
             fixed4 cliffColor = vec.x * cliffColorYZ + vec.z * cliffColorXY;
  
             float3 cliffNormalXY = UnpackNormalWithScale(tex2D(_CliffNormal, IN.worldPos.xy * _CliffTexture_ST.xy), _CliffNormalStrength);
             float3 cliffNormalYZ = UnpackNormalWithScale(tex2D(_CliffNormal, IN.worldPos.yz * _CliffTexture_ST.xy), _CliffNormalStrength);
             float3 cliffNormal = vec.x * cliffNormalYZ + vec.z * cliffNormalXY;
  
             col = lerp(cliffColor, col, threshold);
             o.Normal = lerp(cliffNormal, o.Normal, threshold);
             o.Smoothness = lerp(_CliffSmoothness, o.Smoothness, threshold);
             o.Metallic = lerp(_CliffMetallic, o.Metallic, threshold);
  
             o.Albedo = col.rgb;
             o.Alpha = col.a;
         }
         ENDCG
     }
     FallBack "Diffuse"
 }


tiling.png (452.9 kB)
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

233 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Shader: Modify XY Position of Texture 0 Answers

Shader: Mask Without a Texture? 2 Answers

Trying to blend 3 textures in shader 1 Answer

How to add Emission to my custom shader? 2 Answers

Standard Surface Shader with fade too dark 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