Cg Shader Tutorial

Cg Shader Tutorials

Panda has the ability to process shaders written in the Cg shader language. In this tutorial series, you will learn how to write shaders for Panda3D in Cg. While there are panda specific things in this tutorial you should be able to learn how to write Cg shaders that can be used in other engines.

Pre-requisites

You should be able to write a simple math program in C. Do not underestimate this. If you start writing your own shaders without any prior knowledge about a C-like language it is as hard as starting to write a Panda3D application without knowing anything about Python. Some resources you might want to look at:

You should have a solid grasp of Panda basics. Read the hello world tutorial and understand the “Solar System” sample that comes with the Panda3D distribution. You should also have a good understanding of how the scene graph works. If you’re interested in writing a shadow mapping shader, it helps to have a solid understanding of how the depth buffer works.

Read the first chapter from NVIDIA’s Cg Tutorial. You do not have to understand it fully, but at least you know who invented Cg and what it is for. The NVIDIA and ATI developer sites also have plenty of useful information about shaders.

You should also have the List of Possible Shader Inputs page handy.

Tutorials

  1. Baseline Panda application

  2. The Simplest Possible Shader. So simple that it’s useless.

  3. The simplest possible useful shader.

  4. Applying colors to the model as defined in the model file.

  5. Applying colors with the vertex and fragment shaders. Pass information between the vertex and fragment shader.

  6. Passing inputs to the shader and controlling it from Panda

  7. Applying one texture to your models, disregarding colors.

  8. Applying two textures to your models.

  9. Explaining details about diffuse lighting.

  10. Per vertex diffuse lighting with shaders. The concept of spaces is introduced here.

  11. Per pixel lighting with one point light. Normalization problems that may arise are explained here.

  12. Per pixel lighting with multiple point lights and attenuation.

Note

This section is incomplete. It will be updated soon.

Although some pages aren’t written yet, the sourcecode for all the tutorials is complete. Read this forum topic for more info and links to codes: https://discourse.panda3d.org/t/improving-the-manual/11599