Cesium 场景设置~黑白、夜视和描边
生活随笔
收集整理的這篇文章主要介紹了
Cesium 场景设置~黑白、夜视和描边
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
效果圖
功能說明
場景設置主要基于PostProcessStage方法進行設置,在Cesium中創建一個蒙版式的后期處理,
主要處理是根據Shader進行渲染,有點類似于Canvas的濾鏡效果一般,對全屏進行處理。
所以場景設置實際為后期處理,全球雨雪霧天氣,PostProcessStage方法無法做到局部。
需要局部下雨下雪可以參照官網的示例
核心代碼
以下的代碼,首先創建PostProcessStage對象。通過在PostProcessStage類中uniforms屬性修改雨的傾斜度、大小和速度,就可以創建出所需要的PostProcessStage對象~雨天氣
雨天氣的場景設置
霧天氣的場景設置
var fogthicknessnum = 1.0;//可見度 var nowfragmentShader =`uniform sampler2D colorTexture;uniform sampler2D depthTexture;varying vec2 v_textureCoordinates;uniform float fognum;void main(void){vec4 origcolor=texture2D(colorTexture, v_textureCoordinates);vec4 fogcolor=vec4(0.8,0.8,0.8,0.5);float depth = czm_readDepth(depthTexture, v_textureCoordinates);vec4 depthcolor=texture2D(depthTexture, v_textureCoordinates);float f=(depthcolor.r-0.22)/fognum;if(f<0.0) f=0.0;else if(f>1.0) f=1.0;gl_FragColor = mix(origcolor,fogcolor,f);}`; var ProcessScenes = new Cesium.PostProcessStage({fragmentShader: nowfragmentShader,uniforms: {scale: 1.1,offset: function() {return new Cesium.Cartesian3(0.1, 0.2, 0.3);},fognum: () => {return fogthicknessnum;},}, }) viewer.scene.postProcessStages.add(ProcessScenes);雪天氣的場景設置
var snowSize = Cesium.defaultValue(snowopt.size, 0.02); var snowSpeed = Cesium.defaultValue(snowopt.speed, 60.0); var fragmentShader =`uniform sampler2D colorTexture;varying vec2 v_textureCoordinates;uniform float snowSpeed;uniform float snowSize;float snow(vec2 uv,float scale){float time=czm_frameNumber/snowSpeed;float w=smoothstep(1.,0.,-uv.y*(scale/10.));if(w<.1)return 0.;uv+=time/scale;uv.y+=time*2./scale;uv.x+=sin(uv.y+time*.5)/scale;uv*=scale;vec2 s=floor(uv),f=fract(uv),p;float k=3.,d;p=.5+.35*sin(11.*fract(sin((s+p+scale)*mat2(7,3,6,5))*5.))-f;d=length(p);k=min(d,k);k=smoothstep(0.,k,sin(f.x+f.y)*snowSize);return k*w;}void main(void){vec2 resolution=czm_viewport.zw;vec2 uv=(gl_FragCoord.xy*2.-resolution.xy)/min(resolution.x,resolution.y);vec3 finalColor=vec3(0);float c=0.;c+=snow(uv,30.)*.0;c+=snow(uv,20.)*.0;c+=snow(uv,15.)*.0;c+=snow(uv,10.);c+=snow(uv,8.);c+=snow(uv,6.);c+=snow(uv,5.);finalColor=(vec3(c));gl_FragColor=mix(texture2D(colorTexture,v_textureCoordinates),vec4(finalColor,1),.5);}`; var ProcessScenes = new Cesium.PostProcessStage({fragmentShader: fragmentShader,uniforms: {snowSize: () => {return snowSize;},snowSpeed: () => {return snowSpeed;},}, }) viewer.scene.postProcessStages.add(ProcessScenes);不足之處
該場景設置只能運用到全球,不能實現局部下雨
腳本下載
沒有壓縮,可以HTML文件,里面有黑白場景、夜視場景和描邊場景。
https://download.csdn.net/download/qq_35984445/86031544
包含有添加天際線場景設置腳本
https://download.csdn.net/download/qq_35984445/86744804
總結
以上是生活随笔為你收集整理的Cesium 场景设置~黑白、夜视和描边的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 哪个城市是中国的经济人口重心?
- 下一篇: 爬取斗破苍穹