线样式(无同步间距调节)
This commit is contained in:
@ -7,10 +7,12 @@ function LineTexture() {
|
||||
this._definitionChanged = new Cesium.Event();
|
||||
this._image = undefined;
|
||||
this._color = undefined;
|
||||
this._imageW = undefined;
|
||||
this._speed = undefined;
|
||||
this._repeat = undefined;
|
||||
this.image = options.image || "";
|
||||
this.color = new Cesium.Color.fromCssColorString(options.color || "rgba(255,255,255,1)");
|
||||
this.imageW = options.imageW || 1;
|
||||
this.speed = options.speed != undefined ? options.speed : 1.0;
|
||||
this.repeat = options.repeat || 1.0;
|
||||
}
|
||||
|
||||
get isConstant() {
|
||||
@ -41,11 +43,17 @@ function LineTexture() {
|
||||
Cesium.Color.RED,
|
||||
result.color
|
||||
);
|
||||
result.imageW = Cesium.Property.getValueOrDefault(
|
||||
this._imageW,
|
||||
result.speed = Cesium.Property.getValueOrDefault(
|
||||
this._speed,
|
||||
time,
|
||||
1,
|
||||
result.imageW
|
||||
1.0,
|
||||
result.speed
|
||||
);
|
||||
result.repeat = Cesium.Property.getValueOrDefault(
|
||||
this._repeat,
|
||||
time,
|
||||
1.0,
|
||||
result.repeat
|
||||
);
|
||||
return result;
|
||||
}
|
||||
@ -56,7 +64,8 @@ function LineTexture() {
|
||||
(other instanceof LineTextureMaterialProperty &&
|
||||
Cesium.Property.equals(this._image, other._image) &&
|
||||
Cesium.Property.equals(this._color, other._color) &&
|
||||
Cesium.Property.equals(this._imageW, other._imageW))
|
||||
Cesium.Property.equals(this._imageW, other._imageW) &&
|
||||
Cesium.Property.equals(this._speed, other._speed))
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -64,27 +73,27 @@ function LineTexture() {
|
||||
Object.defineProperties(LineTextureMaterialProperty.prototype, {
|
||||
image: Cesium.createPropertyDescriptor("image"),
|
||||
color: Cesium.createPropertyDescriptor("color"),
|
||||
imageW: Cesium.createPropertyDescriptor("imageW"),
|
||||
speed: Cesium.createPropertyDescriptor("speed"),
|
||||
repeat: Cesium.createPropertyDescriptor("repeat"),
|
||||
});
|
||||
|
||||
Cesium.LineTextureMaterialProperty = LineTextureMaterialProperty;
|
||||
Cesium.Material.LineTextureMaterialProperty = "LineTextureMaterialProperty";
|
||||
Cesium.Material.LineTextureMaterialType = "LineTextureMaterialType";
|
||||
Cesium.Material.LineTextureMaterialSource = `
|
||||
#extension GL_OES_standard_derivatives : enable
|
||||
uniform vec4 color;
|
||||
uniform sampler2D image;
|
||||
uniform float speed;
|
||||
uniform float repeat;
|
||||
czm_material czm_getMaterial(czm_materialInput materialInput)
|
||||
{
|
||||
czm_material m = czm_getDefaultMaterial(materialInput);
|
||||
|
||||
|
||||
vec2 st = materialInput.st * vec2(494/172, 1.0); // 横向重复两次
|
||||
vec2 uv = vec2(fract(st.s + uTime*0.1), st.t);
|
||||
// uv.y = mix(uv.y, 1.0-uv.y, step(0.5, fract(uTime))); // 周期性反转Y轴
|
||||
vec4 tex = texture(image, uv);
|
||||
m.diffuse =(tex.rgb+color.rgb)/2.0;
|
||||
m.alpha = tex.a * (1.0 - fract(st.t)) * color.a; // 顶部渐隐
|
||||
|
||||
return m;
|
||||
czm_material material = czm_getDefaultMaterial(materialInput);
|
||||
vec2 st = materialInput.st;
|
||||
st.s *= repeat; // 关键:通过repeat控制纹理密度
|
||||
vec4 colorImage = texture2D(image, vec2(fract(st.s + speed*czm_frameNumber* 0.01), st.t));
|
||||
material.alpha = colorImage.a * color.a;
|
||||
material.diffuse = color.rgb;
|
||||
return material;
|
||||
}
|
||||
`;
|
||||
Cesium.Material._materialCache.addMaterial(
|
||||
@ -95,7 +104,8 @@ function LineTexture() {
|
||||
uniforms: {
|
||||
color: new Cesium.Color(1.0, 1.0, 1.0, 1.0),
|
||||
image: '',
|
||||
imageW: 1,
|
||||
repeat: 1.0,
|
||||
speed: 1.0,
|
||||
uTime: 1
|
||||
},
|
||||
source: Cesium.Material.LineTextureMaterialSource,
|
||||
|
Reference in New Issue
Block a user