cesium 着色器模板

class Circle {
  constructor(options) {
    this._definitionChanged = new Cesium.Event();
    this._speed = undefined;
    this._color = undefined;
    this._bgcolor = undefined;
    this._offset = undefined;
    this._repeat = undefined;
    this._thickness = undefined;
    this.speed = options.speed;
    this.color = options.color;
    this.bgcolor = options.bgcolor;
    this.offset = options.offset;
    this.repeat = options.repeat;
    this.thickness = options.thickness;
  }
  get isConstant() {
    //必备模板
    return false;
  }
  get definitionChanged() {
    //必备模板
    return this._definitionChanged;
  }
  getType() {
    //负责类型必备的给着色器
    return Cesium.Material.CircleType;
  }
  //entity用getvalue
  //privat不用getvalue
  getValue(time, result) {
    //负责取值给着色器
    if (!Cesium.defined(result)) {
      result = {};
    }
    result.color = Cesium.Property.getValueOrDefault(
      this._color,
      time,
      Cesium.Color.RED,
      result.color
    );
    result.bgcolor = Cesium.Property.getValueOrDefault(
      this._bgcolor,
      time,
      Cesium.Color.RED,
      result.bgcolor
    );
    result.offset = Cesium.Property.getValueOrDefault(
      this._offset,
      time,
      0.0,
      result.offset
    );

    result.repeat = Cesium.Property.getValueOrDefault(
      this._repeat,
      time,
      30.0,
      result.repeat
    );
    result.speed = Cesium.Property.getValueOrDefault(
      this._speed,
      time,
      10.0,
      result.speed
    );
    result.thickness = Cesium.Property.getValueOrDefault(
      this._thickness,
      time,
      0.3,
      result.thickness
    );

    return result;
  }
  equals(other) {
    return (
      this === other ||
      (other instanceof Circle &&
        Cesium.Property.equals(this._color, other._color) &&
        Cesium.Property.equals(this._speed, other._speed) &&
        Cesium.Property.equals(this._bgcolor, other._bgcolor) &&
        Cesium.Property.equals(this._thickness, other._thickness) &&
        Cesium.Property.equals(this._repeat, other._repeat) &&
        Cesium.Property.equals(this._offset, other._offset))
    );
  }
}
Object.defineProperties(Circle.prototype, {
  //添加属性或修改cirtcle对象的color和speed 参数
  color: Cesium.createPropertyDescriptor("color"),
  //一直监视color函数发生变化
  speed: Cesium.createPropertyDescriptor("speed"),
  bgcolor: Cesium.createPropertyDescriptor("bgcolor"),
  offset: Cesium.createPropertyDescriptor("offset"),
  thickness: Cesium.createPropertyDescriptor("thickness"),
  repeat: Cesium.createPropertyDescriptor("repeat")
});
Cesium.Circle = Circle; //entity 引入方式
Cesium.Material.Circle = "Circle";
Cesium.Material.CircleType = "CircleType"; //图元引入方式
Cesium.Material.Source = `
uniform vec4 color;
uniform vec4 bgColor;
uniform float repeat;
uniform float offset;
uniform float speed;
uniform float thickness;
czm_material czm_getMaterial(czm_materialInput materialInput)
{
    czm_material material = czm_getDefaultMaterial(materialInput);
    float sp = 1.0/repeat;
    vec2 st = materialInput.st;
    float dis = distance(st, vec2(0.5));
    float m = mod(dis + offset, sp);
    float a = step(sp*(1.0-thickness), m);
    float time = czm_frameNumber * speed / 1000.0;
vec2 scrPt = st * 2.0 -1.0;
vec3 col = vec3(0.0);
mat2 rot;
float theta = -time * 1.0 * 3.14 -2.2;

float cosTheta = cos(theta);
float sinTheta = sin(theta);
rot[0][0] = cosTheta;
rot[0][1] = -sinTheta;                    
rot[1][0] = sinTheta;
rot[1][1] = cosTheta;
vec2 scrPtRot = rot * scrPt;
float angle = 1.0 - (atan(scrPtRot.y,scrPtRot.x)/6.2831 + 0.5);
float falloff = length(scrPtRot);
material.alpha = pow(length(col + vec3(0.5)),0.25) ;
material.diffuse = (0.5+pow(angle,2.0)*falloff) * color.rgb;
    return material;
}
`;

Cesium.Material._materialCache.addMaterial(Cesium.Material.CircleType, {
  fabric: {
    type: Cesium.Material.CircleType,
    uniforms: {
      color: new Cesium.Color(1.0, 1.0, 0.0, 0.2),
      bgColor: new Cesium.Color(1.0, 0.0, 0.0, 0.2),
      repeat: 30.0,
      offset: 0.0,
      thickness: 0.3,
      speed: 10.0
    },
    source: Cesium.Material.Source
  },
  translucent: function(material) {
    return true;
  }
});

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小白学过的代码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值