RenderTargetTexture Haloing Effect

Hello All,

I recently starting working with Babylon Editor and have encountered a bug I cannot recreate in Babylon’s playground. I’m trying to setup a picture in picture effect with 2 cameras in one scene. One camera used as the main camera and the other used to render to a RenderTargetTexture. However, when using the RenderTargetTexture I have issues with what looks like both cameras additively rendering to the RenderTargetTexture causing a halo’ing effect. Is there something that I’m doing wrong? Is it a bug with the Babylon Editor? Is there something else that I can use to get around this issue?

The scene’s active camera is in editor. The script lives on a plane mesh parented to the camera so it is faux GUI.
Relevant Code:

export default class RenderTextureScript extends Mesh {
    public onInitialize(): void {
        // ...
        var followCamera = new FollowCamera("FollowCam", new Vector3(0, 10, 0), this._scene, this._scene.meshes.find(mesh => mesh.name == "Ball"));
        followCamera.fov = .2;
        followCamera.minZ = 1;
        followCamera.maxZ = 20;

        var renderTarget = new RenderTargetTexture("RenderTarget", 1024, this._scene);
        renderTarget.activeCamera = followCamera;
        this._scene.meshes.forEach(mesh => {
            if(mesh.name != this.name)
            {
                renderTarget.renderList.push(mesh);
            }
        });

        this._scene.customRenderTargets.push(renderTarget);

        var rttMaterial = new StandardMaterial("RTT Material", this._scene);
        rttMaterial.emissiveTexture = renderTarget;
        rttMaterial.disableLighting = true;
        this.material = rttMaterial;
    }
}

https://i.gyazo.com/d4e8e1a7358b9d370b9d5cc4ba6c8e65.png https://i.gyazo.com/24a6b0817fa707e37e7ea54a23b6c919.png

Adding @julien-moreau

Hi @AWest !

I’m adding your script in a project and take a look right now !

@AWest what I understand right now is that the render target is using the post-processes used by the main camera by default. So the render target will render SSAO (which is activated by default in the project).

I have used “renderTarget.useCameraPostProcesses = false;” in your code and the haloing effect disappeared.

What I tried also was to disable only SSAO post-process:

import { ssao2RenderingPipelineRef } from "../tools";
...

// In the onStart function of the script:
public onStart(): void {
    ssao2RenderingPipelineRef?._detachCameras(this._camera);
}

@CraigFeldspar how would you proceed to enable SSAO on the main camera of a scene and a render target? That would need the geometry buffer renderer (in case using it instead of prepass) to render twice. Is that possible today?

Thanks for you answer :slight_smile:

@AWest here is the full code:

import { Mesh, FollowCamera, Vector3, RenderTargetTexture, StandardMaterial } from "@babylonjs/core";
import { ssao2RenderingPipelineRef } from "../tools";

export default class RenderTextureScript extends Mesh {
    private _camera: FollowCamera;

    /**
     * Override constructor.
     * @warn do not fill.
     */
    // @ts-ignore ignoring the super call as we don't want to re-init
    protected constructor() { }

    /**
     * Called on the node is being initialized.
     * This function is called immediatly after the constructor has been called.
     */
    public onInitialize(): void {
        this._camera = new FollowCamera("FollowCam", new Vector3(0, 10, 0), this._scene, this._scene.meshes.find(mesh => mesh.name == "ball"));
        this._camera.fov = .2;
        this._camera.minZ = 1;
        this._camera.maxZ = 20;

        var renderTarget = new RenderTargetTexture("RenderTarget", 1024, this._scene);
        renderTarget.activeCamera = this._camera;

        this._scene.meshes.forEach(mesh => {
            if (mesh != this) {
                renderTarget.renderList.push(mesh);
            }
        });

        this._scene.customRenderTargets.push(renderTarget);

        var rttMaterial = new StandardMaterial("RTT Material", this._scene);
        rttMaterial.emissiveTexture = renderTarget;
        rttMaterial.disableLighting = true;
        this.material = rttMaterial;
    }

    /**
     * Called on the scene starts.
     */
    public onStart(): void {
        ssao2RenderingPipelineRef._detachCameras(this._camera);
    }

    /**
     * Called each frame.
     */
    public onUpdate(): void {
        // ...
    }
}
1 Like

@CraigFeldspar how would you proceed to enable SSAO on the main camera of a scene and a render target? That would need the geometry buffer renderer (in case using it instead of prepass) to render twice. Is that possible today?

Actually, some work has been done to be able to have a prepass in RTs : https://github.com/BabylonJS/Babylon.js/pull/9591

Here is a PG with a Mirror Texture with SSAO2 inside :

Only works with Prepass though

1 Like

Thanks @CraigFeldspar for these informations :slight_smile: