当前位置:   article > 正文

Cesium智慧城市效果(3)道路流光_cesium 流光太多

cesium 流光太多

效果

请添加图片描述
请添加图片描述

代码

Shader的实现

注:因为找个类是继承自PolylineMaterialAppearance ,所以和PolylineMaterialAppearance 一样只能用在PolylineGeometry的外观.
在这里插入图片描述

index.ts

import * as Cesium from "cesium"
import frag from "./frag.glsl?raw"

export default class FlowLightPolylineMaterialAppearance extends Cesium.PolylineMaterialAppearance {
  constructor(option: { lightColor?: Cesium.Color } = {}) {
    const { lightColor = new Cesium.Color(.5, 1, 1) } = option

    super({
      material: new Cesium.Material({
        fabric: {
          uniforms: {
            u_time: 0,
            light_color: lightColor
          }
        }
      }),
      fragmentShaderSource: frag
    })

    const task = (t) => {
      this.material.uniforms.u_time = t * .001
      requestAnimationFrame(task)
    }
    requestAnimationFrame(task)
  }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

frag.glsl

 #ifdef VECTOR_TILE
uniform vec4 u_highlightColor;
      #endif

in vec2 v_st;

void main() {
  czm_materialInput materialInput;

  vec2 st = v_st;
  st.t = czm_readNonPerspective(st.t, gl_FragCoord.w);

  materialInput.s = st.s;
  materialInput.st = st;
  materialInput.str = vec3(st, 0.0);
  czm_material material = czm_getMaterial(materialInput);
  vec3 color = light_color_1.rgb;
  float start = 0.;
  float end = .5;
  float t = fract(u_time_0 * .4) * (1. + end) - end;
  start += t;
  end += t;
  if(st.x > start && st.x < end) {
    float d = 1. - (st.x - start) / (end - start);
    color = mix(color, color * .6, d * d);
  } else {
    color = color * .6;
  }
  material.emission = color;
  out_FragColor = vec4(material.diffuse + material.emission, light_color_1.a);
      #ifdef VECTOR_TILE
  out_FragColor *= u_highlightColor;
      #endif

  czm_writeLogDepth();
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36

使用到Primitive

  const primitive = new Cesium.Primitive({
    appearance: new FlowLightPolylineMaterialAppearance({ lightColor: new Cesium.Color(.5, 1, 1) }),
	// other code....
  })
  • 1
  • 2
  • 3
  • 4

开启场景的Bloom

viewer.scene.postProcessStages.bloom.enabled = true
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/109532
推荐阅读
相关标签
  

闽ICP备14008679号