Search Unity

A better Toon Shader :: Help Adding AO and Emissive Maps.

Discussion in 'Shaders' started by o0_ICE_0o, Mar 23, 2016.

  1. o0_ICE_0o

    o0_ICE_0o

    Joined:
    Apr 3, 2014
    Posts:
    21
    The toon shader has a lot of potential, so iv been cutting and pasting code to make a better toon shader,
    I originally got this shader code from the this forum and i have proceeded to add double side normal support, better shadow support and refined the code a little bit( dont get thrown off by the big words, im a noob too :))
    I want to add AO and Emissive map support to this, but am not sure how to(Im noob) So guys a little help please?
    This shader can help out a lot of people if it had these functions. If you can think of other ways to make this shader better please do so, more than one developer will thank you for it. :)

    This code already supports:: Diffuse, Normal Maps, Shading Ramps, Reflection Cubemap?
    It needs:: AO map, Emissive Map

    Code (CSharp):
    1. Shader "Toon/Modified_Toon" {
    2.      Properties {
    3.          _Color ("Main Color", Color) = (1,1,1,1)
    4.          _MainTex ("Texture", 2D) = "white" {}
    5.          _BumpMap ("Normalmap", 2D) = "bump" {}
    6.          _Ramp ("Shading Ramp", 2D) = "gray" {}
    7.          _ReflectColor ("Reflection Color", Color) = (1,1,1,0.5)
    8.          _Cube ("Reflection Cubemap", Cube) = "_Skybox" { TexGen CubeReflect }      
    9.      }
    10.    
    11.      SubShader {
    12.          Tags { "RenderType" = "Opaque" }
    13.          Cull off
    14.  
    15.      CGPROGRAM
    16.          #pragma surface surf Ramp
    17.          sampler2D _Ramp;
    18.          half4 LightingRamp (SurfaceOutput s, half3 lightDir, half atten) {
    19.            
    20.              half d = (dot (s.Normal, lightDir)*0.5 + 0.5) * atten;
    21.              half3 ramp = tex2D (_Ramp, float2(d,d)).rgb;
    22.              half4 c;
    23.              c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2);
    24.              c.a = s.Alpha;
    25.              return c;
    26.          }
    27.          fixed4 _Color;
    28.          fixed4 _ReflectColor;
    29.        
    30.          struct Input {
    31.              float2 uv_MainTex;
    32.              float2 uv_BumpMap;
    33.              float3 worldRefl;
    34.              INTERNAL_DATA
    35.          };
    36.        
    37.          sampler2D _MainTex;
    38.          sampler2D _BumpMap;
    39.          samplerCUBE _Cube;
    40.    
    41.          void surf (Input IN, inout SurfaceOutput o) {
    42.              fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
    43.              fixed4 c = tex * _Color;
    44.              o.Albedo = c.rgb;
    45.    
    46.              o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
    47.            
    48.              float3 worldRefl = WorldReflectionVector (IN, o.Normal);
    49.              fixed4 reflcol = texCUBE (_Cube, worldRefl);
    50.              reflcol *= tex.a;
    51.              o.Emission = reflcol.rgb * _ReflectColor.rgb;
    52.              o.Alpha = reflcol.a * _ReflectColor.a;
    53.          }
    54.    
    55.          ENDCG
    56.    
    57.      }
    58.    
    59.      Fallback "Diffuse Bumped"
    60. }