[vtkusers] Shader input attribute
Nil Goyette
nil.goyette at imeka.ca
Mon May 26 17:08:05 EDT 2014
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/20140526/99302659/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/20140526/99302659/attachment.png>
More information about the vtkusers
mailing list