Disk.cginc 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //======= Copyright (c) Stereolabs Corporation, All rights reserved. ===============
  2. #include "UnityCG.cginc"
  3. #include "../ZED_Utils.cginc"
  4. // Uniforms
  5. half4 _Tint;
  6. half _PointSize;
  7. float4x4 _Transform;
  8. StructuredBuffer<float4> _PointBuffer;
  9. // Vertex input attributes
  10. struct Attributes
  11. {
  12. uint vertexID : SV_VertexID;
  13. };
  14. // Fragment varyings
  15. struct Varyings
  16. {
  17. float4 position : SV_POSITION;
  18. half3 color : COLOR;
  19. UNITY_FOG_COORDS(0)
  20. };
  21. // Vertex phase
  22. Varyings Vertex(Attributes input)
  23. {
  24. // Retrieve vertex attributes.
  25. float4 pt = _PointBuffer[input.vertexID];
  26. float4 pos = mul(_Transform, float4(pt.xyz, 1));
  27. float4 col = PCDecodeColor(asuint(pt.w));
  28. // Set vertex output.
  29. Varyings o;
  30. o.position = UnityObjectToClipPos(pos);
  31. o.color = col;
  32. UNITY_TRANSFER_FOG(o, o.position);
  33. return o;
  34. }
  35. // Geometry phase
  36. [maxvertexcount(36)]
  37. void Geometry(point Varyings input[1], inout TriangleStream<Varyings> outStream)
  38. {
  39. float4 origin = input[0].position;
  40. float2 extent = abs(UNITY_MATRIX_P._11_22 * _PointSize);
  41. // Copy the basic information.
  42. Varyings o = input[0];
  43. // Determine the number of slices based on the radius of the
  44. // point on the screen.
  45. float radius = extent.y / origin.w * _ScreenParams.y;
  46. uint slices = min((radius + 1) / 5, 4) + 2;
  47. // Slightly enlarge quad points to compensate area reduction.
  48. if (slices == 2) extent *= 1.2;
  49. // Top vertex
  50. o.position.y = origin.y + extent.y;
  51. o.position.xzw = origin.xzw;
  52. outStream.Append(o);
  53. UNITY_LOOP for (uint i = 1; i < slices; i++)
  54. {
  55. float sn, cs;
  56. sincos(UNITY_PI / slices * i, sn, cs);
  57. // Right side vertex
  58. o.position.xy = origin.xy + extent * float2(sn, cs);
  59. outStream.Append(o);
  60. // Left side vertex
  61. o.position.x = origin.x - extent.x * sn;
  62. outStream.Append(o);
  63. }
  64. // Bottom vertex
  65. o.position.x = origin.x;
  66. o.position.y = origin.y - extent.y;
  67. outStream.Append(o);
  68. outStream.RestartStrip();
  69. }
  70. half4 Fragment(Varyings input) : SV_Target
  71. {
  72. half4 c = half4(input.color, _Tint.a);
  73. UNITY_APPLY_FOG(input.fogCoord, c);
  74. return c;
  75. }