Can I use ThreeJS realism effects through Needle

Is it possible to utilise the ThreeJS realism effects from 0beqz when using Needle Engine (GitHub - 0beqz/realism-effects: SSGI, Motion Blur, TRAA - Effects to enhance your three.js scene's realism)

Original Post on Discord

by user 191894382805254144

Hi, technically yes (since we also run based on threejs) but I havent tried it in a while. pmndrs postprocessing package is already a dependency of Needle Engine. You can install this package to your project too, create a composer and assign it to the Needle Engine context to use it

Let me know if you have any more questions

Here’s some very simple example based off of the usage sample here: GitHub - 0beqz/realism-effects: SSGI, Motion Blur, TRAA - Effects to enhance your three.js scene's realism

import { Behaviour } from "@needle-tools/engine";
import * as POSTPROCESSING from "postprocessing"
import { SSAOEffect, HBAOEffect, SSGIEffect, TRAAEffect, MotionBlurEffect, VelocityDepthNormalPass } from "realism-effects"

export class Realism extends Behaviour {
    private _composer: POSTPROCESSING.EffectComposer | null = null
    awake() {
        const renderer = this.context.renderer;
        const scene = this.context.scene;
        const camera = this.context.mainCamera!;

        const composer = new POSTPROCESSING.EffectComposer(renderer)

        const velocityDepthNormalPass = new VelocityDepthNormalPass(scene, camera)
        composer.addPass(velocityDepthNormalPass)

        // SSGI
        const ssgiEffect = new SSGIEffect(scene, camera, velocityDepthNormalPass)

        // TRAA
        const traaEffect = new TRAAEffect(scene, camera, velocityDepthNormalPass)

        // Motion Blur
        const motionBlurEffect = new MotionBlurEffect(velocityDepthNormalPass)

        // SSAO
        const ssaoEffect = new SSAOEffect(composer, camera, scene)

        // HBAO
        const hbaoEffect = new HBAOEffect(composer, camera, scene)

        const effectPass = new POSTPROCESSING.EffectPass(camera, ssgiEffect, hbaoEffect, ssaoEffect, traaEffect, motionBlurEffect)

        composer.addPass(effectPass)

        this._composer = composer
    }
    onEnable(): void {
        this.context.composer = this._composer;
    }
    onDisable(): void {
        this.context.composer = null;
    }
    onDestroy(): void {
        this._composer?.dispose();
    }
}