各位大神,这个水面效果是怎么做的呀

Cesium源码 · jerry · 于 5年前 发布 · 18885 次阅读

共收到 6 条回复
jerry#25年前 0 个赞

这是个例子,看不出如何实现

cesium_abc#35年前 0 个赞

Cesium绘制河流源代码:

var waterPrimitive = new Cesium.Primitive({
    show:false,// 默认隐藏
    allowPicking:false,
    geometryInstances : new Cesium.GeometryInstance({
        geometry : new Cesium.PolygonGeometry({
            polygonHierarchy : new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArrayHeights(waterFace)),
            //extrudedHeight: 0,//注释掉此属性可以只显示水面
            perPositionHeight : true//注释掉此属性水面就贴地了
        })
    }),
    // 可以设置内置的水面shader
    appearance : new Cesium.EllipsoidSurfaceAppearance({
        material : new Cesium.Material({
            fabric : {
                type : 'Water',
                uniforms : {
                    //baseWaterColor:new Cesium.Color(0.0, 0.0, 1.0, 0.5),
                    //blendColor: new Cesium.Color(0.0, 0.0, 1.0, 0.5),
                    //specularMap: 'gray.jpg',
                    normalMap: 'staticFile/images/waterNormals.jpg',
                    frequency: 1000.0,
                    animationSpeed: 0.01,
                    amplitude: 10.0
                }
            }
        }),
        fragmentShaderSource:'varying vec3 v_positionMC;\nvarying vec3 v_positionEC;\nvarying vec2 v_st;\nvoid main()\n{\nczm_materialInput materialInput;\nvec3 normalEC = normalize(czm_normal3D * czm_geodeticSurfaceNormal(v_positionMC, vec3(0.0), vec3(1.0)));\n#ifdef FACE_FORWARD\nnormalEC = faceforward(normalEC, vec3(0.0, 0.0, 1.0), -normalEC);\n#endif\nmaterialInput.s = v_st.s;\nmaterialInput.st = v_st;\nmaterialInput.str = vec3(v_st, 0.0);\nmaterialInput.normalEC = normalEC;\nmaterialInput.tangentToEyeMatrix = czm_eastNorthUpToEyeCoordinates(v_positionMC, materialInput.normalEC);\nvec3 positionToEyeEC = -v_positionEC;\nmaterialInput.positionToEyeEC = positionToEyeEC;\nczm_material material = czm_getMaterial(materialInput);\n#ifdef FLAT\ngl_FragColor = vec4(material.diffuse + material.emission, material.alpha);\n#else\ngl_FragColor = czm_phong(normalize(positionToEyeEC), material);\
gl_FragColor.a=0.5;\n#endif\n}\n'//重写shader,修改水面的透明度
    })
});
waters[idx]=viewer.scene.primitives.add(waterPrimitive);

参考链接:https://blog.csdn.net/weixin_42496466/article/details/80747565

admin#45年前 0 个赞

我尝试加水面,为啥看不出来?用链接里面的代码要怎么修改

devhu#55年前 0 个赞

它这个shader只是纯粹的修改了一下透明度,其他没动,uniforms是在material里用的

cesium_abc#63年前 0 个赞

请问cesium怎么做水面投影

添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics