Cesium高级教程-深度图-场景深度图

Cesium高级教程-深度图-场景深度图

场景深度支持

在Cesium应用中,可以通过scene.context.depthTexture属性来判断是否支持深度图

 function Context(canvas, options) {
     ...
     Object.defineProperties(Context.prototype, {
         /**
         * <code>true</code> if WEBGL_depth_texture is supported.  This extension provides
         * access to depth textures that, for example, can be attached to framebuffers for shadow mapping.
         * @memberof Context.prototype
         * @type {boolean}
         * @see {@link http://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/|WEBGL_depth_texture}
         */
         depthTexture: {
             get: function () {
                 return this._depthTexture || this._webgl2;
             },
         },
         ...
     })
 }   

深度图是一个Texture类型,也就是一张纹理图,只是存储的是深度信息。

 this._depthStencilTexture = new Texture({
   context: context,
   width: width,
   height: height,
   pixelFormat: PixelFormat.DEPTH_STENCIL,
   pixelDatatype: PixelDatatype.UNSIGNED_INT_24_8,
   sampler: Sampler.NEAREST,
 });

场景深度纹理

Cesium并没有提供场景深度纹理的访问接口,因为这个深度纹理是在渲染过程中会根据指定的条件获取,并不固定,并且在整个渲染生命周期结束后,可能就将深度图就被清空了,所以在外面即使能获取到也没有什么用,具体可见Scene类中render等方法,重点可以看resolveFramebuffers方法。

Scene.prototype.resolveFramebuffers = function (passState) {
  const context = this._context;
  const environmentState = this._environmentState;
  const view = this._view;
  const { globeDepth, translucentTileClassification } = view;
  if (defined(globeDepth)) {
    globeDepth.prepareColorTextures(context);
  }

  const {
    useOIT,
    useGlobeDepthFramebuffer,
    usePostProcess,
    originalFramebuffer,
  } = environmentState;

  const globeFramebuffer = useGlobeDepthFramebuffer
    ? globeDepth.colorFramebufferManager
    : undefined;
  const sceneFramebuffer = view.sceneFramebuffer._colorFramebuffer;
  const idFramebuffer = view.sceneFramebuffer.idFramebuffer;

  if (useOIT) {
    passState.framebuffer = usePostProcess
      ? sceneFramebuffer.framebuffer
      : originalFramebuffer;
    view.oit.execute(context, passState);
  }

  if (
    translucentTileClassification.hasTranslucentDepth &&
    translucentTileClassification.isSupported()
  ) {
    translucentTileClassification.execute(this, passState);
  }

  if (usePostProcess) {
    view.sceneFramebuffer.prepareColorTextures(context);
    let inputFramebuffer = sceneFramebuffer;
    if (useGlobeDepthFramebuffer && !useOIT) {
      inputFramebuffer = globeFramebuffer;
    }

    const postProcess = this.postProcessStages;
    const colorTexture = inputFramebuffer.getColorTexture(0);
    const idTexture = idFramebuffer.getColorTexture(0);
    const depthTexture = defaultValue(
      globeFramebuffer,
      sceneFramebuffer,
    ).getDepthStencilTexture();
    postProcess.execute(context, colorTexture, depthTexture, idTexture);
    postProcess.copy(context, originalFramebuffer);
  }

  if (!useOIT && !usePostProcess && useGlobeDepthFramebuffer) {
    passState.framebuffer = originalFramebuffer;
    globeDepth.executeCopyColor(context, passState);
  }
};

在将场景渲染结果交给后处理程序进行处理时,传入了对应的深度纹理

 const depthTexture = defaultValue(
    globeFramebuffer,
    sceneFramebuffer,
  ).getDepthStencilTexture();
 postProcess.execute(context, colorTexture, depthTexture, idTexture);

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

xt3d

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

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

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

打赏作者

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

抵扣说明:

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

余额充值