Skip to content

Overwriting the this.context.composer breaks XR views #101

@ROBYER1

Description

@ROBYER1

Exporter 2.39.3-pre, Unity 2022.1.16f1

Tested on Android Chrome, Xperia 1 Using the below script as PostProcessing.ts in scripts added to a gameobject in the scene, toggling AR view doesn't show the place on surface marker, then pressing the back button in the browser to return to the previous normal 3d view shows the regular view in a squashed cube-shaped window on the bottom half of the screen.

import { Behaviour } from "@needle-tools/engine/engine-components/Component";
import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer.js';
import { RenderPass } from 'three/examples/jsm/postprocessing/RenderPass';
import { UnrealBloomPass } from 'three/examples/jsm/postprocessing/UnrealBloomPass.js';
import { WebGLRenderer} from 'three';
import { GUI } from "three/examples/jsm/libs/lil-gui.module.min.js";

export class PostProcessing extends Behaviour
{
    //@ts-ignore
    params?: PostProcessing.params = {
        //exposure: 1,
        bloomThreshold: 0.656,
        bloomStrength: 2.631,
        bloomRadius: 0.95
    };

    mainComposer?: EffectComposer; 
    renderer?: THREE.WebGLRenderer;

    start()//
    {
        //@ts-ignore
        const bloomPass = new UnrealBloomPass( new THREE.Vector2( window.innerWidth, window.innerHeight ), 1.5, 0.4, 0.85 );
        bloomPass.threshold = this.params.bloomThreshold;
        bloomPass.strength = this.params.bloomStrength;
        bloomPass.radius = this.params.bloomRadius;

        //@ts-ignore
        this.mainComposer = new EffectComposer(this.context.renderer);

        //@ts-ignore
        const renderPass = new RenderPass(this.scene, this.context.mainCamera);
        this.renderer = new WebGLRenderer({ antialias: true, });
        this.renderer?.setSize(this.context.domWidth, this.context.domHeight);
        this.mainComposer.addPass(renderPass);
        this.mainComposer?.addPass(bloomPass);
        this.mainComposer.setSize(this.context.domWidth, this.context.domHeight);

        this.context.composer = this.mainComposer;

        const gui = new GUI();

        gui.add( this.params, 'bloomThreshold', 0.0, 1.0 ).onChange( function ( value ) {

            bloomPass.threshold = Number( value );

        } );

        gui.add( this.params, 'bloomStrength', 0.0, 3.0 ).onChange( function ( value ) {

            bloomPass.strength = Number( value );

        } );

        gui.add( this.params, 'bloomRadius', 0.0, 1.0 ).step( 0.01 ).onChange( function ( value ) {

            bloomPass.radius = Number( value );

        } );
    }
}

c1c44870-928b-445e-9d67-6267e738343a

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions