N8python / n8ao

An efficient and visually pleasing implementation of SSAO with an emphasis on temporal stability and artist control.
Creative Commons Zero v1.0 Universal
378 stars 14 forks source link

Is there any way to integrate with fog? #10

Closed LukeCarlThompson closed 1 year ago

LukeCarlThompson commented 1 year ago

Nice work on this, it's performing very well when testing so far.

One potential issue I'm encountering is that the AO effect is drawn over the top of any fog in the scene. I'm assuming because this effect is a screen space one it's not possible to actually draw it onto the material shaders before the fog. But I wondered if there was some depth information available and we could fade the opacity of the effect based on distance from the camera or something else that would give a reasonable approximation?

Is this kind of thing possible currently or any plans to implement?

N8python commented 1 year ago

Yes, I could modulate the effect by fog. This feature will be added in the next update.

N8python commented 1 year ago

Fog has been added - let me know if its working.

LukeCarlThompson commented 1 year ago

Nice one! It's working perfectly and blending in with the fog.

However there does appear to be a new side effect when working with the pmndrs post processing library using a bloom pass.

Previously I would do a renderPass, then the N8AOPostPass then the post processing effect pass that contained a bloom effect and it all worked together well but the AO effect just displayed over the fog.

Now with the same workflow the AO effect blends in perfectly with the fog, but it seems to disable the bloom effect, the other post processing effect passes still seem to work and there is no error shown in the console.

Not sure if this is actually an issue, but I thought I'd let you know.

Below is a link to my WIP game which has the effects applied.

https://swimmy-fish.lukethompson.com.au/#debug

Let me know if it would be useful and I'll create a minimum example to reproduce the behaviour.

N8python commented 1 year ago
Screen Shot 2023-06-13 at 11 31 23 AM

Here's a picture of (overdone) bloom working with N8AOPass... try updating to 1.6.1.

A minimal example would be helpful!

N8python commented 1 year ago

Try - instead of this: this.effectPass = new gD(this.camera,this.aaEffect,this.brightnessContrastEffect,this.bloomEffect), This: this.effectPass = new gD(this.camera,this.brightnessContrastEffect,this.bloomEffect, this.aaEffect),

As the AA effect should come after everything.

BTW this works with the latest version:


    const composer = new EffectComposer(renderer);
    composer.addPass(new RenderPass(scene, camera));
    const n8aopass = new N8AOPostPass(
        scene,
        camera,
        clientWidth,
        clientHeight
    );
    composer.addPass(n8aopass);
    composer.addPass(new EffectPass(camera, new BloomEffect({
        luminanceThreshold: 0.0,
        intensity: 5.0
    }), new SMAAEffect({
        preset: SMAAPreset.ULTRA
    })));
LukeCarlThompson commented 1 year ago

Thank you for that. I see what the difference is now.

I'm using a selective bloom technique where I set the bloom effect luminance threshold to 1 and then set the materials I want bloom on to betoneMapped: false and the emissiveIntensity to a high value like 8. Then only those objects will have the bloom effect applied. Could it be that because the N8aopass goes first it renders a tone mapped output or some other way of clipping the colours back into the normal range of 0 - 1?

If you try this code sandbox and comment out the aoPass on line 79 you will see the bloom effect is visible again.

https://codesandbox.io/s/sparkling-cdn-qslj6y?file=/src/index.js

N8python commented 1 year ago

N8AO uses non-float render targets... that could definitely be the problem. Next update (will be released tonight/early tmrw) will add support for floating render targets.

N8python commented 1 year ago

Should be fixed now.

LukeCarlThompson commented 1 year ago

Yep, it's working great. Thanks so much really appreciate the great work and fast updates!