vtkValuePass - Depth Issues

Dear VTK Forum,

I am encountering a challenge while working with vtkValuePass and have uncertainties regarding the depth value computation. I expect the depth values to behave similarly to the geometric coordinates they correspond to, as they do with a color map. However, objects that should be behind a surface seem to be drawn in front of it.
I have attached some screenshots for better illustration:

The color map rendering looks like this :
out1

The vtkValuePass rendering like this :
out0

The part that looks wrong to me is marked with lightblue :
Inkedout0_LI

my code for the value pass is based on the vtk example RenderScalarToFloatBuffer , here it is :

        imgextent = self.image_data.GetExtent()

        renderer = vtk.vtkRenderer()
        renderer.AddActor(self.mesh_actor)
        renderer.SetUseDepthPeeling(True)

        render_window = vtk.vtkRenderWindow()
        render_window.SetMultiSamples(0)
        render_window.SetSize(imgextent[1], imgextent[3])
        render_window.OffScreenRenderingOn()
        render_window.AddRenderer(renderer)

        value_pass = vtk.vtkValuePass()
        value_pass.SetInputArrayToProcess(vtk.VTK_SCALAR_MODE_USE_POINT_FIELD_DATA, "messurment1_dir1")
        value_pass.SetInputComponentToProcess(0)

        render_pass_collection = vtk.vtkRenderPassCollection()
        render_pass_collection.AddItem(value_pass)

        sequence_pass = vtk.vtkSequencePass()
        sequence_pass.SetPasses(render_pass_collection)

        camera_pass = vtk.vtkCameraPass()
        camera_pass.SetDelegatePass(sequence_pass)

        renderer.SetPass(camera_pass)
        renderer.SetActiveCamera(self.renderInterface.GetActiveCamera())
        render_window.Render()

        buffer = value_pass.GetFloatImageDataArray(renderer)

        ext = value_pass.GetFloatImageExtents()
        pointer_hex = int(ext.split('_')[1], 16)
        data_pointer = ctypes.cast(pointer_hex, ctypes.POINTER(ctypes.c_int))
        ext = [data_pointer[0], data_pointer[1], data_pointer[2], data_pointer[3]]
        print(ext)

        width = ext[1]
        height = ext[3]
        f = open('mat.txt', 'w')
        for i in range(width):
            for j in range(height):
                bufferIndex = i*height + j
                value = buffer.GetValue(bufferIndex)
                #print(value)
                f.write(f"{value:9.4e}\n")
            #f.write('\n')
            #print()
        f.close()

        image = vtk.vtkImageData()
        image.SetExtent(ext[0], ext[1], ext[2], ext[3], 0, 0)
        image.GetPointData().SetScalars(buffer)

        lut = vtk.vtkLookupTable()
        lut.SetHueRange(0.6, 0)
        lut.SetSaturationRange(1.0, 0)
        lut.SetValueRange(0.5, 1.0)
        lut.SetTableRange(image.GetScalarRange())

        map_colors = vtk.vtkImageMapToColors()
        map_colors.SetLookupTable(lut)
        map_colors.SetInputDataObject(image)
        map_colors.Update()

        writer = vtk.vtkJPEGWriter()
        writer.SetFileName("out.jpg")
        writer.SetInputData(map_colors.GetOutput())
        writer.Write()

I have also tried to use vtkDepthSortPolyData :

        ...
        self.triangle_polydata = addScalarCellData(self.triangle_polydata, R1, "messurment1_dir1")


        self.depthSortData = vtk.vtkDepthSortPolyData()
        self.depthSortData.SetInputData(self.triangle_polydata)
        self.depthSortData.SetCamera(self.renderInterface.GetActiveCamera())
        self.depthSortData.SortScalarsOn()
        self.depthSortData.SetDirectionToBackToFront()
        #self.depthSortData.SetVector(1, 1, 1)
        self.depthSortData.Update()

        self.mesh_mapper = vtk.vtkPolyDataMapper()
        self.mesh_mapper.SetInputData(self.depthSortData.GetOutput())
        sr = 0.0005
        self.mesh_mapper.SetScalarRange([0., sr])
        self.mesh_mapper.SetLookupTable(self.lut)

        self.mesh_actor = vtk.vtkActor()
        self.mesh_actor.SetMapper(self.mesh_mapper)
        ...

Any suggestions would be highly appreciated. :slight_smile: