Advertisement
443eb9

Untitled

Sep 26th, 2023
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. Shader "443eb9/Wireframe"
  2. {
  3. Properties
  4. {
  5. _WireThickness ("WireThickness", Range(0, 0.1)) = 0.05
  6. [HDR] _BaseColor ("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 _BaseColor;
  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(float4, _BaseColor)
  42. UNITY_DOTS_INSTANCING_END(MaterialPropertyMetadata)
  43. #define _WireThickness UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float, _WireThickness)
  44. #define _BaseColor UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float4, _BaseColor)
  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. static 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. [unroll]
  92. for (int i = 0; i < 3; ++i)
  93. {
  94. OUT.positionHCS = IN[i].positionHCS;
  95. OUT.barycentric = barycentricColor[i];
  96. #if UNITY_ANY_INSTANCING_ENABLED
  97. UNITY_SETUP_INSTANCE_ID(IN[i]);
  98. UNITY_TRANSFER_INSTANCE_ID(IN[i], OUT);
  99. #endif
  100. triangleStream.Append(OUT);
  101. }
  102. }
  103.  
  104. float4 frag(GeomToFrag IN) : SV_Target
  105. {
  106. UNITY_SETUP_INSTANCE_ID(IN);
  107.  
  108. float3 delta = abs(ddx(IN.barycentric)) + abs(ddy(IN.barycentric));
  109. delta = IN.barycentric - delta;
  110. float closest = min(delta.x, min(delta.y, delta.z));
  111. float alpha = step(closest, _WireThickness);
  112. return float4(_BaseColor.rgb, alpha);
  113. }
  114. ENDHLSL
  115. }
  116. }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement