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

**URL:** https://discourse.vtk.org/t/is-it-possible-to-set-the-different-color-for-front-back-face-of-a-cell/10947
**Category:** Support
**Created:** [March 12, 2023, 3:54pm UTC](https://discourse.vtk.org/t/is-it-possible-to-set-the-different-color-for-front-back-face-of-a-cell/10947 "2023-03-12T15:54:23Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![AlexLuya](https://discourse.vtk.org/user_avatar/discourse.vtk.org/alexluya/32/4036_2.png) [@AlexLuya](https://discourse.vtk.org/u/AlexLuya)
#### Post date: [March 12, 2023, 3:54pm UTC](https://discourse.vtk.org/t/is-it-possible-to-set-the-different-color-for-front-back-face-of-a-cell/10947/1 "2023-03-12T15:54:23Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [March 13, 2023, 1:50pm UTC](https://discourse.vtk.org/t/is-it-possible-to-set-the-different-color-for-front-back-face-of-a-cell/10947/2 "2023-03-13T13:50:48Z")

</div>

Hello,

You can write a custom fragment shader:

```cpp
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](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](https://vtk.org/Wiki/Shaders_In_VTK) .

best,

PC

---

<div class="post-metadata">

### Author: ![LucasGandel](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lucasgandel/32/1831_2.png) [@LucasGandel](https://discourse.vtk.org/u/LucasGandel)
#### Post date: [March 15, 2023, 4:01pm UTC](https://discourse.vtk.org/t/is-it-possible-to-set-the-different-color-for-front-back-face-of-a-cell/10947/3 "2023-03-15T16:01:02Z")

</div>

The backface property can be specified using [vtkActor::SetBackfaceProperty](https://vtk.org/doc/nightly/html/classvtkActor.html#a67e6053de538c91fd20a496b24172dbd).

---

<div class="post-metadata">

### Author: ![AlexLuya](https://discourse.vtk.org/user_avatar/discourse.vtk.org/alexluya/32/4036_2.png) [@AlexLuya](https://discourse.vtk.org/u/AlexLuya)
#### Post date: [March 16, 2023, 2:41pm UTC](https://discourse.vtk.org/t/is-it-possible-to-set-the-different-color-for-front-back-face-of-a-cell/10947/4 "2023-03-16T14:41:59Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [March 16, 2023, 2:52pm UTC](https://discourse.vtk.org/t/is-it-possible-to-set-the-different-color-for-front-back-face-of-a-cell/10947/5 "2023-03-16T14:52:35Z")

</div>

Hello,

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

regards,

PC

---

<div class="post-metadata">

### Author: ![LucasGandel](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lucasgandel/32/1831_2.png) [@LucasGandel](https://discourse.vtk.org/u/LucasGandel)
#### Post date: [March 16, 2023, 4:29pm UTC](https://discourse.vtk.org/t/is-it-possible-to-set-the-different-color-for-front-back-face-of-a-cell/10947/6 "2023-03-16T16:29:17Z")

</div>

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
