Primitive.shader 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. Shader "PCX/Point Primitive"
  2. {
  3. Properties
  4. {
  5. [HDR] _Color("Tint", Color) = (1, 1, 1, 1)
  6. _PointSize("Point Size", Float) = 0.05
  7. [Toggle] _PSize("Enable Point Size", Float) = 1
  8. }
  9. SubShader
  10. {
  11. Tags { "RenderType"="Opaque" }
  12. Pass
  13. {
  14. CGPROGRAM
  15. #pragma vertex Vertex
  16. #pragma fragment Fragment
  17. #pragma multi_compile_fog
  18. #pragma multi_compile _ _PSIZE_ON
  19. #pragma multi_compile _ _COMPUTE_BUFFER
  20. #include "Common-Compute.cginc"
  21. struct Attributes
  22. {
  23. float4 position : POSITION;
  24. half4 color : COLOR;
  25. };
  26. struct Varyings
  27. {
  28. float4 position : SV_POSITION;
  29. half4 color : COLOR;
  30. #ifdef _PSIZE_ON
  31. float psize : PSIZE;
  32. #endif
  33. UNITY_FOG_COORDS(1)
  34. };
  35. half4 _Color;
  36. float4x4 _Transform;
  37. half _PointSize;
  38. #if _COMPUTE_BUFFER
  39. StructuredBuffer<float4> _PointBuffer;
  40. #endif
  41. #if _COMPUTE_BUFFER
  42. Varyings Vertex(uint vid : SV_VertexID)
  43. #else
  44. Varyings Vertex(Attributes input)
  45. #endif
  46. {
  47. #if _COMPUTE_BUFFER
  48. float4 pt = _PointBuffer[vid];
  49. float4 pos = mul(_Transform, float4(pt.xyz, 1));
  50. half4 col = UnpackColor32(asuint(pt.w));
  51. #else
  52. float4 pos = input.position;
  53. half4 col = input.color;
  54. #endif
  55. Varyings o;
  56. o.position = UnityObjectToClipPos(pos);
  57. o.color = col * _Color;
  58. #ifdef _PSIZE_ON
  59. o.psize = _PointSize / o.position.w * _ScreenParams.y;
  60. #endif
  61. UNITY_TRANSFER_FOG(o, o.position);
  62. return o;
  63. }
  64. half4 Fragment(Varyings input) : SV_Target
  65. {
  66. half4 c = input.color;
  67. UNITY_APPLY_FOG(input.fogCoord, c);
  68. return c;
  69. }
  70. ENDCG
  71. }
  72. }
  73. }