<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body text="#000000" bgcolor="#FFFFFF">
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>
<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.07090905.07080308@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>