It's free to join Gamasutra!|Have a question? Want to know who runs this site? Here you go.|Targeting the game development market with your product or service? Get info on advertising here.||For altering your contact information or changing email subscription preferences.
Registered members can log in here.Back to the home page.

Search articles, jobs, buyers guide, and more.

Gamasutra
July 16 2007

Messing with Tangent Space

arrowrightPage 1
arrowrightPage 2
arrowrightPage 3
arrowrightPage 4
arrowrightPage 5
arrowrightPage 6
arrowrightPage 7


Printer Friendly Version



Sign up for the Gamasutra Daily Newsletter!

Telltale Games : Technical Artist [11.22.08]
Namco Networks America Inc. : Flash Games Engineer [11.21.08]
War Drum Studios, LLC : Network Game Programmer [11.21.08]
First Act Interactive : Project Lead Software Engineer [11.21.08]
Sony Computer Entertainment America : Senior Manager of Game System Engineering [11.21.08]
Cryptic Studios, Inc. : Lead Game Master Support Representative [11.21.08]
Sparkplay Media : QA Manager [11.21.08]
Cryptic Studios, Inc. : User Interface Designer [11.21.08]
Treyarch / Activision : Technical Director [11.21.08]
Ignition Entertainment : Motion Director [11.21.08]
Ignition Entertainment : Producer [11.21.08]
Sony Pictures Entertainment : Software Engineer / Lua Scripter [11.20.08]
Sony Computer Entertainment America : SR. TECHNICAL PROJECT MANAGER [11.20.08]
Edge of Reality : Project Manager [11.20.08]
Stealth Startup : 3d Graphics Programmer - Virtual Worlds [11.20.08]

View All    Post A Job

Post Resume


Upcoming Events:
DIG London Game Conference
London, Canada
11.27.08

5th Australasian Conference on Interactive Entertainment
Brisbane, Australia
12.03.08

IEEE Symposium on Computational Intelligence and Games
Perth, Australia
12.15.08

2K Bot Prize
Perth, Australia
12.15.08

The 6th Annual Mobile Games Forum 2009
London, United Kingdom
01.21.09

Submit Event

View All


Messing with Tangent Space

(Page 1/7)
Next arrow


1. Assumptions

I will assume that you are familiar with some basic vector math and 3D coordinate systems. I will also use the left handed coordinate system (OpenGL uses the right handed system) throughout this document. For the pixel and vertex shaders I will assume that you understand the syntax of DirectX shaders. Many people seem to find assembly shaders quite intimidating. The main point of this article is to help you understand the concepts and not provide code. The code is provided only to assist you in understanding the concepts.

2. Introduction

In this article I will cover what tangent space is and how to convert a point between world space and tangent space. The main reason I wrote this article was so that a person new to pixel shaders will be able to quickly understand a fairly important concept and make his own implementations.

The second section was written to demonstrate a practical use of world space to tangent space conversion. That is when you will actually understand why tangent space is so important in many of today's pixel shaders. I am sure you will find many fancier tutorials for per-pixel lighting on the internet, but this one is meant to get you warmed up on tangent space.

That being said, lets get started...

3. Tangent space

1. What is tangent space

As far as the name goes, tangent space is also known as texture space in some cases.

Our 3D world can be split up in to many different coordinate systems. You already should be familiar with some of these – world space, object space, camera space. If you aren’t I think you are jumping the gun and would strongly recommend you go back to these topics first.

Tangent space is just another such coordinate system, with it’s own origin. This is the coordinate system in which the texture coordinates for a face are specified. The tangent space system will most likely vary for any two faces.

In this coordinate system visualize the X axis pointing in the direction in which the U value increases and the Y axis in the direction in which V value increases. In most texturing only U and V change across a face tangent space can be thought of a 2D coordinate system aligned to the plane of a face.

So what about the Z axis in tangent space?
The u and v values can be used to define a 2D space, but to do calculations in a 3D world we need a Z axis as well. The Z axis can be though of as the face normal, always perpendicular to the face itself.

For now we will call this n (for normal). The value of n will always stay constant at 0 across a face.


Figure 1: Tangent space axis for a face in a plane

Take a look at Figure 1. It will help you visualize the tangent space coordinate system. It shows a quad made up of four vertices and two faces assumed to have a simple texture unwrap applied to it.

Figure 2 shows the tangent space axis for a face on a cube defined by the vertices 1, 2, 3. Once again we assume that this cube has a very simple texture unwrap applied to it.
In the bottom left you will also see the axis for the world space coordinate system marked by x,y,z.

The u, v, n axis represent the direction in which u, v, n values increase across the face, just as the x, y, z values represent the direction in which the x, y, z values increase in the world space coordinate system.

Figure 2: Tangent space axis for a face in a box


Let us take another example. In Figure 2 we try to visualize the tangent space for a top face of a box.


(Page 1/7)
Next arrow


Comments


Kiran Sudhakara 19 Sep 2008 at 1:29 am PST
Step 2: Calculate the T vector
T = E2-1.xyz / E2-1.u

This formula does not seem correct. Wouldn't this just scale the edge?







join | contact us | advertise | write | my profile
news | features | contract work | jobs | resumes | education | product guide | store