http://thelakotaculturalexchangeprogram.org/?p=73 To generate matcap UV coordinates, we use the following formula:
- is a unit vector pointing from the current pixel to the camera (in view-space)
- is a unit vector of the vertex normal or pixel normal (in view-space)
In this tutorial, I demonstrate a step-by-step approach to implementing the formulae laid-out above:
To create a more realistic matcap material, we can split the diffuse and specular reflectance components into two dedicated textures (rather than having a single texture attempting to simulate both). Diffuse reflectance does not vary according to viewing angle, making spherical projection a more approperiate option for portraying it. Specular reflectance on the other hand is viewing angle dependant and ideally suited to using the original matcap projection method. Spherical projection is easily accomplished using the following formula:
- is a unit vector pointing from the sphere’s centre to the current pixel
For a sphere, is no different to a surface normal. This makes things very straightforward to implement!
A more resource friendly approach would be to project the same texture onto both hemispheres, essentially cutting the texture size in half. This will create a symmetry between hemispheres, which should not be too noticeable when combined with the specular texture. In order to implement this approach, we multiply u by 2:
In order to combine the diffuse and specular reflectance textures, we simply add them together ― just like nature does in real-life!