Advertisement
443eb9

Untitled

Sep 26th, 2023 (edited)
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. Shader "443eb9/Wireframe"
  2. {
  3. Properties
  4. {
  5. _WireThickness ("WireThickness", Range(0, 0.1)) = 0.05
  6. [HDR] _WireColor ("WireColor", Color) = (1, 1, 1, 1)
  7. }
  8. SubShader
  9. {
  10. Tags
  11. {
  12. "RenderPipeline"="UniversalPipeline"
  13. "Queue"="Transparent"
  14. "RenderType"="Transparent"
  15. }
  16. LOD 100
  17.  
  18. Pass
  19. {
  20. ZWrite Off
  21. Cull Off
  22. Blend SrcAlpha OneMinusSrcAlpha
  23.  
  24. HLSLPROGRAM
  25. #pragma vertex vert
  26. #pragma fragment frag
  27. #pragma geometry geom
  28. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  29. #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
  30. #pragma multi_compile_instancing
  31. #pragma instancing_options renderinglayer
  32.  
  33. CBUFFER_START(UnityPerMaterial)
  34. float _WireThickness;
  35. float4 _WireColor;
  36. CBUFFER_END
  37.  
  38. #if defined(UNITY_DOTS_INSTANCING_ENABLED)
  39. UNITY_DOTS_INSTANCING_START(MaterialPropertyMetadata)
  40. UNITY_DOTS_INSTANCED_PROP(float, _WireThickness)
  41. UNITY_DOTS_INSTANCED_PROP(Color, _WireColor)
  42. UNITY_DOTS_INSTANCING_END(MaterialPropertyMetadata)
  43. #define _WireThickness UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float, _WireThickness)
  44. #define _WireColor UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(Color, _WireColor)
  45. #endif
  46.  
  47. struct Attributes
  48. {
  49. float3 positionOS : POSITION;
  50. #if UNITY_ANY_INSTANCING_ENABLED
  51. UNITY_VERTEX_INPUT_INSTANCE_ID
  52. #endif
  53. };
  54.  
  55. struct GeomToFrag
  56. {
  57. float4 positionHCS : SV_POSITION;
  58. float3 barycentric : TEXCOORD0;
  59. #if UNITY_ANY_INSTANCING_ENABLED
  60. UNITY_VERTEX_INPUT_INSTANCE_ID
  61. #endif
  62. };
  63.  
  64. struct Varyings
  65. {
  66. float4 positionHCS : SV_POSITION;
  67. #if UNITY_ANY_INSTANCING_ENABLED
  68. UNITY_VERTEX_INPUT_INSTANCE_ID
  69. #endif
  70. };
  71.  
  72. Varyings vert(Attributes IN)
  73. {
  74. Varyings OUT;
  75. OUT.positionHCS = TransformObjectToHClip(IN.positionOS);
  76. #if UNITY_ANY_INSTANCING_ENABLED
  77. UNITY_SETUP_INSTANCE_ID(IN);
  78. UNITY_TRANSFER_INSTANCE_ID(IN, OUT);
  79. #endif
  80. return OUT;
  81. }
  82.  
  83. float3 barycentricColor[] = {float3(1.0, 0.0, 0.0), float3(0.0, 1.0, 0.0), float3(0.0, 0.0, 1.0)};
  84.  
  85. [maxvertexcount(3)]
  86. void geom(triangle Varyings IN[3], inout TriangleStream<GeomToFrag> triangleStream)
  87. {
  88. GeomToFrag OUT;
  89. triangleStream.RestartStrip();
  90.  
  91. for (int i = 0; i < 3; ++i)
  92. {
  93. OUT.positionHCS = IN[i].positionHCS;
  94. OUT.barycentric = barycentricColor[i];
  95. #if UNITY_ANY_INSTANCING_ENABLED
  96. UNITY_SETUP_INSTANCE_ID(IN[i]);
  97. UNITY_TRANSFER_INSTANCE_ID(IN[i], OUT);
  98. #endif
  99. triangleStream.Append(OUT);
  100. }
  101. }
  102.  
  103. float4 frag(GeomToFrag IN) : SV_Target
  104. {
  105. UNITY_SETUP_INSTANCE_ID(IN);
  106.  
  107. float3 delta = abs(ddx(IN.barycentric)) + abs(ddy(IN.barycentric));
  108. delta = IN.barycentric - delta;
  109. float closest = min(delta.x, min(delta.y, delta.z));
  110. float alpha = step(closest, _WireThickness);
  111. return float4(_WireColor.rgb, alpha);
  112. }
  113. ENDHLSL
  114. }
  115. }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement