export function updateResolutionScale(viewer) {
  //判断是否支持图像渲染像素化处理
  if (Cesium.FeatureDetection.supportsImageRenderingPixelated()) {
    viewer.resolutionScale = window.devicePixelRatio
  }
}

const PolyGradientMaterial = `uniform vec4 color;
uniform float diffusePower;
uniform float alphaPower;
uniform float globalAlpha;
uniform vec2 center;

czm_material czm_getMaterial(czm_materialInput materialInput) {
  czm_material material = czm_getDefaultMaterial(materialInput);

  float time = czm_frameNumber/600.;
  float per = fract(time);

  vec2 st = materialInput.st;
  float alpha = distance(st, center);

  material.alpha = color.a * alpha * alphaPower * globalAlpha;
  material.diffuse = color.rgb * diffusePower;
  return material;
}`

export const polygonGradient = color => {
  return new Cesium.Material({
    fabric: {
      source: PolyGradientMaterial,
      uniforms: {
        color: Cesium.Color.fromCssColorString(color),
        diffusePower: 1.8,
        alphaPower: 1.2,
        center: new Cesium.Cartesian2(0.5, 0.5),
        globalAlpha: 0x1,
      },
    },
    translucent: true,
  })
}
