How to get toon Shader to work with terrains - Answered

I apologize in advance for this not actually being a question as much as it is me giving an answer up front. I have been browsing around this site looking for answers on how to implement a toon shader for the built in terrain objects in Unity. There have been lots of posts asking this question with various answers. I took most of those answers and then used a bit of logic and put them together to get something that I could use in my project. Here are the steps that I took:

Step1: import standard toon shaders into project ( Assets > Import Package > toon shading)
Step2: after import navigate to the folder where actual shaders are saved (project folder > Standard Assets > Toon Shading > Sources > Shaders)
Step3: Duplicate the “Toony-LightedOutline.shader” (or any other shader you would prefer) Step4: rename it something like “Toony-LightedOutline-Terrain.shader” (just to be clear what this shader is used for as it will be hidden in the editor)
Step5: open the shader in which ever text editor you like to use
Step6: change the first line text from “Toon/Lighted Outline” to “Hidden/TerrainEngine/Splatmap/Lightmap-FirstPass”

–IF you save at this point and go back into the Unity editor, you will notice that Unity has automatically applied the shader we just created/modified to the terrain object

Here is where I had the biggest problem with the toon shaded terrain. All the terrain object are very dark after applying the new shader

to fix the lighting problem
Step7: back in the editor, change line 3 from _Color (“Main Color”, Color) = (0.5,0.5,0.5,1) to: “_Color (“Main Color”, Color) = (1,1,1,1)”

Now if you go back to the Unity editor you will see that the terrain is looking much brighter (switch to the game mode to see this in action) but you will still see a problem in that at some points not all of the terrain is being shaded all of the time. And if you move around the shading area will harshly “pop” in and looks really bad. To fix that we need to make a few more adjustments:

1: click on your terrain in the Hierarchy view and then click on the “gear” icon in the inspector (button to the far right in the line)
2: move the slider for “Base Map Dist.” to where it looks best for your scene

additionally if you use the built in fog (edit > render settings) you can mask that pop even more to the point that it should not be noticeable in game-play

The one thing that I have been trying to do but have failed so far is to initialize the “_Ramp” property to use a toon ramp of choice. If anybody has any ideas I would love to hear them.

I hope this post was helpful.

*I am not a shader expert by any means so if somebody has some tips then I am all ears as to how to improve upon this shader.
**Also I do not know what the performance ramifications will be when messing with things like the shader for terrain or the “base map dist” I have tested this on my iPad2 and I get a pretty steady frame rate.

below is the shader code I am using for those who want a quick copy paste:

Shader "Hidden/TerrainEngine/Splatmap/Lightmap-FirstPass" {
Properties {
	_Color ("Main Color", Color) = (1,1,1,1)
	_OutlineColor ("Outline Color", Color) = (0,0,0,1)
	_Outline ("Outline width", Range (.002, 0.03)) = .005
	_MainTex ("Base (RGB)", 2D) = "white" {}
	_Ramp ("Toon Ramp (RGB)", 2D) = "grey" {} 

SubShader {
	Tags { "RenderType"="Opaque" }
	UsePass "Toon/Lighted/FORWARD"
	UsePass "Toon/Basic Outline/OUTLINE"

Fallback "Toon/Lighted"


This Post Have been Quite Helpful.
Now my Game looks like Borderlands 2.
Although… It is not what I Expected.
I Thought It Would just Apply the outline to the terrain.
I wish to paint textures in the terrain with the outline shader applied.
Is there any way you can help?