x


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"

}

more ▼

asked Feb 08 '12 at 06:04 PM

n8 gravatar image

n8
192 11 14 26

This looks like it only uses the main (first) texture. Does it work when you have multiple painted terrain textures (grass, dirt... )?

To get a Ramp, I've had some luck with adding a texture to the Terrain, but just not painting with it. Unity just sends the first 4 terrain textures to FirstPass -- what FirstPass does with them is its problem.

Feb 09 '12 at 01:53 AM Owen Reynolds

Yes it is working in my scene with 9 terrain objects that each have 5 different textures applied (through the use of the terrain toolkit). I could be way off here but I thought that the all of the terrain textures were pushed down into one texture for the terrain object. at any rate, I did some more research after making this post and realized that this guy wrote a better shader for toon terrains here:

http://answers.unity3d.com/questions/22364/how-to-achieve-toon-shade-on-terrain.html

it looks like that shader uses the different splatmaps available.

I will also try the toonramp that you were referring to.

Feb 09 '12 at 07:34 PM n8

The "far" map has all your painting pushed into one texture -- very lo-res and blurry, but quick to draw. The "near" map takes all the raw textuers as input and hand-blends them, in the shader, for a hi-res virtual texture.

Feb 10 '12 at 03:19 AM Owen Reynolds
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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?

more ▼

answered Dec 20 '12 at 05:23 AM

IanElinon gravatar image

IanElinon
1 1 2

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1668
x1478
x38
x37
x5

asked: Feb 08 '12 at 06:04 PM

Seen: 3196 times

Last Updated: Dec 20 '12 at 05:23 AM