Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. // Plasticky Unity3D shader
  2. // Based on built-in Toon/Lighted
  3.  
  4. Shader "Custom/ToonyPolymer" {
  5. Properties {
  6. _Color ("Main Color", Color) = (0.5,0.5,0.5,1)
  7. _MainTex ("Base (RGB)", 2D) = "white" {}
  8. _Ramp ("Toon Ramp (RGB)", 2D) = "gray" {}
  9. _Shininess ("Shininess", Range (0.1, 1)) = 0.7
  10. _Intensity ("Intensity", Range (0.1, 5.0)) = 1.0
  11.  
  12. }
  13.  
  14. SubShader {
  15. Tags { "RenderType"="Opaque" }
  16. LOD 200
  17.  
  18. CGPROGRAM
  19. #pragma surface surf ToonRamp
  20.  
  21. sampler2D _Ramp;
  22.  
  23. // custom lighting function that uses a texture ramp based
  24. // on angle between light direction and normal
  25. #pragma lighting ToonRamp exclude_path:prepass
  26. inline half4 LightingToonRamp (SurfaceOutput s, half3 lightDir, fixed3 halfDir, half atten)
  27. {
  28. #ifndef USING_DIRECTIONAL_LIGHT
  29. lightDir = normalize(lightDir);
  30. #endif
  31.  
  32. half d = dot (s.Normal, lightDir)*0.5 + 0.5;
  33. half3 ramp = tex2D (_Ramp, float2(d,d)).rgb;
  34.  
  35. fixed nh = max (0, dot (s.Normal, halfDir));
  36. fixed spec = pow (d, s.Specular*128) * s.Gloss;
  37. fixed diff = nh;
  38.  
  39. half4 c;
  40. float modifier = d;
  41.  
  42. if (modifier > 0.2)
  43. modifier += (modifier-0.1)/4.0;
  44.  
  45. c.rgb = (s.Albedo * _LightColor0.rgb * ramp + _LightColor0.rgb * spec) * (atten*2*modifier);
  46.  
  47. c.a = 0;
  48.  
  49. return c;
  50. }
  51.  
  52. sampler2D _MainTex;
  53. float4 _Color;
  54. half _Shininess;
  55. float _Intensity;
  56.  
  57. struct Input {
  58. float2 uv_MainTex : TEXCOORD0;
  59. };
  60.  
  61. void surf (Input IN, inout SurfaceOutput o) {
  62. fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
  63.  
  64. half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color * _Intensity;
  65.  
  66. o.Albedo = c.rgb;
  67. o.Alpha = tex.a;
  68. o.Gloss = _Shininess;
  69. o.Specular = _Shininess;
  70.  
  71. }
  72. ENDCG
  73.  
  74. }
  75.  
  76. Fallback "Diffuse"
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement