Disabling Ambient Occlusion

Hey community,

I am looking for a way to disable ambient occlusion (AO) in my renderer. I am currently working on a two-point perspective, which causes a mismatch between the AO and the geometry, as you can see here:

As there are different view modes available, I suspect there is a way to disable AO. Does anyone know how?

Best regards,
Mathias

Hi @MathiasWorm

Disabling AO is easy, and attainable through options

const passes = viewer.getRenderer().pipeline.getPass('PROGRESSIVE-AO')
passes.forEach((pass: GPass) => {
  pass.options = { intensity: 0 }
})

However, AO should display properly as long as it gets the correct params. If you can give me more details about what you are doing maybe we can figure out what’s wrong.

Cheers

1 Like

Hi @alex

Thank you for your reply. That worked straight away and is a good temporary solution. However, perhaps we could also find a way to pass the updated frustrum to the ‘AOPass’ and ‘EdgePass’?

I mention the edges here because the same ‘issue’ affects them too.

To achieve the two-point perspective with the camera, I do this:


            const forward = new THREE.Vector3();
            camera.getWorldDirection(forward); 
            const horizontalDistance = Math.sqrt(forward.x * forward.x + forward.y * forward.y);
            
            if (horizontalDistance < 0.001) return;

            const tanPitch = forward.z / horizontalDistance;

            const forwardHorz = new THREE.Vector3(forward.x, forward.y, 0).normalize();
            const horizontalTarget = new THREE.Vector3().copy(camera.position).add(forwardHorz);
            
            camera.up.set(0, 0, 1);
            camera.lookAt(horizontalTarget);

            const fovHalfRad = THREE.MathUtils.degToRad(camera.fov * 0.5);
            const shiftFraction = tanPitch / (2 * Math.tan(fovHalfRad));

        
            const filmWidth = 10000;
            const filmHeight = filmWidth / camera.aspect;

    
            const shiftYPixels = -shiftFraction * filmHeight;
            
            camera.setViewOffset(filmWidth, filmHeight, 0, shiftYPixels, filmWidth, filmHeight);

It seems that setViewOffSet() does not propagate the update to the other system. Is there a way to achieve this?

Best regards

Hi @MathiasWorm

Happy to hear this works as a temporary solution at least.

I’ve looked into the issue and internally some passes (like Edged and AO) set their own camera view offset when rendering, so the values you compute are being overwritten for those passes.

What you could do is extend the pipeline you are using and override the render function, like for example if you use DefaultPipeline

class MyExtendedPipeline extends DefaultPipeline {

public render(): boolean{
  ... // copy over existing implementation
  ... // and just apply jitter on top of existing projection values
  } else if (camera instanceof PerspectiveCamera) {
      camera.projectionMatrix.elements[8] += jitterX / this.drawingSize.x
      camera.projectionMatrix.elements[9] += jitterY / this.drawingSize.y
  }
  ... // whatever is left aftewards
}
}

So basically you are adding the jitter on top of whatever offset you already computed by yourself.
It’s not ideal, as you’d have to copy over code, it’s also untested of course. Also, if you want to apply this to all of your pipelines you could probably just overwrite Pipeline’s prototype with the above instead of extending each derived pipeline and changing the render funtion.

Cheers

1 Like