Parallax Mapping

Parallax Mapping

  Parallax mapping belongs to the family of displacement mapping techniques that displace or offset vertices based on geometrical information stored inside a texture.

1、Height Map。

  One way to do this is to take a plane with roughly 1000 vertices and displace each of these vertices based on a value in a texture that tells us the height of the plane at a specific area. Such a texture that contains height values per texel is called a height map. An example height map derived from the geometric properties of a simple brick surface looks a bit like this:

    

  Taking a flat plane displaced with the above heightmap results in the following image:

  

  A problem with displacing vertices is that a plane needs to consist of a large amount of triangles to get a realistic displacement otherwise the displacement looks too blocky.  As each flat surface could then require over 1000 vertices this quickly becomes computationally infeasible.

2、Parallax Mapping 理论。

  The idea behind parallax mapping is to alter the texture coordinates in such a way that it looks like a fragment's surface is higher or lower than it actually is, all based on the view direction and a heightmap.

    

  Red line represents the values in the heightmap. If the plane would have actual displacement the viewer would see the surface at point B. 

  Parallax mapping aims to offset the texture coordinates at fragment position A in such a way that we get texture coordinates at point B.

  The trick is to figure out how to get the texture coordinates at point B from point A. Parallax mapping tries to solve this by scaling the fragment-to-view direction vector V¯ by the height at fragment A.

  So we're scaling the length of V¯ to be equal to a sampled value from the heightmap H(A) at fragment position A. The image below shows this scaled vector P¯:

    

  We then take this vector P¯P¯ and take its vector coordinates that align with the plane as the texture coordinate offset. This works because vector P¯P¯ is calculated using a height value from the heightmap so the higher a fragment's height, the more it effectively gets displaced.

3、

参考:

1、https://learnopengl.com/Advanced-Lighting/Parallax-Mapping

 

猜你喜欢

转载自www.cnblogs.com/tekkaman/p/9045360.html