Scene渲染命令集合(executeCommands)分析

发布时间 2023-11-28 12:37:36作者: 安安静静的码农

Scene渲染命令集合(executeCommands)分析

前提条件:

// 已经确定了渲染缓冲区: view.globeDepth.framebuffer
passState.framebuffer = view.globeDepth.framebuffer

1、简单流程,没有pick和后处理

// 一般性流程
executeCommands(scene, passState) {
  // 更新相机
  us.updateCamera(camera);

  // 更新视锥
  us.updateFrustum(frustum)

  // -------------------------- 一、渲染环境 -----------------
  us.updatePass(Pass.ENVIRONMENT);
  // sky, sun, moon...

  // ------------------------- 二、渲染视椎里的内容 ---------------------------
  // ----------- 0、准备 -------------------
  // 确定如何处理半透明表面。
  executeTranslucentCommands = scene._executeOITFunction;

  // 读环境状态
  const clearGlobeDepth = environmentState.clearGlobeDepth;
  const useDepthPlane = environmentState.useDepthPlane;
  const usePostProcessSelected = environmentState.usePostProcessSelected;

  // 读场景状态
  const clearClassificationStencil = scene._classificationStencilClearCommand;
  const clearDepth = scene._depthClearCommand;
  const clearStencil = scene._stencilClearCommand;

  // 清除深度缓冲区和模板缓冲区, 颜色缓冲区呢?
  clearDepth.execute(context, passState);
  clearStencil.execute(context, passState);

  // ----------- 1、绘制 GLOBE -------------------
  us.updatePass(Pass.GLOBE);

  // 执行深度拷贝
  // 读入 view.globeDepth._outputFramebuffer 的 getDepthStencilTexture()
  // 写入 view.globeDepth._copyDepthFramebuffer
  globeDepth.executeCopyDepth(context, passState);

  // ----------- 2、绘制 terrain -------------------
  us.updatePass(Pass.TERRAIN_CLASSIFICATION);

  // ----------- 3、绘制 3D Tiles-------------------
  us.updatePass(Pass.CESIUM_3D_TILE);

  // ----------- 4、绘制 体素-------------------
  us.updatePass(Pass.VOXELS);

  // ----------- 5、绘制 不透明元素-------------------
  us.updatePass(Pass.OPAQUE);

  // ----------- 6、绘制 透明元素-------------------
  us.updatePass(Pass.TRANSLUCENT);

  // 执行深度拷贝
  // 读入 globeDepth.depthStencilTexture
  // 写入 pickDepth._framebuffer,用于位置拾取
  const depthStencilTexture = globeDepth.depthStencilTexture;
  const pickDepth = scene._picking.getPickDepth(scene, index);
  pickDepth.update(context, depthStencilTexture);
  pickDepth.executeCopyDepth(context, passState);

  // 如果 picking || !usePostProcessSelected, 就结束了

  // todo...
}