MeshChainSubtract.shader 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. Shader "XRLineRenderer/MeshChain - Subtractive"
  2. {
  3. Properties
  4. {
  5. _Color("Color Tint", COLOR) = (1,1,1,1)
  6. _lineSettings ("Line Thickness Settings", VECTOR) = (0, 1, .5, 1)
  7. _lineRadius("Line Radius Scale, Min, Max", VECTOR) = (1, 0, 100)
  8. // Local space or world space data
  9. [HideInInspector] _WorldData("__worlddata", Float) = 0.0
  10. // Depth effects line width
  11. [HideInInspector] _LineDepthScale("__linedepthscale", Float) = 1.0
  12. }
  13. SubShader
  14. {
  15. Tags{ "RenderType" = "Transparent" "Queue" = "Transparent" }
  16. LOD 100
  17. // We don't want the line segments and caps to draw overtop
  18. // one another as it breaks the continous segment illusion
  19. // To alpha blend with the background, we use a two-pass technique
  20. Pass
  21. {
  22. // In the first pass we 'clear' the alpha channel to 1,
  23. // so that the inner segments can mask this out
  24. Blend One One
  25. BlendOp Max
  26. Cull Off
  27. Lighting Off
  28. ZWrite Off
  29. ColorMask A
  30. Offset 0, -.1
  31. CGPROGRAM
  32. #pragma vertex vert
  33. #pragma fragment fragColor
  34. #pragma multi_compile LINE_PERSPECTIVE_WIDTH LINE_FIXED_WIDTH
  35. #pragma multi_compile LINE_MODEL_SPACE LINE_WORLD_SPACE
  36. #include "UnityCG.cginc"
  37. #include "MeshChain.cginc"
  38. ENDCG
  39. }
  40. Pass
  41. {
  42. // Next we write the line shape and fade only to the alpha channel.
  43. // This lets us punch a hole in the background that our
  44. // line color then shows through
  45. Blend One One
  46. BlendOp Min
  47. Cull Off
  48. Lighting Off
  49. ZWrite Off
  50. ColorMask A
  51. Offset 0, -.1
  52. CGPROGRAM
  53. #pragma vertex vert
  54. #pragma fragment fragAlphaMask
  55. #pragma multi_compile LINE_PERSPECTIVE_WIDTH LINE_FIXED_WIDTH
  56. #pragma multi_compile LINE_MODEL_SPACE LINE_WORLD_SPACE
  57. #include "UnityCG.cginc"
  58. #include "MeshChain.cginc"
  59. ENDCG
  60. }
  61. Pass
  62. {
  63. // In this second pass, we write our line color only as much
  64. // as the alpha value we wrote before allows through. To
  65. // prevent overlapping lines from adding too much color,
  66. // we set the alpha value to one after visiting a pixel.
  67. Blend OneMinusDstAlpha One, One One
  68. BlendOp RevSub, Max
  69. Cull Off
  70. Lighting Off
  71. ZWrite Off
  72. Offset 0, -.1
  73. CGPROGRAM
  74. #pragma vertex vert
  75. #pragma fragment fragColor
  76. #pragma multi_compile LINE_PERSPECTIVE_WIDTH LINE_FIXED_WIDTH
  77. #pragma multi_compile LINE_MODEL_SPACE LINE_WORLD_SPACE
  78. #include "UnityCG.cginc"
  79. #include "MeshChain.cginc"
  80. ENDCG
  81. }
  82. }
  83. FallBack "Diffuse"
  84. CustomEditor "Unity.XRTools.Rendering.MeshChainShaderGUI"
  85. }