- Home /
Unity Terrain Details does not match neighbors
I'm generating a infinte world using unity terrains and the set neighbors function. For heightmap and alphamap it looks seamless.
The problem is with the grass (terrain detail) it does not match across seams, the wind does not match and the colors do not match (see picture)
Is this a problem with my code? Or is it just the way terrain standard shaders works? Will there be a fix for it?
Answer by Tomassacre · Aug 25, 2020 at 02:49 AM
This is because of the way Unity uses the wind property of the grass to change its color. If you go to your terrains and set the Wind Settings for Grass' Size property to 0 for all of them, you'll notice they will match. I haven't found a way to override Unity's grass shader with another that doesn't do the tint change with wind yet. If your game does not require the wind movement for the grass, then setting the above mentioned property to 0 should fix it. But if you do need grass movement, I don't have a solution yet.
Thank you for the answer! Please keep me updated if you find a better solution.
I am sure there is a better solution, but what I ended up doing was replacing a line in the TerrainEngine.cginc (a shader include file) that does that ugly tint effect. What I did was download the built-in shaders (go to https://unity3d.com/get-unity/download/archive, look for your unity version and operating system and use the drop down menu where it says Downloads). By the way, I am using Unity 2019.3.6f1. Once you have that file, copy the TerrainEngine.cginc file into a folder in your Assets (I created a folder named _Shaders). Then, find these 2 shaders that are used for details in terrains: WavingGrass WavingGrassBillboard Also copy them to the same folder where you placed the TerrainEngine.cginc.
Now, open TerrainEngine.cginc ($$anonymous$$ono, Visual Studio or any other IDE/ Text Editor) and find this line:
fixed3 waveColor = lerp (fixed3(0.5,0.5,0.5), _WavingTint.rgb, fixed3(lighting,lighting,lighting));
Just for safety, I commented it instead of removing it :) . Right after I added this line:
fixed3 waveColor = lerp (fixed3(0.5,0.5,0.5), fixed3(0.5,0.5,0.5), fixed3(lighting,lighting,lighting));
Basically, I am telling the system to don't use the WavingTint color for anything. Here is where someone with better shader knowledge could jump in and let us know how to do this in a more optimized way so that this calculation is not done, but I tried a couple ways and the grass looked bad :(
Once done, save it and go back to your project. You'll notice that Unity reimports some stuff. If nothing changes, select both shaders (WavingGrass ones) and Reimport them. This should do the trick.
Your answer
Follow this Question
Related Questions
Unity terrain grass extremely weird 0 Answers
Grass Textures of Terrain changing colors dinamically 2 Answers
Blend edges between multi terrains 0 Answers
How to mix different amplitudes and frequencies when procedurally generating terrain? (Perlin Noise) 0 Answers
How to read raw files for custom terrain generation system? 0 Answers