x


How to achieve Toon shade on Terrain?

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

more ▼

asked Jul 14 '10 at 05:40 PM

fuzzywobs gravatar image

fuzzywobs
39 5 5 9

(comments are locked)
10|3000 characters needed characters left

4 answers: sort voted first

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.

more ▼

answered Jul 14 '10 at 05:54 PM

Peter G gravatar image

Peter G
15k 16 44 136

(comments are locked)
10|3000 characters needed characters left

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"
}
more ▼

answered Dec 20 '11 at 06:47 AM

Fayte220 gravatar image

Fayte220
16

Dude Thanks that really helped me!

Mar 04 at 12:07 AM ghhwer
(comments are locked)
10|3000 characters needed characters left

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"

more ▼

answered May 01 '11 at 01:21 PM

arvz gravatar image

arvz
46 4 4 7

(comments are locked)
10|3000 characters needed characters left
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" }
more ▼

answered Dec 20 '11 at 06:47 AM

Fayte220 gravatar image

Fayte220
16

(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:

x1463
x37

asked: Jul 14 '10 at 05:40 PM

Seen: 5044 times

Last Updated: Mar 04 at 12:07 AM