pointCloud.shader 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. Shader "Immersal/Point Cloud"
  2. {
  3. Properties
  4. {
  5. }
  6. SubShader
  7. {
  8. Cull Off
  9. Tags{ "RenderType" = "Opaque" }
  10. LOD 100
  11. Pass
  12. {
  13. CGPROGRAM
  14. #pragma vertex vert
  15. #pragma fragment frag
  16. #pragma target 3.0
  17. #include "UnityCG.cginc"
  18. float _PointSize;
  19. fixed _PerspectiveEnabled;
  20. fixed4 _PointColor;
  21. struct Vertex
  22. {
  23. float3 vertex : POSITION;
  24. };
  25. struct VertexOut
  26. {
  27. float psize : PSIZE;
  28. float4 center : TEXCOORD0;
  29. half size : TEXCOORD1;
  30. UNITY_FOG_COORDS(0)
  31. };
  32. VertexOut vert(Vertex vertex, out float4 outpos : SV_POSITION)
  33. {
  34. VertexOut o;
  35. outpos = UnityObjectToClipPos(vertex.vertex);
  36. o.psize = lerp(_PointSize, _PointSize / outpos.w * _ScreenParams.y, step(0.5, _PerspectiveEnabled));
  37. o.size = o.psize;
  38. o.center = ComputeScreenPos(outpos);
  39. UNITY_TRANSFER_FOG(o, o.position);
  40. return o;
  41. }
  42. fixed4 frag(VertexOut i, UNITY_VPOS_TYPE vpos : VPOS) : SV_Target
  43. {
  44. fixed4 c = _PointColor;
  45. float4 center = i.center;
  46. center.xy /= center.w;
  47. center.xy *= _ScreenParams.xy;
  48. float d = distance(vpos.xy, center.xy);
  49. if (d > i.size * 0.5) {
  50. discard;
  51. }
  52. UNITY_APPLY_FOG(input.fogCoord, c);
  53. return c;
  54. }
  55. ENDCG
  56. }
  57. }
  58. }