vpNormalIndex(3)

πŸ“¦ version 1.0c7, in fedora 43, fedora 44

πŸ’– vpNormalIndex β€” hey bestie, it's in the Library Functions Manual πŸ’–

okay so real talk, this is a page from the Library Functions Manual, and it's about vpNormalIndex and vpNormal β€” the two functions that encode and decode a surface normal vector. yes, the whole glow-up is bidirectional. slay. ✨


πŸŽ€ NAME πŸŽ€

vpNormalIndex, vpNormal β€” encode/decode a surface normal vector πŸ¦‹


✨ SYNOPSIS ✨

#include <volpack.h>

int
vpNormalIndex(nx, ny, nz)
    double nx, ny, nz;

vpResult
vpNormal(n, nx_ptr, ny_ptr, nz_ptr)
    int n;
    double *nx_ptr, *ny_ptr, *nz_ptr;

🌸 ARGUMENTS 🌸

  • nx β€” the X component of the surface normal vector πŸ’œ
  • ny β€” the Y component of the surface normal vector πŸ’œ
  • nz β€” the Z component of the surface normal vector πŸ’œ
  • n β€” the encoded surface normal vector πŸ‘‘
  • nx_ptr β€” pointer to storage where we hand back the X component of the surface normal vector 🫢
  • ny_ptr β€” pointer to storage where we hand back the Y component of the surface normal vector 🫢
  • nz_ptr β€” pointer to storage where we hand back the Z component of the surface normal vector 🫢

πŸ’… DESCRIPTION πŸ’…

These two routines convert surface normal vectors between encoded and unencoded forms. it's giving translator, it's giving bilingual icon 🌈

An unencoded vector is described by its three components (stored as double-precision floating point numbers) in an orthogonal coordinate system. An encoded vector is described by a single integer that is suitable for use as an index in a shading lookup table. πŸ”₯

VolPack's built-in shading routines require the use of surface normal vectors encoded using vpNormalIndex (or one of the higher-level normal vector computation routines, vpVolumeNormals or vpScanlineNormals). User-defined shading routines or lookup tables are not required to use encoded normal vectors. so if you're rolling your own, you're free, no cap πŸ’«

vpNormalIndex computes an encoded vector from the components of an unencoded vector. the vector must be normalized β€” that's nx*nx + ny*ny + nz*nz = 1, bestie, no wiggle room 😭 The maximum possible value of an encoded normal is given by the constant VP_NORM_MAX. ⭐

vpNormal computes the components of a vector from the encoded integer form. here's the thing though β€” the encoded normal has less resolution than the unencoded form, so the vector computed by vpNormal may not be equal to the original vector you passed to vpNormalIndex. it's giving lossy compression, it's giving "close enough, babe" πŸ™ˆ


πŸ’€ ERRORS πŸ’€

vpNormalIndex always returns a valid encoded normal vector. always. it never misses. πŸ’…

vpNormal normally returns the value VP_OK. The following return value is possible:

  • VPERROR_BAD_VALUE β€” the encoded normal vector is invalid. 🚨

πŸ”₯ SEE ALSO πŸ”₯

VolPack(3), vpVolumeNormals(3), vpScanlineNormals(3) πŸ¦‹


quick vibe check: normalize before you encode, and remember that decode is lossy. that's the whole tea. πŸ“

and that's the page, bestie!! this whole thing came out of VolPack, and yeah, this is vpNormalIndex(3) β€” the very page you just read, iconic behavior honestly. go forth and shade something gorgeous πŸ‘‘πŸ’–βœ¨

πŸ“¦ where this page comes from