Outlined.shader 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //======= Copyright (c) Stereolabs Corporation, All rights reserved. ===============
  2. // Outlines the markers of the garbage matte
  3. Shader "Custom/Green Screen/ Outlined" {
  4. Properties{
  5. _Color("Main Color", Color) = (.5,.5,.5,1)
  6. _OutlineColor("Outline Color", Color) = (0,0,0,1)
  7. _Outline("Outline width", Range(0.0, 0.03)) = .005
  8. _MainTex("Base (RGB)", 2D) = "white" { }
  9. }
  10. CGINCLUDE
  11. #pragma target 4.0
  12. #include "UnityCG.cginc"
  13. struct appdata {
  14. float4 vertex : POSITION;
  15. float3 normal : NORMAL;
  16. };
  17. struct v2f {
  18. float4 pos : POSITION;
  19. float4 color : COLOR;
  20. };
  21. uniform float _Outline;
  22. uniform float4 _OutlineColor;
  23. float4 _Color;
  24. v2f vert(appdata v) {
  25. // just make a copy of incoming vertex data but scaled according to normal direction
  26. v2f o;
  27. o.pos = UnityObjectToClipPos(v.vertex);
  28. float3 norm = mul((float3x3)UNITY_MATRIX_IT_MV, v.normal);
  29. float2 offset = TransformViewToProjection(norm.xy);
  30. o.pos.xy += offset * o.pos.z * _Outline;
  31. o.color = _OutlineColor;
  32. return o;
  33. }
  34. ENDCG
  35. SubShader{
  36. Tags{ "Queue" = "Transparent+2" }
  37. // note that a vertex shader is specified here but its using the one above
  38. Pass{
  39. Name "OUTLINE"
  40. Tags{ "LightMode" = "Always" }
  41. Cull Off
  42. ZWrite Off
  43. //ZTest Always
  44. ColorMask RGB // alpha not used
  45. Blend SrcAlpha OneMinusSrcAlpha // Normal
  46. CGPROGRAM
  47. #pragma vertex vert
  48. #pragma fragment frag
  49. #pragma target 4.0
  50. half4 frag(v2f i) :COLOR{
  51. return i.color;
  52. }
  53. ENDCG
  54. }
  55. Pass
  56. {
  57. CGPROGRAM
  58. #pragma vertex vert2
  59. #pragma fragment frag2
  60. // make fog work
  61. #pragma multi_compile_fog
  62. #include "UnityCG.cginc"
  63. sampler2D _MainTex;
  64. float4 _MainTex_ST;
  65. float4x4 _projection;
  66. v2f vert2(appdata v)
  67. {
  68. v2f o;
  69. o.pos = UnityObjectToClipPos(v.vertex);
  70. o.color = _Color;
  71. return o;
  72. }
  73. float4 frag2(v2f i) : SV_Target
  74. {
  75. return _Color;
  76. }
  77. ENDCG
  78. }
  79. }
  80. //Fallback "Diffuse"
  81. }