• 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
1
Question by fuzzywobs · Jul 14, 2010 at 05:40 PM · terraintoonshading

How to achieve Toon shade on Terrain?

How to you set the terrain to have a toon/cel shaded effect on it?

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

4 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Peter G · Jul 14, 2010 at 05:54 PM

You cannot unless you find the terrain shader in the unity contents folder, and change it to support toon shading. Your only other real option would be to use an image effect such as edge detect.

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
avatar image
2

Answer by Fayte220 · Dec 20, 2011 at 06:47 AM

This might be pretty old but I figured it out

 Shader "Hidden/TerrainEngine/Splatmap/Lightmap-FirstPass" {
 Properties {
     _Control ("Control (RGBA)", 2D) = "red" {}
     _Splat3 ("Layer 3 (A)", 2D) = "white" {}
     _Splat2 ("Layer 2 (B)", 2D) = "white" {}
     _Splat1 ("Layer 1 (G)", 2D) = "white" {}
     _Splat0 ("Layer 0 (R)", 2D) = "white" {}
     // used in fallback on old cards
     _MainTex ("BaseMap (RGB)", 2D) = "white" {}
     _OutlineColor ("Outline Color", Color) = (0,0,0,1)
     _Outline ("Outline width", Range (.002, 0.03)) = .003
     _Color ("Main Color", Color) = (1,1,1,1)
     _ToonShade ("ToonShader Cubemap(RGB)", CUBE) = "" { Texgen CubeNormal }
 }
 
     CGINCLUDE
     #include "UnityCG.cginc"
     
     struct appdata {
         float4 vertex : POSITION;
         float3 normal : NORMAL;
     };
 
     struct v2f {
         float4 pos : POSITION;
         float4 color : COLOR;
     };
     
     uniform float _Outline;
     uniform float4 _OutlineColor;
     
     v2f vert(appdata v) {
         v2f o;
         o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
 
         float3 norm   = mul ((float3x3)UNITY_MATRIX_IT_MV, v.normal);
         float2 offset = TransformViewToProjection(norm.xy);
 
         o.pos.xy += offset * o.pos.z * _Outline;
         o.color = _OutlineColor;
         return o;
     }
     ENDCG
     
 SubShader {
     Tags {
         "SplatCount" = "4"
         "Queue" = "Geometry-100"
         "RenderType" = "Opaque"
     }
         Pass {
             Name "OUTLINE"
             Tags { "LightMode" = "Always" }
             Cull Front
             ZWrite On
             ColorMask RGB
             Blend SrcAlpha OneMinusSrcAlpha
 
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             half4 frag(v2f i) :COLOR { return i.color; }
             ENDCG
         }
 CGPROGRAM
 #pragma surface surf Lambert
 struct Input {
     float2 uv_Control : TEXCOORD0;
     float2 uv_Splat0 : TEXCOORD1;
     float2 uv_Splat1 : TEXCOORD2;
     float2 uv_Splat2 : TEXCOORD3;
     float2 uv_Splat3 : TEXCOORD4;
 };
 
 sampler2D _Control;
 sampler2D _Splat0,_Splat1,_Splat2,_Splat3;
 
 void surf (Input IN, inout SurfaceOutput o) {
     fixed4 splat_control = tex2D (_Control, IN.uv_Control);
     fixed3 col;
     col  = splat_control.r * tex2D (_Splat0, IN.uv_Splat0).rgb;
     col += splat_control.g * tex2D (_Splat1, IN.uv_Splat1).rgb;
     col += splat_control.b * tex2D (_Splat2, IN.uv_Splat2).rgb;
     col += splat_control.a * tex2D (_Splat3, IN.uv_Splat3).rgb;
     o.Albedo = col;
     o.Alpha = 0.0;
 }
 ENDCG  
 }
 
         SubShader {
         Tags { "RenderType"="Opaque" }
         UsePass "Toon/Basic/BASE"
         Pass {
             Name "OUTLINE"
             Tags { "LightMode" = "Always" }
             Cull Front
             ZWrite On
             ColorMask RGB
             Blend SrcAlpha OneMinusSrcAlpha
 
             CGPROGRAM
 // Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it does not contain a surface program or both vertex and fragment programs.
 #pragma exclude_renderers gles
             #pragma vertex vert
             #pragma exclude_renderers shaderonly
             ENDCG
             SetTexture [_MainTex] { combine primary }
         }
     }
 
 
 // Fallback to Diffuse
 Fallback "Diffuse"
 }
Comment
Add comment · Show 1 · 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
avatar image ghhwer · Mar 04, 2013 at 12:07 AM 0
Share

