Cesium高级教程-离屏渲染-隐藏不必要的渲染内容

Cesium高级教程-离屏渲染-隐藏不必要的渲染内容

隐藏内容

在上一节我们通过翻转的方式,将FBO的内容正确地绘制到canvas上,在渲染场景到FBO时,我们使用的Scene类中的render方法里面的代码,代码中其实有些可能是我们不需要的,比如有时我们的离屏渲染可能并不需要天空、大气、甚至连地球也不需要,那我们可以在离屏渲染时将这些对象隐藏掉,以节省程序的性能开销。

function renderToFbo(fbo, scene) {
    const frameState = scene._frameState; 
    scene.globe.show=false;
    const context = scene.context;
    const us = context.uniformState;
    const view = scene._defaultView;
    scene._view = view;
    scene.updateFrameState();
    frameState.passes.render = true;
    frameState.passes.postProcess = scene.postProcessStages.hasSelected;
    frameState.tilesetPassState = renderTilesetPassState;
    let backgroundColor = Cesium.defaultValue(scene.backgroundColor, Cesium.Color.BLACK);
    // if (scene._hdr) {
    //     backgroundColor = Cesium.Color.clone(backgroundColor, scratchBackgroundColor);
    //     backgroundColor.red = Cesium.Math.pow(backgroundColor.red, scene.gamma);
    //     backgroundColor.green = Cesium.Math.pow(backgroundColor.green, scene.gamma);
    //     backgroundColor.blue = Cesium.Math.pow(backgroundColor.blue, scene.gamma);
    // }
    frameState.backgroundColor = backgroundColor;
    frameState.atmosphere = scene.atmosphere;
    scene.fog.update(frameState);
    us.update(frameState);
    // const shadowMap = scene.shadowMap;
    // if (Cesium.defined(shadowMap) && shadowMap.enabled) {
    //     if (!Cesium.defined(scene.light) || scene.light instanceof SunLight) {
    //         // Negate the sun direction so that it is from the Sun, not to the Sun
    //         Cesium.Cartesian3.negate(us.sunDirectionWC, scene._shadowMapCamera.direction);
    //     } else {
    //         Cesium.Cartesian3.clone(scene.light.direction, scene._shadowMapCamera.direction);
    //     }
    //     frameState.shadowMaps.push(shadowMap);
    // }
    scene._computeCommandList.length = 0;
    scene._overlayCommandList.length = 0;
    const viewport = view.viewport;
    viewport.x = 0;
    viewport.y = 0;
    viewport.width = context.drawingBufferWidth;
    viewport.height = context.drawingBufferHeight;
    const passState = view.passState;
    passState.framebuffer = fbo;
    passState.blendingEnabled = undefined;
    passState.scissorTest = undefined;
    passState.viewport = Cesium.BoundingRectangle.clone(viewport, passState.viewport);
    // if (Cesium.defined(scene.globe)) {
    //     scene.globe.beginFrame(frameState);
    // }
    // scene.updateEnvironment();
    scene.updateAndExecuteCommands(passState, backgroundColor);
    scene.resolveFramebuffers(passState);
    passState.framebuffer = undefined;
    //executeOverlayCommands(scene, passState);
    // if (Cesium.defined(scene.globe)) {
    //     scene.globe.endFrame(frameState);
    //     if (!scene.globe.tilesLoaded) {
    //         scene._renderRequested = true;
    //     }
    // }
    context.endFrame();
    scene.globe.show = true;
} 

示例效果可到 xt3d 官网 运行查看

更多内容见 Cesium高级教程-教程简介

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xt3d

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值