[vtkusers] Shader input attribute

Nil Goyette nil.goyette at imeka.ca
Wed May 28 09:53:27 EDT 2014


Hi. Just an update to tell you that I tried something else while waiting 
for an answer. Seeing that one can set the color of each cell by using 
polydata->GetCellData()->SetScalars(cellData);
I thought that I could set the GLSL attribute variable using scalars or 
"data array".
vtkFloatArray *next_point = vtkFloatArray::New();
next_point->SetName("next_point");
next_point->SetNumberOfComponents(3);
next_point->Resize(nb_points);
// Fill next_point on a loop ...
polydata->GetPointData()->AddArray(next_point); // Or other variations, 
SetScalars(), GetCellData(), etc.

Of course it did nothing. I then learned about vtkAssignAttribute. I tried
aa->Assign("next_point", vtkDataSetAttributes::SCALARS, 
vtkAssignAttribute::POINT_DATA);
and tested other parameters. Again, I never saw any change in the color. 
As if nothing I tried was linked to GLSL attribute.

Moreover, I posted this question to 
http://stackoverflow.com/questions/23898917/vtk6-1-shaders-in-attribute-variable. 
Feel free to answer there if you are addicted to internet points :) 
Again, thanks for your time.

Le 2014-05-26 17:08, Nil Goyette a écrit :
> Hi all, I have been seaching in the last hours how to fill an 
> "attribute" variable in GLSL. There's a test TestGLSL.cxx that shows 
> how to use a vertex and fragment shader, but they don't use any input 
> variable. My vertex shader is:
> shader->SetSourceCode(R"VertexShader(
>     #version 120
>     attribute vec3 next_point;
>     varying vec3 vColor;
>
>     void main() {
>         float r = gl_Vertex.x - next_point.x;
>         float g = gl_Vertex.y - next_point.y;
>         float b = gl_Vertex.z - next_point.z;
>
>         if (r < 0.0) { r *= -1.0; }
>         if (g < 0.0) { g *= -1.0; }
>         if (b < 0.0) { b *= -1.0; }
>
>         const float norm = 1.0 / sqrt(r*r + g*g + b*b);
>         vColor = vec3(r * norm, g * norm, b * norm);
>
>         gl_Position = ftransform();
>     }
> )VertexShader");
>
> The goal here is, for each point, get the vector to the next point to 
> calculate the color of the line between them. I can't find a way to 
> set the value of "next_point". I'm pretty sure it's always filled with 
> 0.0 because the output image is red, blue and green on the sides.
>
> I tried using vtkProperty::AddShaderVariable() but I never saw any 
> change and the method's documentation hints about a "uniform variable" 
> so it's probably not the right way.
> fibersActor->GetProperty()->AddShaderVariable("next_x", nb_points, 
> next_x); // Splitted in 3 because I'm not
> fibersActor->GetProperty()->AddShaderVariable("next_y", nb_points, 
> next_y); // sure how to passa vtkPoints
> fibersActor->GetProperty()->AddShaderVariable("next_z", nb_points, 
> next_z); //object to AddShaderVariable
>
> *tl;dr* Can you please tell me how to pass the content of a vtkPoints 
> into a GLSL attribute variable? Thanks for your time.

-- 
Logo Imeka <http://imeka.ca/> 	Nil Goyette, M.Sc.
Programmer
www.imeka.ca <http://imeka.ca/>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140528/64fe5110/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Imeka.png
Type: image/png
Size: 6630 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140528/64fe5110/attachment.png>


More information about the vtkusers mailing list