Is it possible to set the different color for front/back face of a cell?

Hello,we want to use colors to represent the cell normal direction.For example,on the same cell(or ploy),we want to set one face to blue if this face has cell normal towards to camera,and set the another face to red.

How to do it?

Hello,

You can write a custom fragment shader:

if(gl_FrontFacing)
{
    outColor = color1;
}
else    // Fragment is back facing fragment
{
    outColor = color2;
}

Source: https://stackoverflow.com/questions/24903403/how-put-different-colors-at-front-and-back-sides-of-quad

Shader code in VTK is set as string properties (like SQL code in database applications) of some vtkMapper subclass. The OpenGL backend compiles it and the resulting executable runs in the GPU during rendering pipeline execution. Further reading: https://vtk.org/Wiki/Shaders_In_VTK .

best,

PC

1 Like

The backface property can be specified using vtkActor::SetBackfaceProperty.

No,this don’t set diffent color for two face.

Hello,

Maybe a call to ApplyProperties() after Lucas’ answer will do: https://vtk.org/doc/nightly/html/classvtkActor.html#a7ab05fab4845e28158c8d36154f768e1 .

regards,

PC

Hello Paulo,

Good idea, but this should not be required if the actor is not an assembly.
@AlexLuya The following (C#) example definitely sets different colors for the two faces of the plane:

vtkPlaneSource source = vtkPlaneSource.New();
vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
mapper.SetInputConnection(source.GetOutputPort());
vtkActor actor = vtkActor.New();
actor.SetMapper(mapper);
actor.GetProperty().SetColor(1, 0, 0);
vtkProperty bp = vtkProperty.New();
bp.SetColor(0, 1, 0);
actor.SetBackfaceProperty(bp);

Hope this helps,
Lucas