Dude Thanks that really helped me!

avatar image
1

Answer by arvz · May 01, 2011 at 01:21 PM

This is a slightly late response but actually, you can

change the first line of your toon shader code to the same name that the default terrain shader works and unity will use your terrain shader (your toon shader) instead of the default one. i.e.: the first line of your toon terrain shader should be:

"Shader "Hidden/TerrainEngine/Splatmap/Lightmap-FirstPass"

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
avatar image
0

Answer by Fayte220 · Dec 20, 2011 at 06:47 AM

This might be a bit old but I actually figured it out.

 Shader "Hidden/TerrainEngine/Splatmap/Lightmap-FirstPass" {

Properties { _Control ("Control (RGBA)", 2D) = "red" {} _Splat3 ("Layer 3 (A)", 2D) = "white" {} _Splat2 ("Layer 2 (B)", 2D) = "white" {} _Splat1 ("Layer 1 (G)", 2D) = "white" {} _Splat0 ("Layer 0 (R)", 2D) = "white" {} // used in fallback on old cards _MainTex ("BaseMap (RGB)", 2D) = "white" {} _OutlineColor ("Outline Color", Color) = (0,0,0,1) _Outline ("Outline width", Range (.002, 0.03)) = .003 _Color ("Main Color", Color) = (1,1,1,1) _ToonShade ("ToonShader Cubemap(RGB)", CUBE) = "" { Texgen CubeNormal } }

 CGINCLUDE
 #include "UnityCG.cginc"
 
 struct appdata {
     float4 vertex : POSITION;
     float3 normal : NORMAL;
 };

 struct v2f {
     float4 pos : POSITION;
     float4 color : COLOR;
 };
 
 uniform float _Outline;
 uniform float4 _OutlineColor;
 
 v2f vert(appdata v) {
     v2f o;
     o.pos = mul(UNITY_MATRIX_MVP, v.vertex);

     float3 norm   = mul ((float3x3)UNITY_MATRIX_IT_MV, v.normal);
     float2 offset = TransformViewToProjection(norm.xy);

     o.pos.xy += offset * o.pos.z * _Outline;
     o.color = _OutlineColor;
     return o;
 }
 ENDCG
 

SubShader { Tags { "SplatCount" = "4" "Queue" = "Geometry-100" "RenderType" = "Opaque" } Pass { Name "OUTLINE" Tags { "LightMode" = "Always" } Cull Front ZWrite On ColorMask RGB Blend SrcAlpha OneMinusSrcAlpha

         CGPROGRAM
         #pragma vertex vert
         #pragma fragment frag
         half4 frag(v2f i) :COLOR { return i.color; }
         ENDCG
     }

CGPROGRAM #pragma surface surf Lambert struct Input { float2 uv_Control : TEXCOORD0; float2 uv_Splat0 : TEXCOORD1; float2 uv_Splat1 : TEXCOORD2; float2 uv_Splat2 : TEXCOORD3; float2 uv_Splat3 : TEXCOORD4; };

sampler2D _Control; sampler2D _Splat0,_Splat1,_Splat2,_Splat3;

void surf (Input IN, inout SurfaceOutput o) { fixed4 splat_control = tex2D (_Control, IN.uv_Control); fixed3 col; col = splat_control.r tex2D (_Splat0, IN.uv_Splat0).rgb; col += splat_control.g tex2D (_Splat1, IN.uv_Splat1).rgb; col += splat_control.b tex2D (_Splat2, IN.uv_Splat2).rgb; col += splat_control.a tex2D (_Splat3, IN.uv_Splat3).rgb; o.Albedo = col; o.Alpha = 0.0; } ENDCG
}

     SubShader {
     Tags { "RenderType"="Opaque" }
     UsePass "Toon/Basic/BASE"
     Pass {
         Name "OUTLINE"
         Tags { "LightMode" = "Always" }
         Cull Front
         ZWrite On
         ColorMask RGB
         Blend SrcAlpha OneMinusSrcAlpha

         CGPROGRAM

// Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it does not contain a surface program or both vertex and fragment programs. #pragma exclude_renderers gles #pragma vertex vert #pragma exclude_renderers shaderonly ENDCG SetTexture [_MainTex] { combine primary } } }

// Fallback to Diffuse Fallback "Diffuse" }

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to get toon Shader to work with terrains - Answered 1 Answer

Make a simple tree 1 Answer

Toon-Shading Terrain 1 Answer

Toony Terrain 0 Answers

Best way to create a simple cartoon terrain 3 Answers


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