How to draw 3D curves with linear gradient colors ?

Hello I would like to draw 3D curves(polylines) using a linear gradient pattern, is it possible with OpenCascade TKV3d toolkit ?

There is an example in the attachment of what I would like to do.

 

Attachments: 
Kirill Gavrilov's picture

Defining a polyline (Graphic3d_ArrayOfPolylines or Graphic3d_ArrayOfSegments) with per-vertex color (Graphic3d_ArrayFlags_VertexColor) should give such result.

Hugues Delorme's picture

Hello Kirill,

I have tried that and it works, the issue is that in most cases the gradient stops aren't located on the vertices of the polyline.

Assume there are 4 stops in the linear gradient and you have to draw just a 500mm segment (just 2 vertices then).

A workaround is to subdivide the segment to then create helper vertices correctly located to match the positions of the gradient stops.

Maybe a fragment shader would do it ? I never used them, do you think it would be easier ?

Kirill Gavrilov's picture

Sure, you can play with a custom GLSL program (Graphic3d_AspectLine3d::SetShaderProgram())
combined with per-vertex UV coordinates (Graphic3d_ArrayFlags_VertexTexel will be available as occTexCoord in shader or some custom attribute).
The program for lines without shading / clipping would be quite simple.

But as long as this is the only feature you would like to achieve with shader, it would be simpler to split polyline to extra stops.

Hugues Delorme's picture

Hello Kirill, thanks for your advices !

I will go ahead with splitting the polylines.

anglina21_146980's picture

This post is really helpful but I have another issue when I tried to draw 3D curves with linear gradient color it shows an error itunes sync error 54, I know its strange but I have no idea why this occurs, so if you have any idea how to remove this error please share with me.