# How to get vtkShaderProgram\* of an actor?

**URL:** https://discourse.vtk.org/t/how-to-get-vtkshaderprogram-of-an-actor/7602
**Category:** Support
**Created:** [January 8, 2022, 8:23am UTC](https://discourse.vtk.org/t/how-to-get-vtkshaderprogram-of-an-actor/7602 "2022-01-08T08:23:55Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![WailmerPail](https://discourse.vtk.org/user_avatar/discourse.vtk.org/wailmerpail/32/3356_2.png) [@WailmerPail](https://discourse.vtk.org/u/WailmerPail)
#### Post date: [January 8, 2022, 8:23am UTC](https://discourse.vtk.org/t/how-to-get-vtkshaderprogram-of-an-actor/7602/1 "2022-01-08T08:23:55Z")

</div>

Hi teams,

I have already know

```auto
void TestShaderCallback::Execute(vtkObject *, unsigned long, void *cbo){
    auto cellBO = reinterpret_cast<vtkShaderProgram*>(cbo);
    float diffuseColor[3]{1,0.2,0.6};
    cellBO->SetUniform3f("border_color_outside", diffuseColor);
}

```

is the right way to change uniform data in vtkshader,  
But how can I access it by myself?  
Because I can not find the object “cbo” belongs to which part of an actor.

I checked the source code in github for a really long time, but I could not get the result, please help me.

Thank you!

Best regards.

---

<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: [January 9, 2022, 1:26pm UTC](https://discourse.vtk.org/t/how-to-get-vtkshaderprogram-of-an-actor/7602/2 "2022-01-09T13:26:07Z")

</div>

Hello,

`vtkShaderProgram` has three methods to access its component `vtkShader` objects: `GetVertexShader()`, `GetFragmentShader()` and `GetGeometryShader()`. [https://vtk.org/doc/nightly/html/classvtkShaderProgram.html](https://vtk.org/doc/nightly/html/classvtkShaderProgram.html).

regards,

Paulo

---

<div class="post-metadata">

### Author: ![WailmerPail](https://discourse.vtk.org/user_avatar/discourse.vtk.org/wailmerpail/32/3356_2.png) [@WailmerPail](https://discourse.vtk.org/u/WailmerPail)
#### Post date: [January 9, 2022, 1:30pm UTC](https://discourse.vtk.org/t/how-to-get-vtkshaderprogram-of-an-actor/7602/4 "2022-01-09T13:30:00Z")

</div>

But I do not know how to get vtkShaderProgram object of an actor or a mapper.  
How Can I access 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: [January 9, 2022, 1:41pm UTC](https://discourse.vtk.org/t/how-to-get-vtkshaderprogram-of-an-actor/7602/5 "2022-01-09T13:41:37Z")

</div>

Do you set custom shaders in the program?

---

<div class="post-metadata">

### Author: ![WailmerPail](https://discourse.vtk.org/user_avatar/discourse.vtk.org/wailmerpail/32/3356_2.png) [@WailmerPail](https://discourse.vtk.org/u/WailmerPail)
#### Post date: [January 9, 2022, 1:44pm UTC](https://discourse.vtk.org/t/how-to-get-vtkshaderprogram-of-an-actor/7602/6 "2022-01-09T13:44:25Z")

</div>

yes, I used vtkOpenGLMapper-\>SetxxxShadercode(), but where to get the ShaderProgram?

and the ShaderProgram object belongs to which part? the mapper or the actor? or even the renderer?

---

<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: [January 9, 2022, 1:49pm UTC](https://discourse.vtk.org/t/how-to-get-vtkshaderprogram-of-an-actor/7602/7 "2022-01-09T13:49:24Z")

</div>

What class are you using? I can’t find any `vtkOpenGLMapper`.

---

<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: [January 9, 2022, 1:51pm UTC](https://discourse.vtk.org/t/how-to-get-vtkshaderprogram-of-an-actor/7602/8 "2022-01-09T13:51:02Z")

</div>

Are you using `vtkOpenGLPolyDataMapper`?

---

<div class="post-metadata">

### Author: ![WailmerPail](https://discourse.vtk.org/user_avatar/discourse.vtk.org/wailmerpail/32/3356_2.png) [@WailmerPail](https://discourse.vtk.org/u/WailmerPail)
#### Post date: [January 9, 2022, 1:54pm UTC](https://discourse.vtk.org/t/how-to-get-vtkshaderprogram-of-an-actor/7602/9 "2022-01-09T13:54:47Z")

</div>

Thank you, and sorry, it names vtkOpenGLPolyDataMapper actually.

it has the function in 9.0 version, and the function is removed in the lastest version, but the question is the same; despite the way of setting shaders is different, I can not find a easy way to get vtkProgram objects.

---

<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: [January 9, 2022, 2:07pm UTC](https://discourse.vtk.org/t/how-to-get-vtkshaderprogram-of-an-actor/7602/10 "2022-01-09T14:07:15Z")

</div>

Well, I’d add bookkeeping code to the program. Whenever you create a `vtkActor`/`vtkMapper` alongside a `vtkShader` in your scene-building code, you could add the two objects to some indexed STL container (using the `vtkShader` pointers as key). So, when you get a `vtkShader` via `GetVertexShader()`, `GetFragmentShader()` or `GetGeometryShader()` via `vtkShaderProgram` in your callback, simply query the index to find the corresponding `vtkActor`/`vtkMapper`. I know it’s dirty, but I couldn’t think of a better way to do what you want.

Edit: It’s not Python, it’s C++.

---

<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: [January 9, 2022, 2:12pm UTC](https://discourse.vtk.org/t/how-to-get-vtkshaderprogram-of-an-actor/7602/11 "2022-01-09T14:12:49Z")

</div>

Alternatively, you could subclass the `vtkShader` you are using and add setter/getter to add a pointer to whatever object you need to recover in the callback. This is a bit cleaner than bookkeeping.

---

<div class="post-metadata">

### Author: ![WailmerPail](https://discourse.vtk.org/user_avatar/discourse.vtk.org/wailmerpail/32/3356_2.png) [@WailmerPail](https://discourse.vtk.org/u/WailmerPail)
#### Post date: [January 9, 2022, 2:13pm UTC](https://discourse.vtk.org/t/how-to-get-vtkshaderprogram-of-an-actor/7602/12 "2022-01-09T14:13:32Z")

</div>

Thank you! I will try both of them

---

<div class="post-metadata">

### Author: ![ken-martin](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ken-martin/32/884_2.png) [@ken-martin](https://discourse.vtk.org/u/ken-martin)
#### Post date: [January 10, 2022, 3:21pm UTC](https://discourse.vtk.org/t/how-to-get-vtkshaderprogram-of-an-actor/7602/13 "2022-01-10T15:21:19Z")

</div>

You may also want to look at vtkShaderProperty which is on Actor. It supports all sorts of shader manipulation and is already tied to the actor and honored by the mapper. Note that OpenGLPolyDataMapper uses multiple shader programs when rendering (one for lines, another for surfaces, another for edges, and they can be changed by picking/opacity/etc so they tend to be changing based on user input (if the user has that level of control).
