雾特效

作者: 宿州刘德华 | 来源:发表于2020-09-21 13:39 被阅读0次

转载于 https://blog.csdn.net/luoyun620/article/details/107494145

                //计算每个渲染顶点和视点(相机)的距离
                //"//计算雾化距离(当它远离眼睛位置时,系数变小)\n" +
                var fragmentShaderSource =
                "float getDistance(sampler2D depthTexture, vec2 texCoords) \n" +
                "{ \n" +
                "    float depth = czm_unpackDepth(texture2D(depthTexture, texCoords)); \n" +
                "    if (depth == 0.0) { \n" +
                "        return czm_infinity; \n" +
                "    } \n" +
                "    vec4 eyeCoordinate = czm_windowToEyeCoordinates(gl_FragCoord.xy, depth); \n" +
                "    return -eyeCoordinate.z / eyeCoordinate.w; \n" +
                "} \n" +

                "float interpolateByDistance(vec4 nearFarScalar, float distance) \n" +
                "{ \n" +
                "    float startDistance = nearFarScalar.x;//雾化的起点距离 \n" +
                "    float startValue = nearFarScalar.y; \n" +
                "    float endDistance = nearFarScalar.z; \n" +
                "    float endValue = nearFarScalar.w; \n" +
                "    float t = clamp((distance - startDistance) / (endDistance - startDistance), 0.0, 1.0); \n" +
                "    return mix(startValue,endValue,t ); \n" +
                "} \n" +
                "vec4 alphaBlend(vec4 sourceColor, vec4 destinationColor) \n" +
                "{ \n" +
                "    return sourceColor * vec4(sourceColor.aaa, 1.0) + destinationColor * (1.0 - sourceColor.a); \n" +
                "} \n" +
                "uniform sampler2D colorTexture; \n" +
                "uniform sampler2D depthTexture; \n" +
                "uniform vec4 fogByDistance; \n" +
                "uniform vec4 fogColor; //雾的颜色\n" +
                "varying vec2 v_textureCoordinates; \n" +
                "void main(void) \n" +
                "{ \n" +
                "    float distance = getDistance(depthTexture, v_textureCoordinates); \n" +
                "    vec4 sceneColor = texture2D(colorTexture, v_textureCoordinates); \n" +
                "    float blendAmount = interpolateByDistance(fogByDistance, distance); \n" +
                "    vec4 finalFogColor = vec4(fogColor.rgb, fogColor.a * blendAmount); \n" +
                "    gl_FragColor = alphaBlend(finalFogColor, sceneColor); \n" +
                "} \n";
                function addFog () {
                    var postProcessStage = viewer.scene.postProcessStages.add(
                        new Cesium.PostProcessStage({
                            fragmentShader: fragmentShaderSource,
                            uniforms: {
                                fogByDistance: new Cesium.Cartesian4(0.0, 0.0, 15000, 1.0),
                                fogColor: new Cesium.Color(1.0, 1.0, 1.0, 1.0),
                            },
                        })
                    );
                }
                addFog();

相关文章

  • 雾特效

    转载于 https://blog.csdn.net/luoyun620/article/details/10749...

  • 树上有云。

    永兴便江,水上有雾,日落降至,水生雾起,宛如电影情节的特效,感觉回到了梦里,然而老水手似乎并不俗套,喝了一口烧酒,...

  • OpenGLES8-粒子系统

    粒子特效(Particle Efects)水,火,雾,气,三维软件开发。 一.GLSL特殊的数据类型取样器 ●取样...

  • VFX杂乱笔记

    特效有很多种类,如广告牌特效、shader特效、mesh特效以及序列帧特效。最常用的就是混合种类特效,即把多种特效...

  • 2017-07-18

    分享一下特效穴: 发热特效穴——曲池穴 咽痛特效穴——少商穴 咳嗽特效穴——列缺穴 胸痛特效穴——巨阅穴 胸闷特效...

  • 特效穴

    分享一下特效穴: 发热特效穴——曲池穴 咽痛特效穴——少商穴 咳嗽特效穴——列缺穴 胸痛特效穴——巨阅穴 胸闷特效...

  • android 特效收集

    android特效地址1android特效地址2android特效地址3android特效地址4

  • iOS 常用特效篇【长期更新】-最近更新:2017-01-13

    特效!特效!特效!重要的事情说三遍 1.tabbar 点击按钮 特效 在 @interface TabBar : ...

  • 分享一下特效穴

    发热特效穴——曲池穴 咽痛特效穴——少商穴 咳嗽特效穴——列缺穴 胸痛特效穴——巨阙穴 胸闷特效穴——督俞穴 晕厥...

  • AE常用内置特效

    1常用的内置特效 特效主要包括生音特效和视觉特效,主要应用与电视包装,电影,游戏等等 特效添加的方法 方法一;选中...

网友评论

    本文标题:雾特效

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