美文网首页
Cesium 自定义Material 系列 (八)

Cesium 自定义Material 系列 (八)

作者: haibalai | 来源:发表于2022-02-18 15:08 被阅读0次

对于电弧效果 我们先定义一下他的interface, 方便使用的人知道他的调用参数

export interface PMaterialElec{

color?:any,

speed?:number

}

对于电弧我们叫 MaterialElec

```javascript

import { MaterialProperty } from "./MaterialProperty";

const defaultOption: PMaterialElec = {

color: Cesium.Color.AQUA,

speed: 1,

}

//电弧效果

export class MaterialElec extends MaterialProperty {

protected _getType(option: any): string {

return "MaterialElec"

}

constructor(option=defaultOption){

super(MaterialElec.prototype,defaultOption,option);

}

protected getSource(option: any): string {

return `uniform vec4 color;

uniform float speed;

#define pi 3.1415926535

#define PI2RAD 0.01745329252

#define TWO_PI (2. * PI)

float rands(float p){

return fract(sin(p) * 10000.0);

}

float noise(vec2 p){

float time = fract( czm_frameNumber * speed / 1000.0);

float t = time / 20000.0;

if(t > 1.0) t -= floor(t);

return rands(p.x * 14. + p.y * sin(t) * 0.5);

}

vec2 sw(vec2 p){

return vec2(floor(p.x), floor(p.y));

}

vec2 se(vec2 p){

return vec2(ceil(p.x), floor(p.y));

}

vec2 nw(vec2 p){

return vec2(floor(p.x), ceil(p.y));

}

vec2 ne(vec2 p){

return vec2(ceil(p.x), ceil(p.y));

}

float smoothNoise(vec2 p){

vec2 inter = smoothstep(0.0, 1.0, fract(p));

float s = mix(noise(sw(p)), noise(se(p)), inter.x);

float n = mix(noise(nw(p)), noise(ne(p)), inter.x);

return mix(s, n, inter.y);

}

 更多参考 https://xiaozhuanlan.com/topic/1809347256

相关文章

网友评论

      本文标题:Cesium 自定义Material 系列 (八)

      本文链接:https://www.haomeiwen.com/subject/torylrtx.html