DevMaster.net  
[[ Home | Forums | 3D Engines Database | Wiki | Articles/Tutorials | Game Dev Jobs | IRC Chat Network | Contact Us ]]

>


     
31/12/1969

Introduction

As my quest to better understand the pixel and vertex shaders, I’ve written this article, which explains what vertex and pixel shaders are and why they should be used.

Why shaders?

The addition of programmable vertex shaders and pixel shaders makes visual quality in real-time graphics take a quantum leap towards cinematic realism. Thanks to the programmable graphics processors on newer graphics cards, developers can add personalized combinations of graphics operations by using these shaders, creating their own effects to their games. Effects that can be created with shaders:

  • Hair and fur
  • Per-pixel lighting
  • Underwater effects
  • Clothing
  • Place your effect here :)

The developer creates the shaders in assembly code or in the newly announced Cg language (looks almost exactly like C code) from Nvidia and downloads them onto the Graphics Processor during rendering.

One downside to the shaders is that older graphics card can’t support it because they don’t have programmable graphics processors, but all future cards will most probably have one. Pixel shaders is at the time of this writing only supported by GeForce 3/4TI and RADEON 8500-based cards and later cards.

Vertex shader

A definition I’ve found on what a vertex shader is:

A vertex shader is a graphics processing function, which manipulates vertex data values on an X (length), Y (height) and Z (depth) 3D plane through mathematical operations on an object. These variations range anywhere from differences in color, texture coordinates, orientations in space, fog (how dense it may appear at a certain elevation) and point size.

Figure 1 – Show all the data that can come in to a vertex program and that can come out of it

When a vertex shader is enabled, it replaces the fixed-function pipeline for vertices. The shader doesn’t operate on a primitive like a triangle, but on a single vertex. A vertex shader cannot create or destroy vertices, it can only manipulate the vertices. For every vertex to be processed, the shader program executes.

Pixel shader

Here, I’ve found a definition of what a pixel shader is:

A pixel shader is a small program which processes pixels and executes on the Graphics Processing Unit

When you create a pixel shader, you’ve created a fragment processing function which manipulates fragment data. See below in this article for a definition of a fragment. This gives you complete control. With pixel shaders, you can for example create water interaction, detail normal maps and flare, as shown in figure 2.

Figure 2 – Three images showing detail normal maps, flare and water interaction.

One thing though, is that pixel shaders often require data from the vertex shader. Pixel shaders often have to be "driven" by the vertex shader. For example to calculate per-pixel lighting the pixel shader needs the orientation of the triangle, the orientation of the light vector and in some cases the orientation of the view vector.

Fragment

Fragment shader is the same as a pixel shader. The 3D scene in OpenGL is projected onto the xy-plane where all the points are called fragments. The fragments contain information such as position and texture coordinates. Several fragments can be added together when displayed to a pixel on the screen.

Summarize

This article has made a lot of the words and expressions regarding pixel and vertex shaders clearer for me to understand. Hope it’s helped you too in your quest for better understanding in this world. Thanks to Dirk Gerrits for looking through the article and helping with some sentences and explanations.

References

Sim Dietrich, “DX8 Pixel Shader”
http://www.cs.uct.ac.za/Research/CVC/Reading/ARCHIVE/I NTEREST/VertexShaders/PixelShaders-DX8.pdf

Jason L. Mitchell, “Real-Time 3D-Graphics with Pixel shaders”
http://www.intel.com/idf/us/spr2002/presentations/GSSS225.pdf

http://www.pny.com/home/techsupport/faqs/readtopic.cfm?modelID=16
Chris Maughan, Matthias Wloka, “Vertex Shader Introduction”

http://developer.nvidia.com/docs/IO/1315/ATT/NVidiaVertexShadersIntro.pdf




Discuss this article in the forums
Print article

© 2003-2004 DevMaster.net. All Rights Reserved. Terms of Use & Privacy Policy Want to write for us? Click here