Skip to content

Instantly share code, notes, and snippets.

@wwylele
Last active September 19, 2022 17:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wwylele/f61d6653620bb763ab9dc7a60a9831ce to your computer and use it in GitHub Desktop.
Save wwylele/f61d6653620bb763ab9dc7a60a9831ce to your computer and use it in GitHub Desktop.

GPU_LUTINPUT_CP

GPU_LUTINPUT_CP (= "cos(phi)") is used for anisotropic reflection, based on Schlick's model. According to the paper, the input value should be T * H', where T is the tangent vector, and H' is the projection of half-angle vector on to the tangent plane.

Here are some (strange) details:

  • GPU_LUTINPUT_CP is only available under configuration 7
  • H' is not normalized. This is found when replicating the output from 3ds in citra. Unormalized H' produces the same result, while normalized H' doesn't. This means the angle phi is not the angle between T and H' anymore. On Schlick's paper, it is unclear whether this is the case.
  • Also found when implementing in citra: when using normal mapping, it seems that the tangent vector stays (1, 0, 0) in surface-local space, instead of rotating with the normal vector. This means the normal and tangent vectors are not perpendicular anymore
  • Dispite the point above, when projecting H to H', the perturbed normal vector is still used, and the computed H' is not on the tangent plane where the tangent vector is.

Tangent Mapping

The tangent mapping perturbs the tangent vector in the surface-local space (instead of normal vector which is perturbed by normal mapping), and with GPU_LUTINPUT_CP, it is useful to define an anisotropic surface texture.

Like the normal mapping doesn't rotate the tangent vecotr, the tangent mapping might not rotate the normal vector either. This means for all lut inputs other than GPU_LUTINPUT_CP, won't be affected by the tangent map at all because they don't use the tangent vector.

Effect of "Recompute z-component" register bit on the tangent map

For normal map, with this setting enabled, the z-component of each perturbs normal vector will be recomputed as sqrt(1-x^2-y^2). However, when using bump map as tangent map, toggling this bit doesn't affect out put with any lut input (including CP) at all. There are two equivalent explanations:

  • PICA doesn't do recomputation when using tangent map
  • This bit does do the same recomputation z=sqrt(1-x^2-y^2) on each tangent vector, but mathematically this has no effect, because the only tangent map user, CP, equals the dot product between the tangent vector and a tangent plane projection, meaning the orthoganal component of the tangent vector (=z component before quaternion rotation) is eliminated in the dot product.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment