GLSL Shader on a vtkActor (VTK 6.1 and Qt 5.2.1)

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

GLSL Shader on a vtkActor (VTK 6.1 and Qt 5.2.1)

carlinhos
Hi all,

I'm using Vtk 6.1.0 and Qt 5.2.1 (C++) to develop my app.

I have an assembly with different actors into a vtkRenderWindow.

I load a shader with the class vtkShader2, and create the program with vtkShaderProgram2, all ok with this. After that, i wanted to attach the shader to the actors (i'm going to use different shaders, depending on the actors). The problem is i didn't find examples or documentation to do this and i'm not capable to use the classes for the shaders correctly.

I searched into the class vtkOpenGLProperty to set the vtkShaderProgram2 with the method "SetPropProgram" and i set the property of the actors with that one, but vtk shows me a warning window with a conflict between the default shaders and mine (total 4 shaders, 2 vertex and 2 fragment).

Can someone help me? Thanks in advance!!
Reply | Threaded
Open this post in threaded view
|

Re: GLSL Shader on a vtkActor (VTK 6.1 and Qt 5.2.1)

Aashish Chaudhary-2
vtkOpenGLProperty::SetPropProgram is the right function but you have load your shaders manually now. I believe the error you are getting is because it is still trying to use the last shader code. 
- Aashish


On Tue, Jul 8, 2014 at 3:15 AM, carlinhos <[hidden email]> wrote:
Hi all,

I'm using Vtk 6.1.0 and Qt 5.2.1 (C++) to develop my app.

I have an assembly with different actors into a vtkRenderWindow.

I load a shader with the class vtkShader2, and create the program with
vtkShaderProgram2, all ok with this. After that, i wanted to attach the
shader to the actors (i'm going to use different shaders, depending on the
actors). The problem is i didn't find examples or documentation to do this
and i'm not capable to use the classes for the shaders correctly.

I searched into the class vtkOpenGLProperty to set the vtkShaderProgram2
with the method "SetPropProgram" and i set the property of the actors with
that one, but vtk shows me a warning window with a conflict between the
default shaders and mine (total 4 shaders, 2 vertex and 2 fragment).

Can someone help me? Thanks in advance!!



--
View this message in context: http://vtk.1045678.n5.nabble.com/GLSL-Shader-on-a-vtkActor-VTK-6-1-and-Qt-5-2-1-tp5727788.html
Sent from the VTK - Dev mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtk-developers




--
| Aashish Chaudhary
| Technical Leader         
| Kitware Inc.           

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtk-developers

Reply | Threaded
Open this post in threaded view
|

Re: GLSL Shader on a vtkActor (VTK 6.1 and Qt 5.2.1)

carlinhos
Thanks for your answer, i thought it wasn't the right way! 

What do you mean when you say i have to load the shaders manually? The steps i'm doing are:

1- Create a vtkShaderProgram2
2- Create the vtkShader2 (VertexShader) and load it from the file with SetSourceCode.
3- Add my VertexShader to the vtkShaderProgram2 with "GetShaders()->AddItem()".
4- Repeat 2 and 3 with the FragmentShader.
5- Build the vtkShaderProgram and check the Build Status (to check if everything is ok).
6- Create a vtkActor and obtain his property(with GetProperty()).
7- Put ShadingOn to the property and SetPropProgram with the vtkShaderProgram2 build before (The vtkShaderProgram on debug has only the 2 shaders I put in).

When the actors are going to display into the screen, the warning window shows up and tells me that the main is defined twice (and shows me the Default shaders and mine).

Thanks again!!


2014-07-08 18:25 GMT+02:00 Aashish Chaudhary <[hidden email]>:
vtkOpenGLProperty::SetPropProgram is the right function but you have load your shaders manually now. I believe the error you are getting is because it is still trying to use the last shader code. 
- Aashish


On Tue, Jul 8, 2014 at 3:15 AM, carlinhos <[hidden email]> wrote:
Hi all,

I'm using Vtk 6.1.0 and Qt 5.2.1 (C++) to develop my app.

I have an assembly with different actors into a vtkRenderWindow.

I load a shader with the class vtkShader2, and create the program with
vtkShaderProgram2, all ok with this. After that, i wanted to attach the
shader to the actors (i'm going to use different shaders, depending on the
actors). The problem is i didn't find examples or documentation to do this
and i'm not capable to use the classes for the shaders correctly.

I searched into the class vtkOpenGLProperty to set the vtkShaderProgram2
with the method "SetPropProgram" and i set the property of the actors with
that one, but vtk shows me a warning window with a conflict between the
default shaders and mine (total 4 shaders, 2 vertex and 2 fragment).

Can someone help me? Thanks in advance!!



--
View this message in context: http://vtk.1045678.n5.nabble.com/GLSL-Shader-on-a-vtkActor-VTK-6-1-and-Qt-5-2-1-tp5727788.html
Sent from the VTK - Dev mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtk-developers




--
| Aashish Chaudhary
| Technical Leader         
| Kitware Inc.           


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtk-developers

Reply | Threaded
Open this post in threaded view
|

Re: GLSL Shader on a vtkActor (VTK 6.1 and Qt 5.2.1)

Aashish Chaudhary-2
I can reply in detail layer but on this note, you may want to use the new VTK rendering code for it. Marcus or Ken hopefully reply to you on that.

- Aashish


On Tue, Jul 8, 2014 at 2:14 PM, Carlos Martinez <[hidden email]> wrote:
Thanks for your answer, i thought it wasn't the right way! 

What do you mean when you say i have to load the shaders manually? The steps i'm doing are:

1- Create a vtkShaderProgram2
2- Create the vtkShader2 (VertexShader) and load it from the file with SetSourceCode.
3- Add my VertexShader to the vtkShaderProgram2 with "GetShaders()->AddItem()".
4- Repeat 2 and 3 with the FragmentShader.
5- Build the vtkShaderProgram and check the Build Status (to check if everything is ok).
6- Create a vtkActor and obtain his property(with GetProperty()).
7- Put ShadingOn to the property and SetPropProgram with the vtkShaderProgram2 build before (The vtkShaderProgram on debug has only the 2 shaders I put in).

When the actors are going to display into the screen, the warning window shows up and tells me that the main is defined twice (and shows me the Default shaders and mine).

Thanks again!!


2014-07-08 18:25 GMT+02:00 Aashish Chaudhary <[hidden email]>:

vtkOpenGLProperty::SetPropProgram is the right function but you have load your shaders manually now. I believe the error you are getting is because it is still trying to use the last shader code. 
- Aashish


On Tue, Jul 8, 2014 at 3:15 AM, carlinhos <[hidden email]> wrote:
Hi all,

I'm using Vtk 6.1.0 and Qt 5.2.1 (C++) to develop my app.

I have an assembly with different actors into a vtkRenderWindow.

I load a shader with the class vtkShader2, and create the program with
vtkShaderProgram2, all ok with this. After that, i wanted to attach the
shader to the actors (i'm going to use different shaders, depending on the
actors). The problem is i didn't find examples or documentation to do this
and i'm not capable to use the classes for the shaders correctly.

I searched into the class vtkOpenGLProperty to set the vtkShaderProgram2
with the method "SetPropProgram" and i set the property of the actors with
that one, but vtk shows me a warning window with a conflict between the
default shaders and mine (total 4 shaders, 2 vertex and 2 fragment).

Can someone help me? Thanks in advance!!



--
View this message in context: http://vtk.1045678.n5.nabble.com/GLSL-Shader-on-a-vtkActor-VTK-6-1-and-Qt-5-2-1-tp5727788.html
Sent from the VTK - Dev mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtk-developers




--
| Aashish Chaudhary
| Technical Leader         
| Kitware Inc.           




--
| Aashish Chaudhary
| Technical Leader         
| Kitware Inc.           

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtk-developers

Reply | Threaded
Open this post in threaded view
|

Re: GLSL Shader on a vtkActor (VTK 6.1 and Qt 5.2.1)

Marcus D. Hanwell-2
I don't think that would be useful at this time - whilst the new
rendering code is shader based we have not yet started to add
functionality to add your own or modify our shader code.

On Tue, Jul 8, 2014 at 3:07 PM, Aashish Chaudhary
<[hidden email]> wrote:

> I can reply in detail layer but on this note, you may want to use the new
> VTK rendering code for it. Marcus or Ken hopefully reply to you on that.
>
> - Aashish
>
>
> On Tue, Jul 8, 2014 at 2:14 PM, Carlos Martinez <[hidden email]>
> wrote:
>>
>> Thanks for your answer, i thought it wasn't the right way!
>>
>> What do you mean when you say i have to load the shaders manually? The
>> steps i'm doing are:
>>
>> 1- Create a vtkShaderProgram2
>> 2- Create the vtkShader2 (VertexShader) and load it from the file with
>> SetSourceCode.
>> 3- Add my VertexShader to the vtkShaderProgram2 with
>> "GetShaders()->AddItem()".
>> 4- Repeat 2 and 3 with the FragmentShader.
>> 5- Build the vtkShaderProgram and check the Build Status (to check if
>> everything is ok).
>> 6- Create a vtkActor and obtain his property(with GetProperty()).
>> 7- Put ShadingOn to the property and SetPropProgram with the
>> vtkShaderProgram2 build before (The vtkShaderProgram on debug has only the 2
>> shaders I put in).
>>
>> When the actors are going to display into the screen, the warning window
>> shows up and tells me that the main is defined twice (and shows me the
>> Default shaders and mine).
>>
>> Thanks again!!
>>
>>
>> 2014-07-08 18:25 GMT+02:00 Aashish Chaudhary
>> <[hidden email]>:
>>
>>> vtkOpenGLProperty::SetPropProgram is the right function but you have load
>>> your shaders manually now. I believe the error you are getting is because it
>>> is still trying to use the last shader code.
>>>
>>> - Aashish
>>>
>>>
>>>
>>> On Tue, Jul 8, 2014 at 3:15 AM, carlinhos <[hidden email]>
>>> wrote:
>>>>
>>>> Hi all,
>>>>
>>>> I'm using Vtk 6.1.0 and Qt 5.2.1 (C++) to develop my app.
>>>>
>>>> I have an assembly with different actors into a vtkRenderWindow.
>>>>
>>>> I load a shader with the class vtkShader2, and create the program with
>>>> vtkShaderProgram2, all ok with this. After that, i wanted to attach the
>>>> shader to the actors (i'm going to use different shaders, depending on
>>>> the
>>>> actors). The problem is i didn't find examples or documentation to do
>>>> this
>>>> and i'm not capable to use the classes for the shaders correctly.
>>>>
>>>> I searched into the class vtkOpenGLProperty to set the vtkShaderProgram2
>>>> with the method "SetPropProgram" and i set the property of the actors
>>>> with
>>>> that one, but vtk shows me a warning window with a conflict between the
>>>> default shaders and mine (total 4 shaders, 2 vertex and 2 fragment).
>>>>
>>>> Can someone help me? Thanks in advance!!
>>>>
>>>>
>>>>
>>>> --
>>>> View this message in context:
>>>> http://vtk.1045678.n5.nabble.com/GLSL-Shader-on-a-vtkActor-VTK-6-1-and-Qt-5-2-1-tp5727788.html
>>>> Sent from the VTK - Dev mailing list archive at Nabble.com.
>>>> _______________________________________________
>>>> Powered by www.kitware.com
>>>>
>>>> Visit other Kitware open-source projects at
>>>> http://www.kitware.com/opensource/opensource.html
>>>>
>>>> Follow this link to subscribe/unsubscribe:
>>>> http://public.kitware.com/mailman/listinfo/vtk-developers
>>>>
>>>
>>>
>>>
>>> --
>>> | Aashish Chaudhary
>>> | Technical Leader
>>> | Kitware Inc.
>>> | http://www.kitware.com/company/team/chaudhary.html
>>
>>
>
>
>
> --
> | Aashish Chaudhary
> | Technical Leader
> | Kitware Inc.
> | http://www.kitware.com/company/team/chaudhary.html
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtk-developers
>
>
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtk-developers

Reply | Threaded
Open this post in threaded view
|

Re: GLSL Shader on a vtkActor (VTK 6.1 and Qt 5.2.1)

carlinhos
Thanks for your answer, i thought to use them to give my actors metallic visualization.

Maybe i could use textures to show actors with that kind of visualization.

Carlos.


2014-07-08 21:41 GMT+02:00 Marcus D. Hanwell-2 [via VTK] <[hidden email]>:
I don't think that would be useful at this time - whilst the new
rendering code is shader based we have not yet started to add
functionality to add your own or modify our shader code.

On Tue, Jul 8, 2014 at 3:07 PM, Aashish Chaudhary
<[hidden email]> wrote:

> I can reply in detail layer but on this note, you may want to use the new
> VTK rendering code for it. Marcus or Ken hopefully reply to you on that.
>
> - Aashish
>
>
> On Tue, Jul 8, 2014 at 2:14 PM, Carlos Martinez <[hidden email]>
> wrote:

>>
>> Thanks for your answer, i thought it wasn't the right way!
>>
>> What do you mean when you say i have to load the shaders manually? The
>> steps i'm doing are:
>>
>> 1- Create a vtkShaderProgram2
>> 2- Create the vtkShader2 (VertexShader) and load it from the file with
>> SetSourceCode.
>> 3- Add my VertexShader to the vtkShaderProgram2 with
>> "GetShaders()->AddItem()".
>> 4- Repeat 2 and 3 with the FragmentShader.
>> 5- Build the vtkShaderProgram and check the Build Status (to check if
>> everything is ok).
>> 6- Create a vtkActor and obtain his property(with GetProperty()).
>> 7- Put ShadingOn to the property and SetPropProgram with the
>> vtkShaderProgram2 build before (The vtkShaderProgram on debug has only the 2
>> shaders I put in).
>>
>> When the actors are going to display into the screen, the warning window
>> shows up and tells me that the main is defined twice (and shows me the
>> Default shaders and mine).
>>
>> Thanks again!!
>>
>>
>> 2014-07-08 18:25 GMT+02:00 Aashish Chaudhary
>> <[hidden email]>:
>>
>>> vtkOpenGLProperty::SetPropProgram is the right function but you have load
>>> your shaders manually now. I believe the error you are getting is because it
>>> is still trying to use the last shader code.
>>>
>>> - Aashish
>>>
>>>
>>>
>>> On Tue, Jul 8, 2014 at 3:15 AM, carlinhos <[hidden email]>
>>> wrote:

>>>>
>>>> Hi all,
>>>>
>>>> I'm using Vtk 6.1.0 and Qt 5.2.1 (C++) to develop my app.
>>>>
>>>> I have an assembly with different actors into a vtkRenderWindow.
>>>>
>>>> I load a shader with the class vtkShader2, and create the program with
>>>> vtkShaderProgram2, all ok with this. After that, i wanted to attach the
>>>> shader to the actors (i'm going to use different shaders, depending on
>>>> the
>>>> actors). The problem is i didn't find examples or documentation to do
>>>> this
>>>> and i'm not capable to use the classes for the shaders correctly.
>>>>
>>>> I searched into the class vtkOpenGLProperty to set the vtkShaderProgram2
>>>> with the method "SetPropProgram" and i set the property of the actors
>>>> with
>>>> that one, but vtk shows me a warning window with a conflict between the
>>>> default shaders and mine (total 4 shaders, 2 vertex and 2 fragment).
>>>>
>>>> Can someone help me? Thanks in advance!!
>>>>
>>>>
>>>>
>>>> --
>>>> View this message in context:
>>>> http://vtk.1045678.n5.nabble.com/GLSL-Shader-on-a-vtkActor-VTK-6-1-and-Qt-5-2-1-tp5727788.html
>>>> Sent from the VTK - Dev mailing list archive at Nabble.com.

>>>> _______________________________________________
>>>> Powered by www.kitware.com
>>>>
>>>> Visit other Kitware open-source projects at
>>>> http://www.kitware.com/opensource/opensource.html
>>>>
>>>> Follow this link to subscribe/unsubscribe:
>>>> http://public.kitware.com/mailman/listinfo/vtk-developers
>>>>
>>>
>>>
>>>
>>> --
>>> | Aashish Chaudhary
>>> | Technical Leader
>>> | Kitware Inc.
>>> | http://www.kitware.com/company/team/chaudhary.html
>>
>>
>
>
>
> --
> | Aashish Chaudhary
> | Technical Leader
> | Kitware Inc.
> | http://www.kitware.com/company/team/chaudhary.html
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtk-developers
>
>
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtk-developers




If you reply to this email, your message will be added to the discussion below:
http://vtk.1045678.n5.nabble.com/GLSL-Shader-on-a-vtkActor-VTK-6-1-and-Qt-5-2-1-tp5727788p5727800.html
To unsubscribe from GLSL Shader on a vtkActor (VTK 6.1 and Qt 5.2.1), click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: GLSL Shader on a vtkActor (VTK 6.1 and Qt 5.2.1)

xiaoming
This post has NOT been accepted by the mailing list yet.
In reply to this post by carlinhos
i'm sorry but i see that vtkActor::GetProperty() returns a pointer to the vtkProperty not vtkOpenGLProperty,which has a member of SetPropProgram,i 'm just confused with the 7th step,would you bother to tell me sth about that ,thanks in advance.
Quote:
<  7- Put ShadingOn to the property and SetPropProgram with the
vtkShaderProgram2 build before (The vtkShaderProgram on debug has only the
2 shaders I put in).>

Reply | Threaded
Open this post in threaded view
|

Re: GLSL Shader on a vtkActor (VTK 6.1 and Qt 5.2.1)

carlinhos
Hello Xiaoming,

I created a new vtkOpenGLProperty and set it to the actor, anyways i tried to cast the vtkProperty obtained by the a vtkActor::GetProperty(), because vtkProperty is an abstract class. I tried so many things to make it work but i didn't manage to do it. Also i tried to use vtkOpenGLActors instead of vtkActors but it also didn't work.

Carlos.


2014-07-18 9:46 GMT+02:00 xiaoming [via VTK] <[hidden email]>:
i'm sorry but i see that vtkActor::GetProperty() returns a pointer to the vtkProperty not vtkOpenGLProperty,which has a member of SetPropProgram,i 'm just confused with the 7th step,would you bother to tell me sth about that ,thanks in advance.
Quote:
<  7- Put ShadingOn to the property and SetPropProgram with the
vtkShaderProgram2 build before (The vtkShaderProgram on debug has only the
2 shaders I put in).>




If you reply to this email, your message will be added to the discussion below:
http://vtk.1045678.n5.nabble.com/GLSL-Shader-on-a-vtkActor-VTK-6-1-and-Qt-5-2-1-tp5727788p5727903.html
To unsubscribe from GLSL Shader on a vtkActor (VTK 6.1 and Qt 5.2.1), click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: GLSL Shader on a vtkActor (VTK 6.1 and Qt 5.2.1)

Joachim Pouderoux
Actually it seems like there is a bug in vtkOpenGLProperty.cxx that I might have fixed. I will make a patch soon.
In the meanwhile try to change those lines:

        needDefaultMainVS = !progHasVertex
          && propProg->HasVertexShaders();
        needDefaultMainFS = !progHasFragment
          && propProg->HasFragmentShaders();
by
        needDefaultMainVS = !progHasVertex
          && !propProg->HasVertexShaders();
        needDefaultMainFS = !progHasFragment
          && !propProg->HasFragmentShaders();
With that fixed, the steps you defined should now work as no second main() will be added to both shader code.

Joachim

Joachim Pouderoux
PhD, Technical Expert
Kitware SAS


2014-07-18 11:03 GMT+02:00 carlinhos <[hidden email]>:
Hello Xiaoming,

I created a new vtkOpenGLProperty and set it to the actor, anyways i tried to cast the vtkProperty obtained by the a vtkActor::GetProperty(), because vtkProperty is an abstract class. I tried so many things to make it work but i didn't manage to do it. Also i tried to use vtkOpenGLActors instead of vtkActors but it also didn't work.

Carlos.


2014-07-18 9:46 GMT+02:00 xiaoming [via VTK] <[hidden email]>:
i'm sorry but i see that vtkActor::GetProperty() returns a pointer to the vtkProperty not vtkOpenGLProperty,which has a member of SetPropProgram,i 'm just confused with the 7th step,would you bother to tell me sth about that ,thanks in advance.
Quote:
<  7- Put ShadingOn to the property and SetPropProgram with the
vtkShaderProgram2 build before (The vtkShaderProgram on debug has only the
2 shaders I put in).>




If you reply to this email, your message will be added to the discussion below:
http://vtk.1045678.n5.nabble.com/GLSL-Shader-on-a-vtkActor-VTK-6-1-and-Qt-5-2-1-tp5727788p5727903.html
To unsubscribe from GLSL Shader on a vtkActor (VTK 6.1 and Qt 5.2.1), click here.
NAML

Sent from the VTK - Dev mailing list archive at Nabble.com.

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtk-developers




_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtk-developers

Reply | Threaded
Open this post in threaded view
|

Re: GLSL Shader on a vtkActor (VTK 6.1 and Qt 5.2.1)

Joachim Pouderoux
Carlos

Ok actually I was wrong. My patch works but it is not how this is supposed to happen.
Basically, VTK will merge 2 different shader source code to define each type of shader (vertex, fragment etc.).
A first source will come from the shader code that can be attached to the renderer shaders.
If it not exist, the default is a main function that will call propFuncVS()/propFuncFS() etc - depending the shader type.
The second source will come from the shader code that can be attached to the actor's property.
If it not exist, the default behaviour is to define that propFuncVS/FS functions.
Both source codes will be appended before being compiled by the openGlProperty.

So basically if you do not define a renderer shader program, you simply have to provide a shader codes to your property that defines propFuncVS/FS functions instead of usual main() functions.
Also do not build your shader program (program->Build()) in your code as it will fail because the main() functions are not provided. Remember they will be added later automatically before compilation by OpenGLProperty.

Hope it is clear and it helps!

Best,



Joachim Pouderoux
PhD, Technical Expert
Kitware SAS


2014-07-29 14:55 GMT+02:00 Joachim Pouderoux <[hidden email]>:
Actually it seems like there is a bug in vtkOpenGLProperty.cxx that I might have fixed. I will make a patch soon.
In the meanwhile try to change those lines:

        needDefaultMainVS = !progHasVertex
          && propProg->HasVertexShaders();
        needDefaultMainFS = !progHasFragment
          && propProg->HasFragmentShaders();
by
        needDefaultMainVS = !progHasVertex
          && !propProg->HasVertexShaders();
        needDefaultMainFS = !progHasFragment
          && !propProg->HasFragmentShaders();
With that fixed, the steps you defined should now work as no second main() will be added to both shader code.

Joachim

Joachim Pouderoux
PhD, Technical Expert
Kitware SAS


2014-07-18 11:03 GMT+02:00 carlinhos <[hidden email]>:
Hello Xiaoming,

I created a new vtkOpenGLProperty and set it to the actor, anyways i tried to cast the vtkProperty obtained by the a vtkActor::GetProperty(), because vtkProperty is an abstract class. I tried so many things to make it work but i didn't manage to do it. Also i tried to use vtkOpenGLActors instead of vtkActors but it also didn't work.

Carlos.


2014-07-18 9:46 GMT+02:00 xiaoming [via VTK] <[hidden email]>:
i'm sorry but i see that vtkActor::GetProperty() returns a pointer to the vtkProperty not vtkOpenGLProperty,which has a member of SetPropProgram,i 'm just confused with the 7th step,would you bother to tell me sth about that ,thanks in advance.
Quote:
<  7- Put ShadingOn to the property and SetPropProgram with the
vtkShaderProgram2 build before (The vtkShaderProgram on debug has only the
2 shaders I put in).>




If you reply to this email, your message will be added to the discussion below:
http://vtk.1045678.n5.nabble.com/GLSL-Shader-on-a-vtkActor-VTK-6-1-and-Qt-5-2-1-tp5727788p5727903.html
To unsubscribe from GLSL Shader on a vtkActor (VTK 6.1 and Qt 5.2.1), click here.
NAML

Sent from the VTK - Dev mailing list archive at Nabble.com.

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtk-developers





_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtk-developers

Reply | Threaded
Open this post in threaded view
|

Re: GLSL Shader on a vtkActor (VTK 6.1 and Qt 5.2.1)

carlinhos
Joachim,

Thank you so much for the explanation, I tried something similar but building the shaders instead of not doing it (if I remember well). 
Tomorrow i will try it and I will tell you the results!! 

Carlos.




2014-07-29 15:14 GMT+02:00 Joachim Pouderoux [via VTK] <[hidden email]>:
Carlos

Ok actually I was wrong. My patch works but it is not how this is supposed to happen.
Basically, VTK will merge 2 different shader source code to define each type of shader (vertex, fragment etc.).
A first source will come from the shader code that can be attached to the renderer shaders.
If it not exist, the default is a main function that will call propFuncVS()/propFuncFS() etc - depending the shader type.
The second source will come from the shader code that can be attached to the actor's property.
If it not exist, the default behaviour is to define that propFuncVS/FS functions.
Both source codes will be appended before being compiled by the openGlProperty.

So basically if you do not define a renderer shader program, you simply have to provide a shader codes to your property that defines propFuncVS/FS functions instead of usual main() functions.
Also do not build your shader program (program->Build()) in your code as it will fail because the main() functions are not provided. Remember they will be added later automatically before compilation by OpenGLProperty.

Hope it is clear and it helps!

Best,



Joachim Pouderoux
PhD, Technical Expert
Kitware SAS


2014-07-29 14:55 GMT+02:00 Joachim Pouderoux <[hidden email]>:
Actually it seems like there is a bug in vtkOpenGLProperty.cxx that I might have fixed. I will make a patch soon.
In the meanwhile try to change those lines:

        needDefaultMainVS = !progHasVertex
          && propProg->HasVertexShaders();
        needDefaultMainFS = !progHasFragment
          && propProg->HasFragmentShaders();
by
        needDefaultMainVS = !progHasVertex
          && !propProg->HasVertexShaders();
        needDefaultMainFS = !progHasFragment
          && !propProg->HasFragmentShaders();
With that fixed, the steps you defined should now work as no second main() will be added to both shader code.

Joachim

Joachim Pouderoux
PhD, Technical Expert
Kitware SAS


2014-07-18 11:03 GMT+02:00 carlinhos <[hidden email]>:

Hello Xiaoming,

I created a new vtkOpenGLProperty and set it to the actor, anyways i tried to cast the vtkProperty obtained by the a vtkActor::GetProperty(), because vtkProperty is an abstract class. I tried so many things to make it work but i didn't manage to do it. Also i tried to use vtkOpenGLActors instead of vtkActors but it also didn't work.

Carlos.


2014-07-18 9:46 GMT+02:00 xiaoming [via VTK] <[hidden email]>:
i'm sorry but i see that vtkActor::GetProperty() returns a pointer to the vtkProperty not vtkOpenGLProperty,which has a member of SetPropProgram,i 'm just confused with the 7th step,would you bother to tell me sth about that ,thanks in advance.
Quote:
<  7- Put ShadingOn to the property and SetPropProgram with the
vtkShaderProgram2 build before (The vtkShaderProgram on debug has only the
2 shaders I put in).>




If you reply to this email, your message will be added to the discussion below:
http://vtk.1045678.n5.nabble.com/GLSL-Shader-on-a-vtkActor-VTK-6-1-and-Qt-5-2-1-tp5727788p5727903.html
To unsubscribe from GLSL Shader on a vtkActor (VTK 6.1 and Qt 5.2.1), click here.
NAML

Sent from the VTK - Dev mailing list archive at Nabble.com.

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtk-developers





_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtk-developers




If you reply to this email, your message will be added to the discussion below:
http://vtk.1045678.n5.nabble.com/GLSL-Shader-on-a-vtkActor-VTK-6-1-and-Qt-5-2-1-tp5727788p5728004.html
To unsubscribe from GLSL Shader on a vtkActor (VTK 6.1 and Qt 5.2.1), click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: GLSL Shader on a vtkActor (VTK 6.1 and Qt 5.2.1)

carlinhos
In reply to this post by Joachim Pouderoux
Hello Joachim!

I did it, it was the right way to do it :). Thank you so much for your explanation. 

I resume the steps for everyone:

0- Create a shader file with the function propFuncFS(Fragment shader) or propFuncVS(Vertex shader).
1- Load the shader from disk.
2- Create a vtkShader2 and set the source code.
3- Create a vtkShaderProgram2 and initialize it (DO NOT BUILD THE PROGRAM).
4- Add the shader to the program.
5- Obtain the actor vtkOpenGLProperty and set the program
6- Set the shading on.



Code:

QFile fragmentFile(QStringLiteral("C:/myfragmentshader"));
fragmentFile.open(QIODevice::ReadOnly);
auto fragmentBytes = fragmentFile.readAll();
fragmentFile.close();
QString fragmentShaderSource(fragmentBytes);
//The GLSL binded program
vtkSmartPointer<vtkShaderProgram2> program = vtkSmartPointer<vtkShaderProgram2>::New();
// Prepare the fragment shader
vtkSmartPointer<vtkShader2> shader = vtkSmartPointer<vtkShader2>::New();
shader->SetType(VTK_SHADER_TYPE_FRAGMENT);
shader->SetSourceCode(fragmentShaderSource.toStdString().c_str());
program->GetShaders()->AddItem(shader);
vtkSmartPointer<vtkOpenGLProperty> openGLproperty = static_cast<vtkOpenGLProperty*>(gemActor->GetProperty());
openGLproperty->SetPropProgram(program);
openGLproperty->ShadingOn();

Shader (simple shader to paint all fragments red): 

           #version 110
           void propFuncFS(void)
           {
                 gl_FragColor = (255,0,0,1);
           }

Thanks again and have a nice day! =)


2014-07-29 21:48 GMT+02:00 Carlos Martinez <[hidden email]>:
Joachim,

Thank you so much for the explanation, I tried something similar but building the shaders instead of not doing it (if I remember well). 
Tomorrow i will try it and I will tell you the results!! 

Carlos.




2014-07-29 15:14 GMT+02:00 Joachim Pouderoux [via VTK] <[hidden email]>:
Carlos

Ok actually I was wrong. My patch works but it is not how this is supposed to happen.
Basically, VTK will merge 2 different shader source code to define each type of shader (vertex, fragment etc.).
A first source will come from the shader code that can be attached to the renderer shaders.
If it not exist, the default is a main function that will call propFuncVS()/propFuncFS() etc - depending the shader type.
The second source will come from the shader code that can be attached to the actor's property.
If it not exist, the default behaviour is to define that propFuncVS/FS functions.
Both source codes will be appended before being compiled by the openGlProperty.

So basically if you do not define a renderer shader program, you simply have to provide a shader codes to your property that defines propFuncVS/FS functions instead of usual main() functions.
Also do not build your shader program (program->Build()) in your code as it will fail because the main() functions are not provided. Remember they will be added later automatically before compilation by OpenGLProperty.

Hope it is clear and it helps!

Best,



Joachim Pouderoux
PhD, Technical Expert
Kitware SAS


2014-07-29 14:55 GMT+02:00 Joachim Pouderoux <[hidden email]>:
Actually it seems like there is a bug in vtkOpenGLProperty.cxx that I might have fixed. I will make a patch soon.
In the meanwhile try to change those lines:

        needDefaultMainVS = !progHasVertex
          && propProg->HasVertexShaders();
        needDefaultMainFS = !progHasFragment
          && propProg->HasFragmentShaders();
by
        needDefaultMainVS = !progHasVertex
          && !propProg->HasVertexShaders();
        needDefaultMainFS = !progHasFragment
          && !propProg->HasFragmentShaders();
With that fixed, the steps you defined should now work as no second main() will be added to both shader code.

Joachim

Joachim Pouderoux
PhD, Technical Expert
Kitware SAS


2014-07-18 11:03 GMT+02:00 carlinhos <[hidden email]>:

Hello Xiaoming,

I created a new vtkOpenGLProperty and set it to the actor, anyways i tried to cast the vtkProperty obtained by the a vtkActor::GetProperty(), because vtkProperty is an abstract class. I tried so many things to make it work but i didn't manage to do it. Also i tried to use vtkOpenGLActors instead of vtkActors but it also didn't work.

Carlos.


2014-07-18 9:46 GMT+02:00 xiaoming [via VTK] <[hidden email]>:
i'm sorry but i see that vtkActor::GetProperty() returns a pointer to the vtkProperty not vtkOpenGLProperty,which has a member of SetPropProgram,i 'm just confused with the 7th step,would you bother to tell me sth about that ,thanks in advance.
Quote:
<  7- Put ShadingOn to the property and SetPropProgram with the
vtkShaderProgram2 build before (The vtkShaderProgram on debug has only the
2 shaders I put in).>




If you reply to this email, your message will be added to the discussion below:
http://vtk.1045678.n5.nabble.com/GLSL-Shader-on-a-vtkActor-VTK-6-1-and-Qt-5-2-1-tp5727788p5727903.html
To unsubscribe from GLSL Shader on a vtkActor (VTK 6.1 and Qt 5.2.1), click here.
NAML

Sent from the VTK - Dev mailing list archive at Nabble.com.

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtk-developers





_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtk-developers




If you reply to this email, your message will be added to the discussion below:
http://vtk.1045678.n5.nabble.com/GLSL-Shader-on-a-vtkActor-VTK-6-1-and-Qt-5-2-1-tp5727788p5728004.html
To unsubscribe from GLSL Shader on a vtkActor (VTK 6.1 and Qt 5.2.1), click here.
NAML