/*
* @Descripttion:
* @version: 1.0
* @Author: tanzheng
* @Date: 2024-1-23 15:30:42
*/
/**
*
* 封装天气场景
* 积雪
*/
class SnowCover{
constructor(viewer){
}
//创建雪
createSnowCover(){
this.collection = viewer.scene.postProcessStages;
this._snowCover = new Cesium.PostProcessStage({
name: 'czm_snowcover',
fragmentShader: this.getSnowCover(),
// uniforms: {
// snowIntensity: 3.0, // 积雪厚度, 0~1
// }
});
this.collection.add(this._snowCover);
viewer.scene.skyAtmosphere.hueShift = -0.8;
viewer.scene.skyAtmosphere.saturationShift = -0.7;
viewer.scene.skyAtmosphere.brightnessShift = -0.33;
viewer.scene.fog.density = 0.001;
viewer.scene.fog.minimumBrightness = 0.8;
}
//获得雪的shader
getSnowCover(){
var fs= `
uniform sampler2D colorTexture;
varying vec2 v_textureCoordinates;
float snowIntensity = 2.0; // 积雪强度
void main() {
vec4 color = texture2D(colorTexture, v_textureCoordinates);
vec3 snowColor = vec3(1.0, 1.0, 1.0); // 积雪颜色
// 在片元着色器中根据亮度添加积雪纹理
float brightness = dot(color.rgb, vec3(0.2126, 0.7152, 0.0722));
vec3 snow = snowColor * snowIntensity * brightness;
color.rgb += snow;
gl_FragColor = color;
}
`
return fs;
}
//获得雪的shader
setSnowCoverValue(va){
var fs= `
uniform sampler2D colorTexture;
varying vec2 v_textureCoordinates;
void main() {
vec4 color = texture2D(colorTexture, v_textureCoordinates);
vec3 snowColor = vec3(1.0, 1.0, 1.0); // 积雪颜色
float snowIntensity = ${va}; // 积雪强度
// 在片元着色器中根据亮度添加积雪纹理
float brightness = dot(color.rgb, vec3(0.2126, 0.7152, 0.0722));
vec3 snow = snowColor * snowIntensity * brightness;
color.rgb += snow;
gl_FragColor = color;
}
`
return fs;
}
//清除雪
clearSnowCover(){
viewer.scene.postProcessStages.remove(this._snowCover);
}
//修改积雪大小
setSnowCover(value){
this.clearSnowCover();
this._snowCover = new Cesium.PostProcessStage({
name: 'czm_snowcover',
fragmentShader: `
uniform sampler2D colorTexture;
varying vec2 v_textureCoordinates;
void main() {
vec4 color = texture2D(colorTexture, v_textureCoordinates);
vec3 snowColor = vec3(1.0, 1.0, 1.0); // 积雪颜色
float snowIntensity = ${value}; // 积雪强度
// 在片元着色器中根据亮度添加积雪纹理
float brightness = dot(color.rgb, vec3(0.2126, 0.7152, 0.0722));
vec3 snow = snowColor * snowIntensity * brightness;
color.rgb += snow;
gl_FragColor = color;
}
`,
});
this.collection.add(this._snowCover);
}
}
Cesium 封装积雪效果
最新推荐文章于 2024-03-22 17:43:59 发布