OK,what exactly are Pixel and Vertex shaders?

OK I know this might seem like a really dumb question (what with all the talk of this new technology) but I still couldn’t (for the life of me) figure out what the hell Pixel and Vertex shaders are!

I’ve checked nVidia’s website to try and find info on them but all I managed to find was a presentation on them.That presentation didn’t tell me much.The only thing I found out that I have to use assembly to program these things.

So my question to you is:
(1) What is a Vertex Shader and what is it used for?
(2) What is a Pixel Shader and what is it used for?
(3) Where in an OpenGL program do you actually code pixel/vertex shaders? (Or is the code in a totally separate file)
(4) Any one know of any REALLY brain dead simple source code I could take a look at? I’m looking for something like just drawing a cude and texturing it using Pixel or Vertex shaders.Something simple like that.

Any other links you guys can think of with tutorials or sample source code would be nice.I wanna see how pixel/vertex shaders are actually implemented (programatically speaking) It’s too bad nVidia doesn’t have a white paper on this kind of stuff in OpenGL (or if there is,I couldn’t find it)

Thanx for any help guys.The more info I get on these things,the sooner I can start to play around with them.

The terms “vertex shader” and “pixel shader” are the DX8 terms for two “programs” you can write to alter portions of the rendering pipeline.

DX8 Vertex Shaders are the equivalent of the OpenGL extension vertex_program_NV. It, basically, overrides the T&L pipeline.

From what I can gather, DX8 pixel shaders combine the equivalent functionality of both texture_shader_NV and register_combiner_NV, in a less-than-steller interface (especially since these are two very different functions). Feel free to read up on these specs in the NVIDIA OpenGL specification document avaliable on their web page.

when you give your vertices, they first pass the vertexpipeline of a gpu
there, they are transformed to screen, when you enabled lighing the lighing is calculated, when you have some autotexturegeneration, this is done there, too ( environment maps, projected maps )

then a triangle is rastericed

and for every pixel of the triangle there will be calculated this pixel
in the pixelpipeline
its a today very complicated “function”, wich does give you the power of doing stuff like perpixellighing and more
there the texturepixels are sampled for this pixel, the vertexcolors are interpolated, and the tex_environment functions are done ( like GL_ADD, GL_MODULATE or stuff like GL_DOTPRODUCT3_EXT ), or even you have enabled register_combiners with those you get full access to this…

trick is now
vertexshader replaces the vertexpipeline, so that you can perform your own transfer and lighing

pixelshader replaces the pixelpipeline, so that you can there perform your own perpixelcalculations

whats the power of vertexshaders/pixelshaderS?

ok, i wrote in my program ( opengl ) a vertexprogram and the pixelstuff i replaced with my own registercombiners ( no pixelshaders… registercombiners are bether anyways for todays gpu’s… )

then i wanted to change from pervertexlighting to perpixellighing

first, you cant do that without direct access to the pixelpipeline…
second, with the vertexprogram, it took me 2 lines of code to change it to a perpixelsetup and 2 lines i had to change in the registercombiner setup to get there the perpixelllighing

thats the power of nows extensions…

OK I’m kind of getting it.Where can I find more info on vertex_program_NV extension for OpenGL?

davepermen: Do you mind if I took a look at your source code? (If this is for a big project you’re working on,then don’t worry about it )

And one more thing,do you use all that assembly syntax in OpenGL too? Or is that only in D3D?

Thanx for the responses guys!

download the openglsdk from nvidia.com/developer

there you get everything you need… my source… ok… soon…

yes, you write it in an assembler style on opengl, too… its the most easy way to get fast results…

There are some vertex program examples on my website.
www.nutty.org

Nutty

I am working on an application which will use Vertex Programs, Texture Shaders and Register Combiners. Unfortunately we have to support the option for OpenGL and DirectX (multi-platform), so the interface to this will need to be abstracted at a high enough level so as to not be API specific.
Has anyone done any mapping of the OpenGL instructions to DirectX assembly for Texture SHaders, Register Combiners vs pixel shaders. (I have Vertex Programs vs vertex shaders under control).
Any help would be appreciated.

AFAIK (which is not very in D3D) vertex shaders syntax is very similar to vertex programs. The way of passing them down to the driver, and setting them up… is very similar.

Pixel shaders on the other hand, are totally different. In D3D you use a kind of assembly language, (like in vertex shaders) which you write and pass over to D3D. In OpenGL, you access the pixel shader stuff through the register combiner functions.

I have heard, that the OpenGL method gives more flexability, and exposes more pixel shader functionality, than the D3D equivelent.

Nutty

How about hardware support for vertex and pixel shaders?
Example: 3dMark 2001 doesnt want to display the landscape game test because i dont have the needed per pixel shader support .(my card is a geforce2Mx, dx8 and the latest drivers from nvidia) But Im able to run the per pixel lighting demos and nvidias pixel shader tool (the one for OpenGl, I dont know about Direct-x) are those emulated, just like the vertex shaders? (at least one per pixel demo I could run before I had emulatenv20 enabled)
(btw is it legal to use the 10.XXX drivers from nvidia because I can`t find them on their site)

Pentagram

Hardware support for vertex and pixel shaders is only in Geforce 3.

The per pixel lighting demos from Nvidia’s site use Register Combiners. (Similar to pixel shaders, except register combiners are supported in hardware since Geforce 1)

Vertex shaders can be emulated quite quickly, and from Detonator 7 series onwards the drivers do have emulation code in there for vertex shaders. I’m not sure if D3D has their own emulation or not.

As for pixel shader emulation… it can be done. but it’s soo god damn slow it’s pointless. Almost impossible to get even close to 1fps.

Re drivers, It’s probably not illegal to use them. They’re beta drivers. Their website probably only gives out official drivers.

hope that answers some questions.

Nutty

Thanx for the replies guys.I’m getting to know these shaders a little better now that I’m reading the DX8 SDK docs.

But there was this one interesting thing I say on the xbox presentation at the GDC and that was creating fur and grass using pixel shaders.Is that easy or hard to do (if you know how to program pixel shaders?)

I just want to get a clear idea of how complex shader code can become.

Thanx!