Not logged in, Join Here! or Log In Below:  
News Articles Search    

 Home / 3D Theory & Graphics / Vertex Shaders - Counting vertices Account Manager
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.

May 13, 2005, 05:13 AM

Is it possible to 'count' the vertices in a vertex shader - ie. so the shader
knows the index of each vertex so that it can perform specific operations on,
say, every other vertex ? - or to maintain a value in a register between
each vertex being processed (again, so that I can operate on every 2nd vertex? )
Ta very much....

Erik Faye-Lund

May 13, 2005, 05:15 AM

just write the index to a separate attribute-stream... ? :)


May 13, 2005, 05:28 AM

Cant do - the problem is that given a vertex buffer I am extruding it to form
a strip, along a vector, so that each vertex has a corresponding extruded vertex. By creating an index buffer where each index is duplicated eg: 0,0,1,1,2,2 then if I could detect every OTHER index then I could extrude the
original vertex in the shader, and avoid having to do this on the CPU and having a dynamic vertex buffer.

Erik Faye-Lund

May 13, 2005, 05:47 AM

you can't rely on any register to remain between vertices, no. if you're doing shadow volume extrusions, one solution is to make a twice as big vertexbuffer, and set the w-components of the vertices to be extruded to 0. then let indexing do the job.


May 13, 2005, 05:59 AM

Yeah... I'm extruding a shadow vol. I'll just duplicate the vertex buffer and,
as you suggest, use the 'w' channel to hold either 1.0 or 0.0, extrude all vertices by w * extrusion_vector... shame I got to waste so much buffer though... cheers ( still better than generating to a dynamic buffer I guess.)

This thread contains 5 messages.
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.