Point.shader 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Pcx - Point cloud importer & renderer for Unity
  2. // https://github.com/keijiro/Pcx
  3. Shader "Point Cloud/Point"
  4. {
  5. Properties
  6. {
  7. _Tint("Tint", Color) = (0.5, 0.5, 0.5, 1)
  8. _PointSize("Point Size", Float) = 0.05
  9. [Toggle] _Distance("Apply Distance", Float) = 1
  10. }
  11. SubShader
  12. {
  13. Tags { "RenderType"="Opaque" }
  14. Pass
  15. {
  16. CGPROGRAM
  17. #pragma vertex Vertex
  18. #pragma fragment Fragment
  19. #pragma multi_compile_fog
  20. #pragma multi_compile _ UNITY_COLORSPACE_GAMMA
  21. #pragma multi_compile _ _DISTANCE_ON
  22. #pragma multi_compile _ _COMPUTE_BUFFER
  23. #pragma only_renderers d3d11
  24. #include "UnityCG.cginc"
  25. #include "Common.cginc"
  26. struct Attributes
  27. {
  28. float4 position : POSITION;
  29. half3 color : COLOR;
  30. };
  31. struct Varyings
  32. {
  33. float4 position : SV_Position;
  34. half3 color : COLOR;
  35. half psize : PSIZE;
  36. UNITY_FOG_COORDS(0)
  37. };
  38. half4 _Tint;
  39. float4x4 _Transform;
  40. half _PointSize;
  41. #if _COMPUTE_BUFFER
  42. StructuredBuffer<float4> _PointBuffer;
  43. #endif
  44. #if _COMPUTE_BUFFER
  45. Varyings Vertex(uint vid : SV_VertexID)
  46. #else
  47. Varyings Vertex(Attributes input)
  48. #endif
  49. {
  50. #if _COMPUTE_BUFFER
  51. float4 pt = _PointBuffer[vid];
  52. float4 pos = mul(_Transform, float4(pt.xyz, 1));
  53. half3 col = PcxDecodeColor(asuint(pt.w));
  54. #else
  55. float4 pos = input.position;
  56. half3 col = input.color;
  57. #endif
  58. #ifdef UNITY_COLORSPACE_GAMMA
  59. col *= _Tint.rgb * 2;
  60. #else
  61. col *= LinearToGammaSpace(_Tint.rgb) * 2;
  62. col = GammaToLinearSpace(col);
  63. #endif
  64. Varyings o;
  65. o.position = UnityObjectToClipPos(pos);
  66. o.color = col;
  67. #ifdef _DISTANCE_ON
  68. o.psize = _PointSize / o.position.w * _ScreenParams.y;
  69. #else
  70. o.psize = _PointSize;
  71. #endif
  72. UNITY_TRANSFER_FOG(o, o.position);
  73. return o;
  74. }
  75. half4 Fragment(Varyings input) : SV_Target
  76. {
  77. half4 c = half4(input.color, _Tint.a);
  78. UNITY_APPLY_FOG(input.fogCoord, c);
  79. return c;
  80. }
  81. ENDCG
  82. }
  83. }
  84. CustomEditor "Pcx.PointMaterialInspector"
  85. }