ZED_PointCloud.shader 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //======= Copyright (c) Stereolabs Corporation, All rights reserved. ===============
  2. //Displays point cloud though geometry
  3. Shader "ZED/ZED PointCloud"
  4. {
  5. Properties
  6. {
  7. _MainTex ("Texture", 2D) = "white" {}
  8. _Size("Size", Range(0.1,2)) = 0.1
  9. }
  10. SubShader
  11. {
  12. Pass
  13. {
  14. Cull Off
  15. CGPROGRAM
  16. #pragma target 5.0
  17. #pragma vertex vert
  18. #pragma fragment frag
  19. #include "UnityCG.cginc"
  20. struct PS_INPUT
  21. {
  22. float4 position : SV_POSITION;
  23. float4 color : COLOR;
  24. float3 normal : NORMAL;
  25. };
  26. sampler2D _MainTex;
  27. float4 _MainTex_ST;
  28. sampler2D _XYZTex;
  29. sampler2D _ColorTex;
  30. float4 _XYZTex_TexelSize;
  31. float4x4 _Position;
  32. float _Size;
  33. PS_INPUT vert (appdata_full v, uint vertex_id : SV_VertexID, uint instance_id : SV_InstanceID)
  34. {
  35. PS_INPUT o;
  36. o.normal = v.normal;
  37. //Compute the UVS
  38. float2 uv = float2(
  39. clamp(fmod(instance_id, _XYZTex_TexelSize.z) * _XYZTex_TexelSize.x, _XYZTex_TexelSize.x, 1.0 - _XYZTex_TexelSize.x),
  40. clamp(((instance_id -fmod(instance_id, _XYZTex_TexelSize.z) * _XYZTex_TexelSize.x) / _XYZTex_TexelSize.z) * _XYZTex_TexelSize.y, _XYZTex_TexelSize.y, 1.0 - _XYZTex_TexelSize.y)
  41. );
  42. //Load the texture
  43. float4 XYZPos = float4(tex2Dlod(_XYZTex, float4(uv, 0.0, 0.0)).rgb ,1.0f);
  44. //Set the World pos
  45. o.position = mul(mul(UNITY_MATRIX_VP, _Position ), XYZPos);
  46. o.color = float4(tex2Dlod(_ColorTex, float4(uv, 0.0, 0.0)).bgr ,1.0f);
  47. return o;
  48. }
  49. struct gs_out {
  50. float4 position : SV_POSITION;
  51. float4 color : COLOR;
  52. };
  53. fixed4 frag (PS_INPUT i) : SV_Target
  54. {
  55. return i.color;
  56. }
  57. ENDCG
  58. }
  59. }
  60. }