Assignment for RMIT Mixed Reality in 2020
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.

103 lines
2.9 KiB

  1. Shader "VRTK/OutlineBasic"
  2. {
  3. Properties
  4. {
  5. _OutlineColor("Outline Color", Color) = (1, 0, 0, 1)
  6. _Thickness("Thickness", float) = 1
  7. }
  8. SubShader
  9. {
  10. Tags
  11. {
  12. "Queue" = "Transparent"
  13. "IgnoreProjector" = "True"
  14. "RenderType" = "Transparent"
  15. }
  16. // Fill the stencil buffer
  17. Pass
  18. {
  19. Stencil
  20. {
  21. Ref 1
  22. Comp Always
  23. Pass Replace
  24. ZFail Replace
  25. }
  26. ColorMask 0
  27. }
  28. // Draw the outline
  29. Pass
  30. {
  31. Blend SrcAlpha OneMinusSrcAlpha
  32. ZWrite Off // On (default) = Ignore lights etc. Should this be a property?
  33. Stencil
  34. {
  35. Ref 0
  36. Comp Equal
  37. }
  38. CGPROGRAM
  39. #pragma vertex vert
  40. #pragma geometry geom
  41. #pragma fragment frag
  42. #include "UnityCG.cginc"
  43. half4 _OutlineColor;
  44. float _Thickness;
  45. struct appdata
  46. {
  47. float4 vertex : POSITION;
  48. };
  49. struct v2g
  50. {
  51. float4 pos : SV_POSITION;
  52. };
  53. v2g vert(appdata IN)
  54. {
  55. v2g OUT;
  56. OUT.pos = UnityObjectToClipPos(IN.vertex);
  57. return OUT;
  58. }
  59. void geom2(v2g start, v2g end, inout TriangleStream<v2g> triStream)
  60. {
  61. float width = _Thickness / 100;
  62. float4 parallel = (end.pos - start.pos) * width;
  63. float4 perpendicular = normalize(float4(parallel.y, -parallel.x, 0, 0)) * width;
  64. float4 v1 = start.pos - parallel;
  65. float4 v2 = end.pos + parallel;
  66. v2g OUT;
  67. OUT.pos = v1 - perpendicular;
  68. triStream.Append(OUT);
  69. OUT.pos = v1 + perpendicular;
  70. triStream.Append(OUT);
  71. OUT.pos = v2 - perpendicular;
  72. triStream.Append(OUT);
  73. OUT.pos = v2 + perpendicular;
  74. triStream.Append(OUT);
  75. }
  76. [maxvertexcount(12)]
  77. void geom(triangle v2g IN[3], inout TriangleStream<v2g> triStream)
  78. {
  79. geom2(IN[0], IN[1], triStream);
  80. geom2(IN[1], IN[2], triStream);
  81. geom2(IN[2], IN[0], triStream);
  82. }
  83. half4 frag(v2g IN) : COLOR
  84. {
  85. _OutlineColor.a = 1;
  86. return _OutlineColor;
  87. }
  88. ENDCG
  89. }
  90. }
  91. FallBack "Diffuse"
  92. }