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
2
Question by n8 · Feb 08, 2012 at 06:04 PM · shaderterraintoontoonshadingtoony

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.

  • 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"

}

Comment
Add comment · Show 4
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
avatar image Owen-Reynolds · Feb 09, 2012 at 01:53 AM 0
Share

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.

avatar image n8 · Feb 09, 2012 at 07:34 PM 0
Share

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.

avatar image Owen-Reynolds · Feb 10, 2012 at 03:19 AM 0
Share

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.

avatar image Sylker · Feb 09, 2014 at 09:16 AM 0
Share

Great post. I am quite new to shaders and this post was very helpful, thanks. Terrain texture however becomes low res and burry. Was anyone able to fix that?

Image01

Image02

screen-shot-terrain01.jpg (47.6 kB)
screen-shot-terrain02.jpg (93.1 kB)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by IanElinon · Dec 20, 2012 at 05:23 AM

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?

Comment
Add comment · Share
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

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Use texture to determine shading? 0 Answers

How can I get this type of terrain texture? 1 Answer

How to make toon shader work with terrain place trees? 1 Answer

Terrain Shading 1 Answer

Improved Graphics for Terrain 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