# VTK blend color in wierd way with vtkassembly

**URL:** https://discourse.vtk.org/t/vtk-blend-color-in-wierd-way-with-vtkassembly/2149
**Category:** Support
**Created:** [November 26, 2019, 2:20am UTC](https://discourse.vtk.org/t/vtk-blend-color-in-wierd-way-with-vtkassembly/2149 "2019-11-26T02:20:02Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![lainegates](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lainegates/32/1349_2.png) [@lainegates](https://discourse.vtk.org/u/lainegates)
#### Post date: [November 26, 2019, 2:20am UTC](https://discourse.vtk.org/t/vtk-blend-color-in-wierd-way-with-vtkassembly/2149/1 "2019-11-26T02:20:02Z")

</div>

When I update VTK to version 8.2.0, I encounter a specical bug that VTK will blend color with ‘vtkAssembly’ in wierd way comparing to behavior by `vtkActor` .

While blend color with vtkAssembly, it seems that VTK just add color by (r,g,b), thus white color appears offen.

In the following example, left is drawn by `vtkActor` , and right is added to scene by `vtkAssembly`  
 ![%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20191125222905](https://discourse.vtk.org/uploads/default/original/2X/5/5d0b3bad88d1e9ea33115300a34360c7b6b8b5d1.png)

I reproduce bug with following simple code :

```cpp
#include "vtkActor.h"
#include "vtkNew.h"
#include "vtkCamera.h"
#include "vtkCellArray.h"
#include "vtkFloatArray.h"
#include "vtkPointData.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderWindow.h"
#include <vtkGenericOpenGLRenderWindow.h>
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include <vtkLookupTable.h>
#include <vtkProperty.h>
#include <vtkCellData.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkAssembly.h>

#include <vtkAutoInit.h>

VTK_MODULE_INIT(vtkRenderingOpenGL2)
VTK_MODULE_INIT(vtkInteractionStyle)
VTK_MODULE_INIT(vtkRenderingFreeType)

void createScene(vtkActor* actor)
{
    int i;
    //
    static float x[10][3]={{ 0, 0, 1}, { 0, 0,-1}
                          , { 0, 1, 0}, { 1, 1, 0}
                          , { 1, 0, 0}, { 1,-1, 0}
                          , { 0,-1, 0}, {-1,-1, 0}
                          , {-1, 0, 0}, {-1, 1, 0}};
    //
    static vtkIdType pts[8][4]={{0,1,2}, {0,1,3}, {0,1,4}, {0,1,5}
                                , {0,1,6}, {0,1,7}, {0,1,8}, {0,1,9}};
    //
    vtkPolyData *cube = vtkPolyData::New();
    vtkPoints *points = vtkPoints::New();
    vtkCellArray *polys = vtkCellArray::New();
    //
    vtkFloatArray *scalars = vtkFloatArray::New();
    //
    for(i=0;i<10;i++)points->InsertPoint(i,x[i]);
    //
    for(i=0;i<8;i++)polys->InsertNextCell(4,pts[i]);
    //
    for(i=0;i<8;i++)scalars->InsertTuple1(i,i);
    //
    cube->SetPoints(points);
    //
    cube->SetPolys(polys);
    //
    cube->GetCellData()->SetScalars(scalars);
    points->Delete();
    polys->Delete();
    scalars->Delete();
    //
    vtkLookupTable *pColorTable=vtkLookupTable::New();
    //
    pColorTable->SetNumberOfColors(6);
    pColorTable->SetTableValue(0, 1.0, 0.0, 0.0, 1.0);
    pColorTable->SetTableValue(1, 0.0, 1.0, 0.0, 1.0);
    pColorTable->SetTableValue(2, 1.0, 1.0, 0.0, 1.0);
    pColorTable->SetTableValue(3, 0.0, 0.0, 1.0, 1.0);
    pColorTable->SetTableValue(4, 1.0, 0.0, 1.0, 1.0);
    pColorTable->SetTableValue(5, 0.0, 1.0, 1.0, 1.0);
    pColorTable->Build();

    //
    vtkPolyDataMapper *cubeMapper = vtkPolyDataMapper::New();
    cubeMapper->SetScalarModeToUseCellData();
    cubeMapper->SetInputData(cube);
    cubeMapper->SetScalarRange(0,7);
    cubeMapper->SetLookupTable(pColorTable);
    actor->SetMapper(cubeMapper);
    actor->GetProperty()->SetOpacity(0.5);
}

int main(int argc, char** argv)
{
    vtkCamera *camera = vtkCamera::New();
    camera->SetPosition(1,1,1);
    camera->SetFocalPoint(0,0,0);

    vtkRenderer *renderer = vtkRenderer::New();

    vtkRenderWindow *renWin = vtkRenderWindow::New();
    renWin->AddRenderer(renderer);

    vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
    iren->SetRenderWindow(renWin);
    iren->SetInteractorStyle(vtkInteractorStyleTrackballCamera::New());

    vtkNew<vtkActor> actor1, actor2;
    createScene(actor1);
    renderer->AddActor(actor1);

    createScene(actor2);
    vtkNew<vtkAssembly> assembly;
    assembly->AddPart(actor2);
    assembly->SetPosition(3,0,0);
    renderer->AddActor(assembly);

    renderer->SetActiveCamera(camera);
    renderer->ResetCamera();
    renderer->SetBackground(0,0,0);

    renWin->SetSize(600,600);
    renWin->Render();
    iren->Start();
    return 0;
}

```

---

<div class="post-metadata">

### Author: ![marcomusy](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcomusy/32/95_2.png) [@marcomusy](https://discourse.vtk.org/u/marcomusy)
#### Post date: [November 26, 2019, 5:22pm UTC](https://discourse.vtk.org/t/vtk-blend-color-in-wierd-way-with-vtkassembly/2149/2 "2019-11-26T17:22:44Z")

</div>

I guess it has to do with `vtkRenderer.SetUseDepthPeeling()`  
I can reproduce it in python with vtk 8.1.2:

`SetUseDepthPeeling(True)`:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/a/a006d79b0f1d1de7b71f0eff1da432ddb25dfe36.png)

`SetUseDepthPeeling(False)`:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/7/7453ca2759336276474c05e62588937b92f07ce4.png)

```python
from vtkplotter import *

settings.useDepthPeeling = False

vtxs = [
    [0, 0, 1],
    [0, 0, -1],
    [0, 1, 0],
    [1, 1, 0],
    [1, 0, 0],
    [1, -1, 0],
    [0, -1, 0],
    [-1, -1, 0],
    [-1, 0, 0],
    [-1, 1, 0],
]
faces = [
    [0, 1, 2],
    [0, 1, 3],
    [0, 1, 4],
    [0, 1, 5],
    [0, 1, 6],
    [0, 1, 7],
    [0, 1, 8],
    [0, 1, 9],
]
arr = range(len(faces))

actor1 = Actor([vtxs,faces]).addCellScalars(arr, "myscals").alpha(0.5)
actor2 = Actor([vtxs,faces]).addCellScalars(arr, "myscals").alpha(0.5)
asse = Assembly([actor2])

show(actor1, asse, N=2, bg="black", viewup="z")

```

---

<div class="post-metadata">

### Author: ![lainegates](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lainegates/32/1349_2.png) [@lainegates](https://discourse.vtk.org/u/lainegates)
#### Post date: [November 27, 2019, 8:56am UTC](https://discourse.vtk.org/t/vtk-blend-color-in-wierd-way-with-vtkassembly/2149/3 "2019-11-27T08:56:19Z")

</div>

I tried it, there is some different, but the problem still exists.

![%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20191127165446](https://discourse.vtk.org/uploads/default/original/2X/8/8b120b1a757ab54b54f25c424d924759acce72a2.png)

---

<div class="post-metadata">

### Author: ![lainegates](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lainegates/32/1349_2.png) [@lainegates](https://discourse.vtk.org/u/lainegates)
#### Post date: [November 27, 2019, 9:38am UTC](https://discourse.vtk.org/t/vtk-blend-color-in-wierd-way-with-vtkassembly/2149/4 "2019-11-27T09:38:49Z")

</div>

I switch from vtk 8.1.2 to 8.2.0  
With 8.1.2, the problem doesn’t appear.
