Cesium基础知识-添加云特效

  1. //加载云特效
  2. function LoadClouds() {
  3.     const worldRectangle1 = viewer.scene.primitives.add(new Cesium.Primitive({
  4.         geometryInstances: new Cesium.GeometryInstance({
  5.             geometry: new Cesium.RectangleGeometry({
  6.                 rectangle: Cesium.Rectangle.fromDegrees(-180.0, -90.0, 180.0, 90.0),
  7.                 vertexFormat: Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT
  8.             })
  9.         }),
  10.         appearance: new Cesium.EllipsoidSurfaceAppearance({
  11.             material: new Cesium.Material({
  12.                 fabric: {
  13.                     type: 'Image',
  14.                     uniforms: {
  15.                         image: '../../img/clouds.png',
  16.                         radians: 0,
  17.                     },
  18.                     //shader
  19.                     source: `
  20.               #define M_PI 3.1415926535897932384626433832795
  21.   
  22.               uniform sampler2D image;
  23.               uniform float radians;
  24.               
  25.               czm_material czm_getMaterial(czm_materialInput materialInput)
  26.               {
  27.                 czm_material material = czm_getDefaultMaterial(materialInput);
  28.                 vec2 st = vec2(materialInput.st.x - 0.5, materialInput.st.y - 0.5);
  29.                 float alpha = 1.3 - st.x - 0.5;
  30.                 float current_radians = atan(st.y, st.x);
  31.                 float radius = sqrt(st.x * st.x + st.y * st.y);
  32.                 if (radius < 0.50) {
  33.                   current_radians = current_radians - radians;
  34.                   st = vec2(cos(current_radians) * radius, sin(current_radians) * radius);
  35.                   st = vec2(st.x + 0.5, st.y + 0.5);
  36.                   vec4 colorImage = texture2D(image, st);
  37.                   material.diffuse = colorImage.rgb;
  38.                   material.alpha = colorImage.a * alpha;
  39.                 } else {
  40.                   material.alpha = 0.0;
  41.                 }
  42.   
  43.                 return material;
  44.               }
  45.               `
  46.                 }
  47.             }),
  48.             aboveGround: true
  49.         }),
  50.         show: true
  51.     }))
  52.     var radians = 0
  53.     viewer.scene.postRender.addEventListener(() => {
  54.         radians += Math.PI / 50000;
  55.         worldRectangle1.appearance.material.uniforms.radians = radians;
  56.     });
  57. }
  58. LoadClouds();
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值