def add_SSAO(ren):
bounds = np.asarray(ren.ComputeVisiblePropBounds())
b_r = np.linalg.norm([bounds[1] - bounds[0], bounds[3] - bounds[2], bounds[5] - bounds[4]])
occlusion_radius = b_r * 0.1 # tune to your preference
occlusion_bias = 0.04 # not actually sure what this does
passes = vtk.vtkRenderPassCollection()
passes.AddItem(vtk.vtkRenderStepsPass())
seq = vtk.vtkSequencePass()
seq.SetPasses(passes)
ssao = vtk.vtkSSAOPass()
ssao.SetRadius(occlusion_radius)
ssao.SetDelegatePass(seq)
ssao.SetBias(occlusion_bias)
ssao.SetBlur(True)
ssao.SetKernelSize(256) # if this is too low the AO is inaccurate
fxaaP = vtk.vtkOpenGLFXAAPass() # Anti-Aliasing isn't included in the default
fxaaP.SetDelegatePass(ssao)
ren.SetPass(fxaaP)
ren.SetUseDepthPeeling(True)
ren.SetOcclusionRatio(0.1)
ren.SetMaximumNumberOfPeels(100)
return ren
See the vtk forum: