# How to get shader source for an actor

**URL:** https://discourse.vtk.org/t/how-to-get-shader-source-for-an-actor/8408
**Category:** Support
**Created:** [May 1, 2022, 9:24pm UTC](https://discourse.vtk.org/t/how-to-get-shader-source-for-an-actor/8408 "2022-05-01T21:24:21Z")
**Posts on this page:** 1
**Showing post:** 4

<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: [May 2, 2022, 8:54pm UTC](https://discourse.vtk.org/t/how-to-get-shader-source-for-an-actor/8408/4 "2022-05-02T20:54:35Z")

</div>

Hello, Roger,

> [@BlueKnight7](#):
>
> I don’t see Get_Source routines listed in the vtkShaderProperty class reference page, but there are several Get_ShaderCode function. Not trying to be picky, but this might make it clearer for others reading this. I will assume that you meant Get\*ShaderCode.

Fixed.

> [@BlueKnight7](#):
>
> I saw these functions before, but was uncertain as to how to handle the fact that the return type is a “virtual char \*”; that is why I was trying to work with the vtkShader function that returned a string.
> 
> Could you educate us less knowledgeable C++ programmers; how do you use a function that returns a virtual pointer? Do I just ignore the virtual part and assign it to a char \* in this case?

The `virtual` keyword only means that the function’s behavior may change depending on the object’s class. It doesn’t have to do with the returned data type, which is `char *`. Suppose the `Animal` class that has a `virtual string talk(){return "";}`. You can have a `Dog` and a `Cat` classes that extend `Animal`. These subclasses may override `Animal::talk()` to implement behavior especific to them: `virtual string Dog::talk(){ return "woof woof!";}` and `virtual string Cat::talk(){ return "meow!";}`. So if you declare an `Animal` object like this: `Animal* a = new Dog();` and if you call its `talk()` method, it’ll return “woof woof!”. Without the `virtual` keyword, it would return an empty string, since `a` belongs to the `Animal` class. The `virtual` keyword is one way in C++ to implement polymorphism, that is, variable behavior for seemingly the same thing.

`char` means a single character. `*` means that it is a pointer to the given data type. So `char *` is a variable that has the memory address to a singe character. Normally, a `char *` denotes the pointer to the first character of a string, which ends with the first of the following characters that has the null character (`\0`) or the 8-bit integer value of zero. These are the so-called "C-string"s. In practice, C++ programmers use some high level string class such as `std::string`. You can just create a `std::string` object from a `char *` by doing, for example, `std::string myString( shaderProperty->GetFragmentShaderCode() );`.

Please, take a look at some examples of shader usage here: [Any example or tips to render sea surface(shader+FFT)? - #2 by Paulo\_Carvalho](https://discourse.vtk.org/t/any-example-or-tips-to-render-sea-surface-shader-fft/7432/2) .

take care,

Paulo

---

_[View the full topic](https://discourse.vtk.org/t/how-to-get-shader-source-for-an-actor/8408)._
