Need help with deferred shading tutorial

I am currently trying to understand deferred shading and have dug up this tutorial which appears to be quite good to me.

I am understanding the idea and the basic concepts, but I cannot follow some of the math and code in the tutorial. Would it be possible that someone takes a look into it (pages 12 - 15) and answers the following questions I have?

What are “object space”, “clip space” and “view space” (I reckon view space is just the world as seen by the camera?)

Where does the vertex shader’s input “a2v” come from, and what are its normal, tangent and binormal vectors? Why is the normal transformed by using them in the fragment shader?

Sorry, I just don’t know enough about this, so I thought I’d ask someone who does. :slight_smile:

It doesn’t make it any easier that I don’t really know Cg, but only basic HLSL.

Object space is usually the space your vertices for your model sit in before you do anything like translate your object, move it in front of the “camera”, etc. Say you have a model that has a point (1,1,1) when you load it. That point is in model space. When you move the whole model over 10 points in the “world” y that point (1,1,1) in model space is (1,11,1) in world space. In OpenGL you usually keep the model and view (camera) matrices as one so when that point is multiplied by the modelview matrix, it moves that point into “camera” or “eye” space. The “camera” in OpenGL is always pointing down the negative z-axis so things like gluLookAt are spinning things around to be in front of the camera. Clipping space is after the projection, where everything in the frustum is squeezed into the [-1,1] box.

a2v is just a structure that gets declared on page 13 “struct a2v”. That structure’s data is automatically filled based on the semantics attached to them. So when using a2v IN, IN.pos or IN.normal, it’s just pulling up the references to the normal or position that the vertex came in with. Again, if you look at the POSITION in a2v, it is in object space which means it has the value that you sent down with glVertex or whatever is in your buffer before any transformations.

The normal vector you probably know. The binormal and tangent are a basis for orienting your normal. When read from a normal map, that normal is usually pointing in the Z direction (why most normal maps look blue when you see them). You need the binormal and tangent to spin it around to a useful space. If you want more on that, you should look up a full tutorial on normal mapping, which is it’s own deal.

I think I have understood this now, thank you very much.

I guess I only need binormal and tangent for bump or displacement mapping, and they have been computed somewhere ahead of rendering and are passed to OpenGL via textures bound to the TMUs.

I had a bit of a problem understanding this because I don’t really know Cg.