pointcloud.fs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #if defined paraboloid_point_shape
  2. #extension GL_EXT_frag_depth : enable
  3. #endif
  4. #define PI 3.141592653589793
  5. precision highp float;
  6. precision highp int;
  7. /*
  8. #if defined(usePanoMap)
  9. uniform samplerCube pano0Map; //随便设置一个samplerCube去使用都会让点云消失
  10. uniform samplerCube pano1Map;
  11. uniform float progress;
  12. uniform float easeInOutRatio;
  13. uniform vec3 pano0Position;
  14. uniform mat4 pano0Matrix;
  15. uniform vec3 pano1Position;
  16. uniform mat4 pano1Matrix;
  17. varying vec3 vWorldPosition0;
  18. varying vec3 vWorldPosition1;
  19. #endif
  20. */
  21. //------------
  22. uniform mat4 viewMatrix;
  23. uniform mat4 uViewInv;
  24. uniform mat4 uProjInv;
  25. uniform vec3 cameraPosition;
  26. uniform mat4 projectionMatrix;
  27. //uniform float uOpacity;
  28. varying float vOpacity; //add
  29. uniform float blendHardness;
  30. uniform float blendDepthSupplement;
  31. uniform float fov;
  32. uniform float uSpacing;
  33. uniform float near;
  34. uniform float far;
  35. uniform float uPCIndex;
  36. uniform float uScreenWidth;
  37. uniform float uScreenHeight;
  38. varying vec3 vColor;
  39. varying float vLogDepth;
  40. varying vec3 vViewPosition;
  41. varying float vRadius;
  42. varying float vPointSize;
  43. varying vec3 vPosition;
  44. float specularStrength = 1.0;
  45. vec2 getSamplerCoord( vec3 direction )
  46. {
  47. direction = normalize(direction);
  48. float tx=atan(direction.x,-direction.y)/(PI*2.0)+0.5;
  49. float ty=acos(direction.z)/PI;
  50. return vec2(tx,ty);
  51. }
  52. void main() {
  53. vec3 color = vColor;
  54. /*#if defined(usePanoMap) //加 经测试,即使全部写在fragment里也是无论pointsize多大都是一个点一个颜色,所以干脆写在vectex里
  55. vec4 colorFromPano0=textureCube(pano0Map,vWorldPosition0.xyz);
  56. vec4 colorFromPano1=textureCube(pano1Map,vWorldPosition1.xyz);
  57. color = mix(colorFromPano0,colorFromPano1,progress).xyz;
  58. //float easeInOutRatio = 0.0; //缓冲,渐变点云到贴图的颜色
  59. if(progress < easeInOutRatio){
  60. float easeProgress = (easeInOutRatio - progress) / easeInOutRatio;
  61. color = mix(color,vColor,easeProgress);
  62. }else if(progress > 1.0 - easeInOutRatio){
  63. float easeProgress = (progress - (1.0 - easeInOutRatio) ) / easeInOutRatio;
  64. color = mix(color,vColor,easeProgress);
  65. }
  66. #else
  67. color = vColor;
  68. #endif*/
  69. float depth = gl_FragCoord.z;
  70. #if defined(circle_point_shape) || defined(paraboloid_point_shape)
  71. float u = 2.0 * gl_PointCoord.x - 1.0;
  72. float v = 2.0 * gl_PointCoord.y - 1.0;
  73. #endif
  74. #if defined(circle_point_shape)
  75. float cc = u*u + v*v;
  76. if(cc > 1.0){
  77. discard;
  78. }
  79. #endif
  80. #if defined color_type_indices //pick point recognize
  81. gl_FragColor = vec4(color, uPCIndex / 255.0);
  82. #else
  83. gl_FragColor = vec4(color, vOpacity);
  84. #endif
  85. #if defined paraboloid_point_shape
  86. float wi = 0.0 - ( u*u + v*v);
  87. vec4 pos = vec4(vViewPosition, 1.0);
  88. pos.z += wi * vRadius;
  89. float linearDepth = -pos.z;
  90. pos = projectionMatrix * pos;
  91. pos = pos / pos.w;
  92. float expDepth = pos.z;
  93. depth = (pos.z + 1.0) / 2.0;
  94. gl_FragDepthEXT = depth;
  95. #if defined(color_type_depth)
  96. color.r = linearDepth;
  97. color.g = expDepth;
  98. #endif
  99. #if defined(use_edl)
  100. gl_FragColor.a = log2(linearDepth);
  101. #endif
  102. #else
  103. #if defined(use_edl)
  104. gl_FragColor.a = vLogDepth;
  105. #endif
  106. #endif
  107. #if defined(weighted_splats)
  108. float distance = 2.0 * length(gl_PointCoord.xy - 0.5);
  109. float weight = max(0.0, 1.0 - distance);
  110. weight = pow(weight, 1.5);
  111. gl_FragColor.a = weight;
  112. gl_FragColor.xyz = gl_FragColor.xyz * weight;
  113. #endif
  114. //gl_FragColor = vec4(0.0, 0.7, 0.0, 1.0);
  115. }