What, exactly, is a vertex shader?

Started by
12 comments, last by Normie 22 years, 1 month ago
I''ve looked everywhere, and I''m either missing the obvious, or I just can''t find any info. Can someone clue me in? -Normie the Infinitely Clueless
I am a devout follower of the"Lazy Programmer's Doctrime"(tm)...and I'm damned proud of it, too!-----"I came, I saw, I started makinggames." ... If you'll excuseme, I must resume my searchfor my long lost lobotomy stitches.
Advertisement
A very quick reply (sorry, short on time...)

Check out the ripple sample in the SDK. The vertices in that sample are set to a flat plane. The ripple effect is being done by a shader that applies a sine wave to the vertices based on their distances from the center of the plane (I think it''s the center...)

A vertex shader manipulates vertices within the hardware. There are many many uses for this.
Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces", A third book on advanced lighting and materials
So, a vertex shader actually has nothing to do with shading? It just tweens the vertices in place?

Makes sense, but why is it called a shader then?

Also not sure,
Landsknecht
My sig used to be, "God was my co-pilot but we crashed in the mountains and I had to eat him..."
But folks whinned and I had to change it.
if you''re familiar with Raytracer software, just think of Vertex shader as procedural displacement maps.
No a vertex shader is an algorithm to procees 3D vertices into 2D screen space. You could use it for tweening ( I do)as well as a billion other things)

Example:

You want to have a simple water effect where the position of the x part of the vertex is multiplied by the sine of the y part. To do this without a vertex shader you would have to process each vertex with this sin function, copy that into another Vertex Buffer, Output that vertex buffer. Using a vertex shader you simply tell D3D to use your transormation code instead of passing an FVF to the SetVertexShader. A small piece of Vertex shader assembly processes that algorithm (which is HW accelerated on Geforce3+ and Radeon, or 3DNow/SSE/SSE2 on the processor here no HW Acceleration).

If you seach the net there are tone of cool demos and articles on them. It makes programming D3D 8 really cool as you can create your own effects so easily.

PS Vertex Shaders are called (more sensibly in my opinion) Vertex Programs.

WHATCHA GONNA DO WHEN THE LARGEST ARMS IN THE WORLD RUN WILD ON YOU?!?!
WHATCHA GONNA DO WHEN THE LARGEST ARMS IN THE WORLD RUN WILD ON YOU?!?!
So, a vertex shader doesn''tchange vertex locations then. They basicaly just screw with the normals then... Kinda correct? So it acts kinda like a procedural bump map? Am I even in the right ballpark here? Thanks.

Landseknecht
My sig used to be, "God was my co-pilot but we crashed in the mountains and I had to eat him..."
But folks whinned and I had to change it.
A vertex shader replaces the normal T&L route. Basically when you call DrawPrimitive, for every vertex your VS code is called.

This code may change the vert positions, the colours, apply lighting, apply bump effect, make every thing green, etc, etc.



No, incorrect. You can change the position (or in fact: any vertex attribute) in the shader. You cannot create new vertices or delete them using a vertex shader.

Kippesoep
Yes, as I said, the vert positions, the colours, apply lighting, apply bump effect, make every thing green, etc, etc.
It sounds like a vertex shader is a vertex modifier, and has little to do with shading.

This topic is closed to new replies.

Advertisement