清除
相机渲染场景之前,会清除其渲染目标;未指定渲染目标时,目标就是屏幕。你可以控制清除哪些内容,以及清除为哪种颜色:
camera.camera.clearColor = new pc.Color(0, 0, 0);
camera.camera.clearColorBuffer = true; // clear the color buffer (default: true)
camera.camera.clearDepthBuffer = true; // clear the depth buffer (default: true)
camera.camera.clearStencilBuffer = true; // clear the stencil buffer (default: true)
清除颜色实际上就是场景的背景色。不过,如果场景有天空盒,它会完全覆盖清除颜色。
透明背景
清除颜色具有 alpha 通道,应用画布默认支持透明。因此,单台相机就可以将场景绘制在周围网页之上,适用于 3D 产品展示、页头等嵌入内容:
// The web page shows through wherever nothing is drawn
camera.camera.clearColor = new pc.Color(0, 0, 0, 0);
禁用清除
禁用清除标志会保留渲染目标的现有内容,这是将多个相机合成为一幅图像的基础。参见相机堆叠。