首页 > 其他分享 >Cesium风场:GPU Powered Wind Visualization With Cesium

Cesium风场:GPU Powered Wind Visualization With Cesium

时间:2023-06-26 23:01:24浏览次数:41  
标签:Visualization rendering Powered custom var Cesium new wind

This is a guest post by Rayman Ng about his open source wind map built on top of CesiumJS.

这是Rayman Ng关于他在CesiumJS之上构建的开源风图的客座帖子。

Wind is an important element in studying the weather and climate, and it affects our daily lives in various ways. Analyzing wind is critical in many fields such as climate analysis and wind farm management. Visualizing it is crucial in being able to quickly understand the numerical wind data collected by measurement devices.

风是研究天气和气候的重要元素,它以各种方式影响着我们的日常生活。在气候分析和风电场管理等许多领域,分析风是至关重要的。将其可视化对于能够快速理解测量设备收集的数值风数据至关重要。

There are already some wind visualization applications, like Earth Nullschool and Windy, but unfortunately it seems that none of them can display the terrain, which is important for estimating the effect of wind on a specific location.

Given that I could not find an existing visualization application that met all my requirements, I decided to make my own. I found Cesium, which contains almost everything I need: 3D globe and terrain, Web Map Service layer display, and a powerful rendering engine. Basically I just needed to implement the wind visualization part.

You can run the live demo in your browser or access the source code on GitHub.

How it works

A common technique to visualize wind is to use a particle system, which places lots of particles in the wind field and updates their positions regularly with the wind force. The trails of moving particles can be used to reveal the flow pattern of the wind.

 

At first I tried the Entity API to draw the particle trails, but the performance was not satisfying when I placed more than 10,000 particles. After some investigation, I realized that the Entity API performs computation on the CPU, and the computation for more than 10,000 particles is just too much for my CPU. For better performance, I needed to move the computation to the GPU, but I still had to render the trails, which meant working with the low level Cesium Renderer module.

In Cesium, the key object of the rendering procedure is Cesium.DrawCommand: it is created in Cesium.Primitive, dispatched by Cesium.Scene, and executed in the render engine. The Cesium.DrawCommand contains everything needed in rendering, for example, Cesium.FramebufferCesium.Texture, and Cesium.ShaderProgram.

To perform custom rendering, a custom DrawCommand is required. To build a DrawCommand, first initialize its components, which are ShaderProgramTextureUniforms, and Framebuffer, piece by piece, and then combine them together to create a DrawCommand object. To inject the DrawCommand into the render engine, a custom primitive object is needed. It does not need to implement all the methods of Cesium.Primitive, only the update, isDestroyed, and the destroy method are necessary. The update method will be called before the start of each rendering.

As for the computation on GPU (also known as GPGPU), by using the technique of rendering to texture, it is similar to doing custom rendering; just use a fullscreen quad as vertex shader and write the calculation code in the fragment shader. Fortunately, Cesium already provides the rendering to texture function—all I needed to do was simply pass my fragment shader code to Cesium.ComputeCommand and use Cesium.ComputeEngine to perform the GPGPU.

The final step is to add the CustomPrimitive that contains the custom DrawCommand to the PrimitiveCollection of Scene. Below is a fully commented example of how to create a primitive and add it to the scene with a custom draw command.

class CustomPrimitive {
    constructor() {

        // most of the APIs in the renderer module are private,
        // so you may want to read the source code of Cesium to figure out how to initialize the below components,
        // or you can take my wind visualization code as a example (https://github.com/RaymanNg/3D-Wind-Field)
        var vertexArray = new Cesium.VertexArray(parameters);
        var primitiveType = Cesium.PrimitiveType.TRIANGLES // you can set it to other values
        var uniformMap = {
            uniformName: function() {
                // return the value corresponding to the name in the function
                // value can be a number, Cesium Cartesian vector, or Cesium.Texture
            }
        }
        var modelMatrix = new Cesium.Matrix4(parameters);
        var shaderProgram = new Cesium.ShaderProgram(parameters);
        var framebuffer = new Cesium.Framebuffer(parameters);
        var renderState = new Cesium.RenderState(parameters);
        var pass = Cesium.Pass.OPAQUE // if you want the command to be executed in other pass, set it to corresponding value


        this.commandToExecute = new Cesium.DrawCommand({
            owner: this,
            vertexArray: vertexArray,
            primitiveType: primitiveType,
            uniformMap: uniformMap,
            modelMatrix: modelMatrix,
            shaderProgram: shaderProgram,
            framebuffer: framebuffer,
            renderState: renderState,
            pass: pass
        });
    }

    update(frameState) {
        // if (!this.show) return;
        // if you do not want to show the CustomPrimitive, use return statement to bypass the update

        frameState.commandList.push(this.commandToExecute);
    }

    isDestroyed() {
        // return true or false to indicate whether the CustomPrimitive is destroyed
    }

    destroy() {
        // this method will be called when the CustomPrimitive is no longer used
    }
}

// To begin the custom rendering, add the CustomPrimitive to the Scene
var viewer = new Cesium.Viewer('cesiumContainer');
var customPrimitive = new CustomPrimitive();
viewer.scene.primitives.add(customPrimitive);

Conclusion

Compared with the Entity API, the Primitive API with custom draw commands provides lower level functions, making it possible to achieve better performance but requiring more coding work. By making use of the powerful render engine, wind visualization is possible with satisfying performance, and I believe that there are many other ways to use this powerful yet general render engine.

For example, it was very useful to be able to switch between different imagery layers, so you can see dynamic wind data in its global context and easily switch to comparing it with historic wind data. This is shown below using the slider.

参考1:https://www.jianshu.com/p/bff42183ce2c

参考2:https://cesium.com/blog/2019/04/29/gpu-powered-wind/

 

标签:Visualization,rendering,Powered,custom,var,Cesium,new,wind
From: https://www.cnblogs.com/2008nmj/p/17507384.html

相关文章

  • Cesium加载影像图层(ArcGIS、Bing、Mapbox、高德地图、腾讯地图、天地图等各类影像图)
    在Cesium中,加载影像图层主要通过ImageryLayer、ImageryProvider和ImageryLayerCollection三个类来实现;首先我们先来认识下这三个类一、ImageryLayer类在Cesium中,使用ImageryLayer对象来表示一个影像图层。ImageryLayer是一个包含一个或多个瓦片的图层,它可以用来控制地图影像的显......
  • Cesium将相机定位到指定的位置
    使用Cesium的viewer.camera.flyTo方法将相机定位到指定的位置,并设置相机的方向和倾斜角。viewer.camera.flyTo({//摄像机在WGS84(世界)中的最终位置坐标或从自上而下的视图中可以看到的矩形destination:Cesium.Cartesian3.fromDegrees(113,23,8000.0),//包含方向和......
  • Cesium 更改默认的鼠标操作
    //将原来鼠标中键倾斜视图修改为鼠标右键触发viewer.scene.screenSpaceCameraController.tiltEventTypes=[Cesium.CameraEventType.RIGHT_DRAG,];//将原来鼠标右键放大缩放修改为鼠标滚轮滚动viewer.scene.screenSpaceCameraController.zoomEventTypes=[Cesium.Ca......
  • Cesium结合GIS天地图 加载倾斜摄影3dtile + vue3
    实现思路将倾斜摄影OSGB数据转换为3dtile(转换方式很多,可以利用第三方工具cesiumlab)利用Cesium加载GIS地图,我这里使用的是天地图,可以加载其他地图都行加载3dtile数据到地图中展示安装插件npminstallcesium加载地图以加载天地图为例,需要先到天地图官网去申请开发者,获取......
  • CesiumJS 源码杂谈 - 时间与时钟系统
    目录1.时间的“诞生”2.时间的推进3.EntityAPI与PropertyAPI的更新动力源4.简单应用4.1.使用原生JSDate对象创建JulianDate4.2.使用时间字符串(ISO8601标准的时间字符串或UTC时间字符串)创建JulianDate4.3.为时钟设置起止时间和速率4.4.调整时钟的循环情况你......
  • Cesium:模型裁切
    关于平面裁切,官网有两个例子,3DTiles裁切和地形裁切。本文实现的功能:由两点确定一条直线,给定裁切位置,对3DTiles数据做裁切。裁切效果:要实现平面裁切,首先需要创建裁切平面1、ClippingPlanenewCesium.ClippingPlane(normal,distance)名称默认值normal平面的......
  • vue+cesium实现卫星在轨绕行动画
    1、初始化蓝星首先要实现这个功能,一定要开启时间轴timeline:true,//是否显示时间线控件this.viewer=newCesium.Viewer('cesiumContainer',{    baseLayerPicker:false, //影像切换    animation:false, //是否显示动画控件......
  • Cesium:数据处理遇到的一些问题
    CesiumLab地形切片出错原因是tif数据没有定义空间参考,首先找到“投影和变换——要素——定义投影”定义坐标系,选择与其他图层相同的坐标系。没有其他图层的坐标参考就根据个人需要定义坐标系统;可以参考文章......
  • X-Powered-By: ARR/3.0 是什么
    背景:项目调用了一个内部接口,查看接口返回的内容,看到X-Powered-By:ARR/3.0,出于好奇百查了一下ApplicationRequestRouting(ARR)isafeatureinIISthatallowsyoutosetupawebfarmandloadbalancetherequests.ARRsitswithinIISManagerandprovidesloadb......
  • Cesium:设置加载时的初始视角
    先选好位置,并调整好视角,然后按F12打开控制台分别输入:viewer.camera.positionviewer.camera.headingviewer.camera.pitchviewer.camera.roll来分别获取你选好的位置的坐标,视角等信息,然后利用viewer.camera.setView进行设置。viewer.camera.setView({//Cesium的坐......