**A**‘, we calculate the offset using the fragment-to-eye vector and height-map. Parallax mapping aims to offset the texture coordinates at fragment position ‘

**A**‘ in such a way that we get texture coordinates at point ‘

**B**‘. We then use the texture coordinates at point ‘

**B**‘ for all subsequent texture samples, making it look like the viewer is actually looking at point ‘

**B**‘.

**P**‘ vector will have its

`x`

and `y `

component aligned to the surface’s tangent and bi-tangent vectors. As the tangent and bi-tangent vectors are pointing in the same direction as the surface’s texture coordinates we can take the `x`

and `y`

components of ‘**P**‘ as the texture coordinate offset, regardless of the surface’s direction. One more benefit of doing that is now we can transform the light-direction vector and view-direction vector in tangent space by multiplying the vectors with transpose of TBN matrix and do the calculations in vertex shader and let it interpolate for each fragment. This saves us from matrix multiplications in the fragment shader. This is a nice optimization as the vertex shader runs considerably less often than the fragment shader.

Parallax Mapping implemented in this is called Normal Parallax Mapping and gives more or less valid results only when height-map is smooth and doesn’t contain a lot of small details. Also, with large angles between vector to camera ‘**V**‘ and normal ‘**N**‘, effect of parallax won’t be valid. We can also choose to leave components x and y as they are, such implementation is called Parallax Mapping with Offset Limiting. Parallax Mapping with Offset Limiting allows to decrease amount of weird results when angle between vector to the camera ‘**V**‘ and noraml ‘**N**‘ is high. So if you will add x and y components of vector ‘**V**‘ to original texture coordinates you get new texture coordinates that are shifted along vector ‘**V**‘.

Once I am done implementing this, I would try to analyze these two scenarios and find out when exactly Normal Parallax Mapping gives best result and when should we use Parallax Mapping with Offset Limiting. Also, we can also take multiple samples instead of only one. It is called Steep Parallax Mapping, my another stretch goal.