Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width,initial-scale=1.0">
  6. <title>dc-example</title>
  7. <script src='/libs/dc-sdk/dc.min.js'></script>
  8. <script src="../dat.gui.min.js"></script>
  9. <link href='/libs/dc-sdk/dc.min.css' type='text/css' rel='stylesheet'>
  10. <link href='../index.css' type='text/css' rel='stylesheet'>
  11. </head>
  12. <body>
  13. <div id="viewer-container" class="viewer-container" style=""></div>
  14. <script>
  15. let viewer = undefined
  16. let effect = undefined
  17. function initViewer() {
  18. viewer = new DC.Viewer('viewer-container',{
  19. orderIndependentTranslucency:false,
  20. contextOptions:{
  21. webgl:{
  22. alpha:true
  23. }
  24. }
  25. }).setOptions({
  26. showMoon: false,
  27. showSun: false,
  28. skyBox: {
  29. show:false
  30. },
  31. showAtmosphere:false,
  32. globe: {
  33. showGroundAtmosphere:false,
  34. depthTestAgainstTerrain: true // 当前示例中的Shader渲染需要开启深度检测,并在无地形时效果好些。
  35. }
  36. })
  37. let baseLayer = DC.ImageryLayerFactory.createImageryLayer(DC.ImageryType.AMAP,{
  38. style:'img',
  39. crs:'WGS84'
  40. })
  41. viewer.addBaseLayer(baseLayer)
  42. let Cesium = DC.getLib('Cesium')
  43. const fs =`
  44. uniform sampler2D colorTexture;
  45. uniform sampler2D depthTexture;
  46. uniform vec3 centerWC;
  47. uniform vec3 normalWC;
  48. uniform float radius;
  49. in vec2 v_textureCoordinates;
  50. float getDepth(){
  51. float z_window = czm_unpackDepth(texture(depthTexture, v_textureCoordinates));
  52. z_window = czm_reverseLogDepth(z_window);
  53. float n_range = czm_depthRange.near;
  54. float f_range = czm_depthRange.far;
  55. return (2.0 * z_window - n_range - f_range) / (f_range - n_range);
  56. }
  57. vec4 toEye(in vec2 uv, in float depth){
  58. vec2 xy = vec2((uv.x * 2.0 - 1.0),(uv.y * 2.0 - 1.0));
  59. vec4 posInCamera =czm_inverseProjection * vec4(xy, depth, 1.0);
  60. posInCamera = posInCamera / posInCamera.w;
  61. return posInCamera;
  62. }
  63. vec3 pointProjectOnPlane(in vec3 planeNormal, in vec3 planeOrigin, in vec3 point){
  64. vec3 v01 = point - planeOrigin;
  65. float d = dot(planeNormal, v01) ;
  66. return (point - planeNormal * d);
  67. }
  68. void main() {
  69. float depth = getDepth();
  70. vec4 color = texture(colorTexture, v_textureCoordinates);
  71. vec4 viewPos = toEye(v_textureCoordinates, depth);
  72. vec4 center = czm_view * vec4(centerWC,1);
  73. vec4 planeNormal = czm_view * vec4(normalWC,0);
  74. vec3 prjOnPlane = pointProjectOnPlane(planeNormal.xyz, center.xyz, viewPos.xyz);
  75. float dis = length(prjOnPlane.xyz - center.xyz);
  76. if(color.rgb !=vec3(0.0) && dis <= radius && depth < 1.0){
  77. out_FragColor = vec4(color.rgb, 1.0);
  78. }
  79. }`;
  80. let center = Cesium.Cartesian3.fromDegrees(120,31)
  81. let up = Cesium.Ellipsoid.WGS84.geodeticSurfaceNormal(
  82. center,
  83. new Cesium.Cartesian3()
  84. )
  85. viewer.scene.postProcessStages.add(new Cesium.PostProcessStage({
  86. fragmentShader : fs,
  87. uniforms : {
  88. centerWC: function () {
  89. return center
  90. },
  91. normalWC:function () {
  92. return up
  93. },
  94. radius : function () {
  95. return 10000
  96. },
  97. }
  98. }));
  99. addGuiController() // add controller
  100. }
  101. function addGuiController(){
  102. }
  103. DC.ready({
  104. baseUrl:'../libs/dc-sdk/resources/'
  105. }).then(initViewer)
  106. </script>
  107. </body>
  108. </html>