<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">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 <tt>polydata</tt><tt>->GetCellData()->SetScalars(cellData);</tt><br>
I thought that I could set the GLSL attribute variable using
scalars or "data array".<br>
<tt>vtkFloatArray *next_point = vtkFloatArray::New();</tt><tt><br>
</tt><tt>next_point->SetName("next_point");</tt><tt><br>
</tt><tt>next_point->SetNumberOfComponents(3);</tt><tt><br>
</tt><tt>next_point->Resize(nb_points);</tt><tt><br>
</tt><tt>// Fill next_point on a loop ...</tt><tt><br>
</tt><tt>polydata->GetPointData()->AddArray(next_point); //
Or other variations, SetScalars(), GetCellData(), etc.</tt><br>
<br>
Of course it did nothing. I then learned about vtkAssignAttribute.
I tried<br>
<tt>aa->Assign("next_point", vtkDataSetAttributes::SCALARS,
vtkAssignAttribute::POINT_DATA);</tt><br>
and tested other parameters. Again, I never saw any change in the
color. As if nothing I tried was linked to GLSL attribute.<br>
<br>
Moreover, I posted this question to
<a class="moz-txt-link-freetext" href="http://stackoverflow.com/questions/23898917/vtk6-1-shaders-in-attribute-variable">http://stackoverflow.com/questions/23898917/vtk6-1-shaders-in-attribute-variable</a>.
Feel free to answer there if you are addicted to internet points
:) Again, thanks for your time.<br>
<br>
Le 2014-05-26 17:08, Nil Goyette a écrit :<br>
</div>
<blockquote cite="mid:5383AD35.2080800@imeka.ca" type="cite">
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
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:<br>
<tt>shader->SetSourceCode(R"VertexShader(</tt><tt><br>
</tt><tt> #version 120</tt><tt><br>
</tt><tt> attribute vec3 next_point;</tt><tt><br>
</tt><tt> varying vec3 vColor;</tt><tt><br>
</tt><tt><br>
</tt><tt> void main() {</tt><tt><br>
</tt><tt> float r = gl_Vertex.x - </tt><tt>next_point.</tt><tt><tt>x</tt>;</tt><tt><br>
</tt><tt> float g = gl_Vertex.y - </tt><tt>next_point.</tt><tt><tt>y</tt>;</tt><tt><br>
</tt><tt> float b = gl_Vertex.z - </tt><tt>next_point.</tt><tt><tt>z</tt>;</tt><tt><br>
</tt><tt><br>
</tt><tt> if (r < 0.0) { r *= -1.0; }</tt><tt><br>
</tt><tt> if (g < 0.0) { g *= -1.0; }</tt><tt><br>
</tt><tt> if (b < 0.0) { b *= -1.0; }</tt><tt><br>
</tt><tt><br>
</tt><tt> const float norm = 1.0 / sqrt(r*r + g*g + b*b);</tt><tt><br>
</tt><tt> vColor = vec3(r * norm, g * norm, b * norm);</tt><tt><br>
</tt><tt><br>
</tt><tt> gl_Position = ftransform();</tt><tt><br>
</tt><tt> }</tt><tt><br>
</tt><tt>)VertexShader");</tt><br>
<br>
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 "<tt>next_point</tt>". I'm pretty sure
it's always filled with 0.0 because the output image is red, blue
and green on the sides.<br>
<br>
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.<br>
<tt>fibersActor->GetProperty()->AddShaderVariable("next_x",
nb_points, </tt><tt><tt>next_x</tt>); // Splitted in 3 because
I'm not </tt><tt><br>
</tt><tt>fibersActor->GetProperty()->AddShaderVariable("</tt><tt><tt>next_y</tt>",
nb_points, </tt><tt><tt>next_y</tt>); // </tt><tt><tt>sure how
to pass</tt></tt><tt> </tt><tt>a vtkPoints<br>
</tt><tt>fibersActor->GetProperty()->AddShaderVariable("</tt><tt><tt>next_z</tt>",
nb_points, </tt><tt><tt>next_z</tt>); //</tt><tt> object to </tt><tt>AddShaderVariable</tt><br>
<br>
<b>tl;dr</b> Can you please tell me how to pass the content of a
vtkPoints into a GLSL attribute variable? Thanks for your time.<br>
</blockquote>
<br>
<div class="moz-signature">-- <br>
<table cellpadding="2" cellspacing="2" width="218" border="0"
height="96">
<tbody>
<tr>
<td valign="middle"> <a href="http://imeka.ca/"> <img
alt="Logo Imeka"
src="cid:part1.03080608.09020502@imeka.ca" width="66"
height="67"> </a> </td>
<td valign="top"> Nil Goyette, M.Sc.<br>
Programmer<br>
<a href="http://imeka.ca/">www.imeka.ca</a><br>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>