[SOLVED] Render Object Over Another Objects with one camera

It is possible by setting a layer to clear depth before you render meshes in a layer that you want to render on top of everything else.

I’ve done it in the project here: https://playcanvas.com/project/950571/overview/fps-pit

I’ve made a layer called ‘Clear Depth’ that I set in code to clear the depth buffer.

Code: https://playcanvas.com/editor/code/950571?tabs=95528900

(function() {
    const app = pc.Application.getApplication();
    app.on('start', () => {
        // We have special layer that we want to set so that it clears the depth buffer
        // This helps us render the weapon on top of the world
        const clearDepthLayer = app.scene.layers.getLayerByName('Clear Depth');
        clearDepthLayer.clearDepthBuffer = true;
    });
})();

This means that anything that renders after this layer is going to render over anything that has rendered before.

In my case, the Weapon layer that the gun is on:

2 Likes