Cesium智慧城市特效(1)

效果

请添加图片描述

代码

Shader的实现

index.ts

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


export default class SweepShader extends Cesium.CustomShader {
    lineColor: Cesium.Cartesian3
    bgColor: Cesium.Cartesian3

    constructor(opt: { [key in string]: Cesium.Cartesian3 } = {}) {
        const {
            lineColor = new Cesium.Cartesian3(0.0, 0.7333, 1.0),
            bgColor = new Cesium.Cartesian3(0) } = opt;

        super({
            vertexShaderText: vertex,
            fragmentShaderText: frag,
            uniforms: {
                u_line_color: {
                    value: lineColor,
                    type: Cesium.UniformType.VEC3
                },
                u_bg_color: {
                    value: bgColor,
                    type: Cesium.UniformType.VEC3
                },
                u_time: {
                    value: 0, // initial value
                    type: Cesium.UniformType.FLOAT
                },

            },
            varyings: {
                v_selectedColor: Cesium.VaryingType.VEC3,
                v_uv: Cesium.VaryingType.VEC2,
            },
        })


        this.lineColor = lineColor
        this.bgColor = bgColor
    }
}

frag.glsl

void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) {
  vec3 originColor = u_bg_color;
  vec3 color = u_line_color;
  vec2 st = fract(v_uv * 5.);
  float d = smoothstep(0., .05, abs(st.y-.5));
  color += vec3(d);
  color = mix(color,originColor,d);
  // material.diffuse  = color;
  // material.emissive += vec3(1.-d)*.3;
  material.emissive += color;

}

vertex.glsl

void vertexMain(VertexInput vsInput, inout czm_modelVertexOutput vsOutput) {
	// 这里的80和200 并非固定值,根据模型的宽高调整
	// 如果模型有uv直接用uv即可
  v_uv = vec2(vsInput.attributes.positionMC.x / 80., vsInput.attributes.positionMC.y / 200.);
}

使用到Cesium3DTileset

const option = {
  lineColor = new Cesium.Cartesian3(0.0, 0.7333, 1.0), // 线的颜色
  bgColor = new Cesium.Cartesian3(0) // 背景颜色
}
tileset.customShader = new LineShader(option)

开启场景的Bloom

viewer.scene.postProcessStages.bloom .enabled = true
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值