diff --git a/src/scene/camera.js b/src/scene/camera.js index 3a8d1584fd1..2c61b360518 100644 --- a/src/scene/camera.js +++ b/src/scene/camera.js @@ -12,7 +12,6 @@ import { } from './constants.js'; import { RenderPassColorGrab } from './graphics/render-pass-color-grab.js'; import { RenderPassDepthGrab } from './graphics/render-pass-depth-grab.js'; -import { RenderPassDepth } from './graphics/render-pass-depth.js'; // pre-allocated temp variables const _deviceCoord = new Vec3(); @@ -497,9 +496,7 @@ class Camera { _enableRenderPassDepthGrab(device, renderer, enable) { if (enable) { if (!this.renderPassDepthGrab) { - this.renderPassDepthGrab = device.isWebGL1 ? - new RenderPassDepth(device, renderer, this) : - new RenderPassDepthGrab(device, this); + this.renderPassDepthGrab = new RenderPassDepthGrab(device, this); } } else { this.renderPassDepthGrab?.destroy(); diff --git a/src/scene/graphics/render-pass-depth.js b/src/scene/graphics/render-pass-depth.js deleted file mode 100644 index f54295b9779..00000000000 --- a/src/scene/graphics/render-pass-depth.js +++ /dev/null @@ -1,125 +0,0 @@ -import { Color } from "../../core/math/color.js"; -import { ADDRESS_CLAMP_TO_EDGE, FILTER_NEAREST, PIXELFORMAT_RGBA8 } from "../../platform/graphics/constants.js"; -import { Texture } from "../../platform/graphics/texture.js"; -import { RenderPass } from "../../platform/graphics/render-pass.js"; -import { BlendState } from "../../platform/graphics/blend-state.js"; -import { RenderTarget } from "../../platform/graphics/render-target.js"; -import { LAYERID_DEPTH, SHADER_DEPTH } from "../constants.js"; - -const webgl1DepthClearColor = new Color(254.0 / 255, 254.0 / 255, 254.0 / 255, 254.0 / 255); -const tempMeshInstances = []; -const lights = [[], [], []]; - -// uniform names (first is current name, second one is deprecated name for compatibility) -const _depthUniformNames = ['uSceneDepthMap', 'uDepthMap']; - -/** - * A render pass implementing rendering of depth. In current implementation, the depth is encoded in - * RGBA8 texture, and is used on WebGL1 devices as a fallback for missing depth grab functionality. - * - * @ignore - */ -class RenderPassDepth extends RenderPass { - constructor(device, renderer, camera) { - super(device); - this.renderer = renderer; - this.camera = camera; - - this.setupRenderTarget(); - } - - destroy() { - super.destroy(); - - if (this.renderTarget) { - this.renderTarget.destroyTextureBuffers(); - this.renderTarget.destroy(); - this.renderTarget = null; - } - } - - update(scene) { - this.scene = scene; - } - - setupRenderTarget() { - - const texture = new Texture(this.device, { - name: _depthUniformNames[0], - format: PIXELFORMAT_RGBA8, - width: 4, - height: 4, - mipmaps: false, - minFilter: FILTER_NEAREST, - magFilter: FILTER_NEAREST, - addressU: ADDRESS_CLAMP_TO_EDGE, - addressV: ADDRESS_CLAMP_TO_EDGE - }); - - const renderTarget = new RenderTarget({ - name: `${_depthUniformNames[0]}RT}`, - colorBuffer: texture, - depth: true, - stencil: false - }); - - this.init(renderTarget, {}); - - // webgl1 depth rendering clear values - this.setClearColor(webgl1DepthClearColor); - this.setClearDepth(1.0); - } - - before() { - - // assign uniform - const device = this.device; - const colorBuffer = this.renderTarget.colorBuffer; - _depthUniformNames.forEach(name => device.scope.resolve(name).setValue(colorBuffer)); - } - - execute() { - - const { device, renderer, camera, scene, renderTarget } = this; - const layers = scene.layers.layerList; - const subLayerEnabled = scene.layers.subLayerEnabled; - const isTransparent = scene.layers.subLayerList; - - for (let i = 0; i < layers.length; i++) { - const layer = layers[i]; - - if (layer.enabled && subLayerEnabled[i]) { - - // if the layer is rendered by the camera - if (layer.camerasSet.has(camera)) { - - // only render the layers before the depth layer - if (layer.id === LAYERID_DEPTH) - break; - - const culledInstances = layer.getCulledInstances(camera); - const meshInstances = isTransparent[i] ? culledInstances.transparent : culledInstances.opaque; - - for (let j = 0; j < meshInstances.length; j++) { - const meshInstance = meshInstances[j]; - - // only collect meshes that update the depth - if (meshInstance.material?.depthWrite) { - tempMeshInstances.push(meshInstance); - } - } - - renderer.setCameraUniforms(camera, renderTarget); - renderer.renderForward(camera, tempMeshInstances, lights, SHADER_DEPTH, (meshInstance) => { - // writing depth to color render target, force no blending and writing to all channels - device.setBlendState(BlendState.NOBLEND); - }, layer); - - tempMeshInstances.length = 0; - } - } - } - } -} - -export { RenderPassDepth }; diff --git a/src/scene/renderer/forward-renderer.js b/src/scene/renderer/forward-renderer.js index 38946d67a9a..bf0791fe50d 100644 --- a/src/scene/renderer/forward-renderer.js +++ b/src/scene/renderer/forward-renderer.js @@ -819,7 +819,6 @@ class ForwardRenderer extends Renderer { buildFrameGraph(frameGraph, layerComposition) { const scene = this.scene; - const webgl1 = this.device.isWebGL1; frameGraph.reset(); // update composition, cull everything, assign atlas slots for clustered lighting @@ -858,20 +857,7 @@ class ForwardRenderer extends Renderer { } else { - // on webgl1, depth pass renders ahead of the main camera instead of the middle of the frame - const depthPass = camera.camera.renderPassDepthGrab; - if (depthPass && webgl1 && renderAction.firstCameraUse) { - depthPass.options.resizeSource = camera.camera.renderTarget; - depthPass.update(this.scene); - frameGraph.addRenderPass(depthPass); - } - const isDepthLayer = layer.id === LAYERID_DEPTH; - - // skip depth layer on webgl1 if color grab pass is not enabled, as depth pass renders ahead of the main camera - if (webgl1 && isDepthLayer && !camera.renderSceneColorMap) - continue; - const isGrabPass = isDepthLayer && (camera.renderSceneColorMap || camera.renderSceneDepthMap); // start of block of render actions rendering to the same render target @@ -884,7 +870,7 @@ class ForwardRenderer extends Renderer { // info about the next render action const nextRenderAction = renderActions[i + 1]; const isNextLayerDepth = nextRenderAction ? nextRenderAction.layer.id === LAYERID_DEPTH : false; - const isNextLayerGrabPass = isNextLayerDepth && (camera.renderSceneColorMap || camera.renderSceneDepthMap) && !webgl1; + const isNextLayerGrabPass = isNextLayerDepth && (camera.renderSceneColorMap || camera.renderSceneDepthMap); const nextNeedDirShadows = nextRenderAction ? (nextRenderAction.firstCameraUse && this.cameraDirShadowLights.has(nextRenderAction.camera.camera)) : false; // end of the block using the same render target if the next render action uses a different render target, or needs directional shadows @@ -907,7 +893,7 @@ class ForwardRenderer extends Renderer { frameGraph.addRenderPass(colorGrabPass); } - if (camera.renderSceneDepthMap && !webgl1) { + if (camera.renderSceneDepthMap) { frameGraph.addRenderPass(camera.camera.renderPassDepthGrab); } }