Advertisement
443eb9

Untitled

Sep 26th, 2023
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 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. uint instanceID : INSTANCEID_SEMANTIC;
  52. #endif
  53. };
  54.  
  55. struct GeomToFrag
  56. {
  57. float4 positionHCS : SV_POSITION;
  58. float3 barycentric : TEXCOORD0;
  59. #if UNITY_ANY_INSTANCING_ENABLED
  60. uint instanceID : CUSTOM_INSTANCE_ID;
  61. #endif
  62. };
  63.  
  64. struct Varyings
  65. {
  66. float4 positionHCS : SV_POSITION;
  67. #if UNITY_ANY_INSTANCING_ENABLED
  68. uint instanceID : CUSTOM_INSTANCE_ID;
  69. #endif
  70. };
  71.  
  72. float3 barycentricColor[] = {float3(1, 0, 0), float3(0, 1, 0), float3(0, 0, 1)};
  73.  
  74. Varyings vert(Attributes IN)
  75. {
  76. Varyings OUT;
  77. OUT.positionHCS = TransformObjectToHClip(IN.positionOS);
  78. #if UNITY_ANY_INSTANCING_ENABLED
  79. OUT.instanceID = IN.instanceID;
  80. #endif
  81. return OUT;
  82. }
  83.  
  84. [maxvertexcount(3)]
  85. void geom(triangle Varyings IN[3], inout TriangleStream<GeomToFrag> triangleStream)
  86. {
  87. GeomToFrag OUT;
  88. triangleStream.RestartStrip();
  89.  
  90. for (int i = 0; i < 3; ++i)
  91. {
  92. OUT.positionHCS = IN[i].positionHCS;
  93. OUT.barycentric = barycentricColor[i];
  94. UNITY_TRANSFER_INSTANCE_ID(IN, OUT);
  95. triangleStream.Append(OUT);
  96. }
  97. }
  98.  
  99. float4 frag(GeomToFrag IN) : SV_Target
  100. {
  101. UNITY_SETUP_INSTANCE_ID(IN);
  102.  
  103. float3 delta = abs(ddx(IN.barycentric)) + abs(ddy(IN.barycentric));
  104. delta = IN.barycentric - delta;
  105. float closest = min(delta.x, min(delta.y, delta.z));
  106. float alpha = step(closest, _WireThickness);
  107. return float4(_WireColor.rgb, alpha);
  108. }
  109. ENDHLSL
  110. }
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement