You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.3 KiB

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