Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Specular(rgb) map and emissive(rgb) map on my shader

Discussion in 'Scripting' started by Yearl, Mar 17, 2016.

  1. Yearl

    Yearl

    Joined:
    Jun 26, 2015
    Posts:
    33
    Hi everybody,
    I'm trying to add a specular map on my modified ToonShader based on rgb,
    so if I put a rainbow map on specular my mesh will shine multicolored !

    Here my script (specular doesnt working ...)

    Code (CSharp):
    1.     Properties {
    2.         _Color ("Main Color", Color) = (0.5,0.5,0.5,1)
    3.         _MainTex ("Base (RGB)", 2D) = "white" {}
    4.         _BumpMap ("Normalmap", 2D) = "bump" {}
    5.         _SpecMap ("Spec map (RGB)", 2D) = "black" {}
    6.         _Shininess ("Shininess", Range (0.03, 1)) = 0.078125
    7.         _Ramp ("Toon Ramp (RGB)", 2D) = "gray" {}
    8.         _CutOff("Cut off", float) = 0.0
    9.     }
    10.  
    11.     SubShader {
    12.         Tags { "RenderType"="Opaque" }
    13.        
    14.         Cull Off
    15.        
    16. CGPROGRAM
    17. #pragma surface surf ToonRamp
    18.  
    19. sampler2D _Ramp;
    20.  
    21. // custom lighting function that uses a texture ramp based
    22. // on angle between light direction and normal
    23. #pragma lighting ToonRamp exclude_path:prepass
    24. inline half4 LightingToonRamp (SurfaceOutput s, half3 lightDir, half atten)
    25. {
    26.     #ifndef USING_DIRECTIONAL_LIGHT
    27.     lightDir = normalize(lightDir);
    28.     #endif
    29.    
    30.     half d = dot (s.Normal, lightDir)*0.5 + 0.5;
    31.     half3 ramp = tex2D (_Ramp, float2(d,d)).rgb;
    32.    
    33.     half4 c;
    34.     c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2);
    35.     c.a = 0;
    36.     return c;
    37. }
    38.  
    39.  
    40. sampler2D _MainTex;
    41. sampler2D _BumpMap;
    42. sampler2D _SpecMap;
    43. float4 _Color;
    44. half _Shininess;
    45. float _CutOff;
    46.  
    47. struct Input {
    48.     float2 uv_MainTex : TEXCOORD0;
    49. };
    50.  
    51. void surf (Input IN, inout SurfaceOutput o) {
    52.     half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    53.     half4 s = tex2D(_SpecMap, IN.uv_MainTex);
    54.     if(c.a < _CutOff) discard;
    55.     o.Albedo = c.rgb;
    56.     o.Specular = s.rgb * _Shininess;
    57.     o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_MainTex));
    58.     o.Alpha = c.a;
    59. }
    60. ENDCG
    61.  
    62.     }
    63.  
    64.     Fallback "Diffuse"
    65. }
    Then after that, I would be able to put an emissive map too !

    Anyone can help ?
    Thx in advance !!
     
  2. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    You're probably better off posting it in the shader section.
     
  3. Yearl

    Yearl

    Joined:
    Jun 26, 2015
    Posts:
    33
    Wow ok, never seen Shader section before ... thx !