JustWe
JustWe

Reputation: 4484

How to implement bump mapping with phong shading

In fragment shader, i have normal vector in view coordinate axis system which is read from 3D model and the bump normal vector which get from bump texture. If i want to get diffuse factor and specular factor. Shall i just simple plus these two normal or do something else?

Upvotes: 0

Views: 1697

Answers (1)

Anton Angelov
Anton Angelov

Reputation: 1244

The most common normal mapping technique for real time usage, requires to calculate in advance the tangent and bi-tangent vectors per vertex, as addition to the normal vector.

After you have the normal, tangent, binormal vectors, you create a matrix (lets say TBN) to transforms from view space to model's tangent space.

So (in the vertex shader) you transform light vector and eye vectors (required for Lambert diffuse term and Phong reflection) to tangent space using TBN matrix;

And for example (in the fragment shader) the diffuse term will be D = L dot N; (where L is light position in tangent space and N is the normal vector extracted from the normal map texture).

You can find a detailed tutorial: here.

Upvotes: 1

Related Questions