22
2014
Custom Terrain Shader: Sharp Blending
Modified terrain shader for sharp blending.
Tutorial:
– Download terrain shader sources for your unity version: http://unity3d.com/unity/download/archive
– Copy “DefaultResourcesExtra\Nature\Terrain\TerrBumpFirstPass.shader” into your project
– Rename the “TerrBumpFirstPass.shader” into “”TerrBumpFirstPassCustom.shader”
– Edit “TerrBumpFirstPassCustom.shader”
– Find line:
Shader "Nature/Terrain/Custom Bumped Specular" {
– Replace with: *So we get this shader under custom list
Shader "Custom/Nature/Terrain/Custom Bumped Specular" {
– Find line:
fixed4 col;
– Add these lines after it: *I’m sure there would be a better way to clamp those to use max channel only, but works for now 🙂
if (splat_control.r>=splat_control.g && splat_control.r>=splat_control.b && splat_control.r>=splat_control.a) { splat_control.r=1; splat_control.g=0; splat_control.b=0; splat_control.a=0; } if (splat_control.g>=splat_control.r && splat_control.g>=splat_control.b && splat_control.g>=splat_control.a) { splat_control.r=0; splat_control.g=1; splat_control.b=0; splat_control.a=0; } if (splat_control.b>=splat_control.g && splat_control.b>=splat_control.r && splat_control.b>=splat_control.a) { splat_control.r=0; splat_control.g=0; splat_control.b=1; splat_control.a=0; } if (splat_control.a>=splat_control.g && splat_control.a>=splat_control.b && splat_control.a>=splat_control.r) { splat_control.g=0; splat_control.b=0; splat_control.r=0; splat_control.a=1; }
– Now create new material (Right click over project window, Create / Material
– Rename the new material as “CustomTerrainMaterial”
– Assign “Custom/Nature/Terrain/Custom Bumped Specular” to that material (from the material shader dropdown)
– Now assign material to the terrain: to Terrain object, Settings tab, Material slot
—————————————-
*Update for Unity5 (5.1.2)
– Download latest builtin shader (tested with 5.1.2) : http://unity3d.com/unity/download/archive
– Copy this file to your project: “\DefaultResourcesExtra\TerrainShaders\Splats\Standard-FirstPass.shader”
– Edit the copied “Standard-FirstPass.shader” and rename it to “Nature/Terrain/StandardSharp”
– Copy file “\512\CGIncludes\TerrainSplatmapCommon.cginc” to your project
– Modify file “TerrainSplatmapCommon.cginc”, find line “splat_control = tex2D(_Control, IN.tc_Control);”
– After that line, insert same custom code as above for unity4
– Create new material, assign shader Nature/Terrain/StandardSharp
– Assign this material to terrain (from terrain settings, material > custom, assign your material here)
—
Original terrain shader: (default blend)
Custom terrain shader: (sharp blending)
Related Posts
10 Comments + Add Comment
Leave a comment
Recent posts
- [GreaseMonkey] Unity Forum Fixer
- UnityHub: Make Hub application background Translucent
- Customize SpriteShapeRenderer quality (but has issues)
- Editor tool: Copy selected gameobject’s names into clipboard as rows (for Excel)
- Editor tool: Replace string in selected gameobject’s names
- UnityHub: Enable built-in Login Dialog (no more browser login/logout issues!)
- Use TikTok-TTS in Unity (with WebRequest)
- Create Scene Thumbnail Image using OnSceneSaved & OnPreviewGUI
- webgl+javascript TTS
- Using Moonsharp (LUA) + Unity Webgl
- Using 3D gameobject prefabs with Unity Tilemap + NavMesh Surface
- Custom Unity Hub Project Template Preview Image/Video (using HTML+CSS in package description)
Recent Comments
- Vector3 maths for dummies! on
- UnityHub: Make Hub application background Translucent on
- UnityHub: Make Hub application background Translucent on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- [Asset Store] Point Cloud Viewer & Tools on
- [Asset Store] Point Cloud Viewer & Tools on
- ffmpeg stream raw video into Unity Texture2D on
Hey dude, i’ve been trying to use this type of shader on UNITY 5 , but i can’t figure it out, it just dosnt work. can u update this shader into a Unity5 ready one?
Thanksss!!
^ updated post for unity5 differences
Can you update this tutorial to work with 5.6.0f3. I tried it and it didn’t work.
tested on 2007.1.0b5 still works.
It doesn’t work for me on my unity 5.6. there is still terrain blending. However it did not throw back any errors.
Hi !
This post is very usefull for my project. But I can’t manage to use it on a terrain with more than 4 textures. The others turn very very white and shiny. Am I doing something wrong ?
yeah, would need to add support for more colors..
i think it would happen at file “TerrainSplatmapCommon.cginc”, inside “void SplatmapMix(“..
What do you mean ? More splat_controls are needed ?
I don’t really get what happen but i think the shader Standard Pass only deal with the first 4 textures, the others are dealt with AddPass shader which is referenced in the one downloaded from unity website at the end :
Dependency “AddPassShader” = “Hidden/TerrainEngine/Splatmap/Standard-AddPass”
Dependency “BaseMapShader” = “Hidden/TerrainEngine/Splatmap/Standard-Base”
So it’s still the standard one.
But we now kinda have two versions of TerrainSplatmapCommon (which can make the librairy bug).
I’m not even sur it’s using the modifiyed oned for the pass shader (but it does for the firstpass and is still using the standard one if the first pass shader is standard).
I tried to upload the others standard shader and renaming them but it didn’t work. Also tried to rename TerrainSplatmapCommon.cginc but didn’t managed to so the two differents versions still exists…
new version here, doesn’t require any custom shaders:
https://unitycoder.com/blog/2017/05/20/terrain-alphamap-texture-filtermode-sharp-texture-blending/
How would you do this on Unity 2019 4.41?