ToonBasicOutline.shader 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "Toon/Basic Outline" {
  3. Properties {
  4. _Color ("Main Color", Color) = (.5,.5,.5,1)
  5. _OutlineColor ("Outline Color", Color) = (0,0,0,1)
  6. _Outline ("Outline width", Range (.002, 0.03)) = .005
  7. _MainTex ("Base (RGB)", 2D) = "white" { }
  8. _ToonShade ("ToonShader Cubemap(RGB)", CUBE) = "" { }
  9. }
  10. CGINCLUDE
  11. #include "UnityCG.cginc"
  12. struct appdata {
  13. float4 vertex : POSITION;
  14. float3 normal : NORMAL;
  15. };
  16. struct v2f {
  17. float4 pos : SV_POSITION;
  18. UNITY_FOG_COORDS(0)
  19. fixed4 color : COLOR;
  20. };
  21. uniform float _Outline;
  22. uniform float4 _OutlineColor;
  23. v2f vert(appdata v) {
  24. v2f o;
  25. o.pos = UnityObjectToClipPos(v.vertex);
  26. float3 norm = normalize(mul ((float3x3)UNITY_MATRIX_IT_MV, v.normal));
  27. float2 offset = TransformViewToProjection(norm.xy);
  28. o.pos.xy += offset * o.pos.z * _Outline;
  29. o.color = _OutlineColor;
  30. UNITY_TRANSFER_FOG(o,o.pos);
  31. return o;
  32. }
  33. ENDCG
  34. SubShader {
  35. Tags { "RenderType"="Opaque" }
  36. UsePass "Toon/Basic/BASE"
  37. Pass {
  38. Name "OUTLINE"
  39. Tags { "LightMode" = "Always" }
  40. Cull Front
  41. ZWrite On
  42. ColorMask RGB
  43. Blend SrcAlpha OneMinusSrcAlpha
  44. CGPROGRAM
  45. #pragma vertex vert
  46. #pragma fragment frag
  47. #pragma multi_compile_fog
  48. fixed4 frag(v2f i) : SV_Target
  49. {
  50. UNITY_APPLY_FOG(i.fogCoord, i.color);
  51. return i.color;
  52. }
  53. ENDCG
  54. }
  55. }
  56. Fallback "Toon/Basic"
  57. }