Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 weltraumimport · Jan 31 at 04:59 PM · shaderterrainhlslsplatmapsplatmaps

Splat Map with transition texture?

Hi! I have been following catlikecoding's tutorial on this terrain editor and i need help figuring out how or where i would add a texture to the shader in order to transition from one texture to the other. At the moment it just lerps between the two textures which looks not like the style i am going for.

This is how it looks right now alt text

This is the result of that transition texture i'd like to implement where the texture blends a bit more uneven, likely achieved through an extra noise texture? (picture from endless legend) alt text

this is the code i have from catlikecoding

 Shader "Custom/TerrainShader"
 {
     Properties {
         _Color ("Color", Color) = (1,1,1,1)
         _MainTex ("Terrain Texture Array", 2DArray) = "white" {} //add our epic 2D texture arrays
         _GridTex ("Grid Texture", 2D) = "white" {}
 
         _BumpMap ("Normal Map", 2D) = "bump" {}
         _NormalScalar ("Normal Scalar", Range(0,100)) = 0.01
         _NormalWeight ("Normal Weight", Range(0,5)) = 1
 
         _Glossiness ("Smoothness", Range(0,1)) = 0.5
         _Specular ("Specular", Color) = (0.2, 0.2, 0.2)
         _BackgroundColor ("Background Color", Color) = (0,0,0) //color unexplored areas will be tinted to
         [Toggle(SHOW_MAP_DATA)] _ShowMapData ("Show Map Data", Float) = 0
     }
     SubShader {
         Tags { "RenderType"="Opaque" }
         LOD 200
         
         CGPROGRAM
         #pragma surface surf StandardSpecular fullforwardshadows vertex:vert
         #pragma target 3.5
 
         #pragma multi_compile _ GRID_ON
         #pragma multi_compile _ HEX_MAP_EDIT_MODE
         #pragma shader_feature SHOW_MAP_DATA
 
         #include "HexMetrics.cginc"
         #include "HexCellData.cginc"
 
         UNITY_DECLARE_TEX2DARRAY(_MainTex);
 
         struct Input {
             float4 color : COLOR;
             float3 worldPos;
             float3 terrain;
             float4 visibility; //float 4 instead of 3 to accomodate exploration state as well
 
             #if defined(SHOW_MAP_DATA)
                 float mapData;
             #endif
         };
 
         void vert (inout appdata_full v, out Input data) {
             UNITY_INITIALIZE_OUTPUT(Input, data);
             //data.terrain = v.texcoord2.xyz;
 
             float4 cell0 = GetCellData(v, 0);
             float4 cell1 = GetCellData(v, 1);
             float4 cell2 = GetCellData(v, 2);
 
             data.terrain.x = cell0.w; //terrain type stored in last component w
             data.terrain.y = cell1.w;
             data.terrain.z = cell2.w;
 
             data.visibility.x = cell0.x; //cell visibilty stored in first component x
             data.visibility.y = cell1.x;
             data.visibility.z = cell2.x;
             data.visibility.xyz = lerp(0.25, 1, data.visibility.xyz); //make it not fully dark
             data.visibility.w = cell0.y * v.color.x + cell1.y * v.color.y + cell2.y * v.color.z; //exploration state
 
             #if defined(SHOW_MAP_DATA)
                 data.mapData = cell0.z * v.color.x + cell1.z * v.color.y + cell2.z * v.color.z;
             #endif
 
         }
 
         half _Glossiness;
         fixed3 _Specular;
         fixed4 _Color;
         sampler2D _GridTex;
         half3 _BackgroundColor;
 
         sampler2D _BumpMap;
         fixed _NormalScalar;
         fixed _NormalWeight;
 
         //make texture coordinates, sample array, modulate sample with splat map
         float4 GetTerrainColor (Input IN, int index) {
             float3 uvw = float3(IN.worldPos.xz * (2 * TILING_SCALE), IN.terrain[index]); //coord scaled down so texture doesnt tile too often
             float4 c = UNITY_SAMPLE_TEX2DARRAY(_MainTex, uvw);
             return c * (IN.color[index] * IN.visibility[index]); //color can be treated as array as it represents 0 = r, 1 = g, etc
         }
 
         void surf (Input IN, inout SurfaceOutputStandardSpecular o) {
             fixed4 c = 
             //last coordinate is texarray index
                 GetTerrainColor(IN, 0) +
                 GetTerrainColor(IN, 1) +
                 GetTerrainColor(IN, 2);
 
             fixed4 grid = 1;
             #if defined(GRID_ON)
                 //the whole 5sqrt3, 20sqrt3 hexagon thing to calculate grid tex size correctly
                 float2 gridUV = IN.worldPos.xz; 
                 gridUV.x *= 1 / (4 * 8.66025404); //inner radius  of cells four times in order to move two cells to right
                 gridUV.y *= 1 / (2 * 15.0); //frwd dist between cell centers is 15
                 grid = tex2D (_GridTex, gridUV); //gridUV insteadof IN.worldPos.xz
             #endif
 
             float explored = IN.visibility.w;
             o.Albedo = c.rgb * grid * _Color * explored;
             #if defined(SHOW_MAP_DATA)
                 o.Albedo = IN.mapData * grid;
             #endif
             o.Specular = _Specular * explored;
             o.Smoothness = _Glossiness;
             o.Occlusion = explored; //without this the surface specular has a fresnel effect which we dont want
             o.Emission = _BackgroundColor * (1 -  explored);
             o.Alpha = c.a;
 
             //really ugly add
             o.Normal = UnpackScaleNormal(tex2D(_BumpMap, _NormalScalar * IN.worldPos.xz), _NormalWeight);
         }
         ENDCG
     }
     FallBack "Diffuse"
 }
 


hu.png (326.5 kB)
original.jpg (117.8 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

199 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

Related Questions

Can you change terrain material? 4 Answers

Unity Terrain shader on non-terrain objects 0 Answers

How to modify output color of built-in Terrain Shader with more than 4 Splat Textures? 2 Answers

Shader with "alpha" parameter no longer writes to Z-Buffer 2 Answers

Deleting terrain splatmap through scripts. 1 Answer


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