Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

Vector transformations

Started by jochenstier Jan 22, 2007 at 11:33 AM 0 replies 950+ views
Original Post
jochenstier
jochenstier
Hi, I am looking for a simple way of mapping a normal map onto a sphere. I am building a planet by subividing a sphere into square patches which can be covered with water or land. For water patches I would like to use normal maps for lighting calculations. The problem is that the normal maps are based on the xy plane with z being up. That works fine for a planar water surface but the patches I am talking about are maped onto a sphere. Somehow I have to transform the normals of the map into the space of the patch. I looked around and found some examples of how to rotate vectors, but that was too expensive for per pixel lighting. Somehow there must be a simple solution, but I can't see it. In the pixel shader I have access to the normal map via a texture2D and the Patch normal P. The Patch Normal orients the patch on the sphere in the global coordinate space. I first have to transform the normal from the texture map into this space, before I can use the normal for lighting calculations. I am hoping that there is a simple solution that does not require too many calculations. The solution does not have to be exact as long as it is good enough for specular lighting. Cheers Jochen P.S. Here is a little screenshot of where I am at so far (http://www.geist3d.org/1.JPG)
Demus79
Demus79
You'll need to use TBN (Tangent-Bitangent-Normal) matrix to either transform your light vector or normal map.

Practically this means 2 more 3d-vectors per vertex.

With the TBN matrix you'll have two choices:

- to transform the normal map to the object space (in pixel shader) to perform lighting

or

- to transform the light vector to the tangent space (in vertex shader) to perform lighting in tangent space. The tangent space is (approximately) the same space as your normal map so it works for an object of any shape.


Naturally, one of the methods requires actually the inverse of the TBN matrix.

You'll find resources on the net to calculate the TBN matrix.

Good luck !

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.