vpNormalIndex(3)
π vpNormalIndex(3) β your girl's guide to normal vectors, bestie π
okay so real talk, this page lives in the Library Functions Manual and it's all about vpNormalIndex and vpNormal, two lil functions from VolPack that do the whole encode/decode thing with surface normal vectors. yes THE surface normals. the ones your shading table has been begging for. let's get into it π¦
β¨ 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 your surface normal vector. just the x. that's her πnyβ the Y component of your surface normal vector. yes, y, we love her.nzβ the Z component of your surface normal vector. z is here too, trio complete β¨nβ an encoded surface normal vector. it's an int, she's compact, she's iconic πnx_ptrβ pointer to storage where we'll drop the X component of the surface normal vector back out. she's a pointer, she receives π«Άny_ptrβ pointer to storage for returning the Y component of the surface normal vector.nz_ptrβ pointer to storage for returning the Z component of the surface normal vector.
β¨ DESCRIPTION β¨
so these two routines? they convert surface normal vectors between encoded and unencoded forms. that's literally their whole job and they ate π₯
an unencoded vector is described by its three components, stored as double-precision floating point numbers, in an orthogonal coordinate system. three doubles. very demure, very spacious.
an encoded vector is described by a single integer that is suitable for use as an index in a shading lookup table. one int. tiny. efficient. main character energy π
here's the tea: 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. so like, you could do it yourself, but why π
and before you panic β user-defined shading routines or lookup tables are not required to use encoded normal vectors. so if you're going custom, you're free. no cap π
okay so vpNormalIndex computes an encoded vector from the components of an unencoded vector. BUT. and this is important bestie, listen β the vector must be normalized, meaning:
nx*nx + ny*ny + nz*nz = 1
the maximum possible value of an encoded normal is given by the constant VP_NORM_MAX. remember her β
then vpNormal does the reverse: it computes the components of a vector from the encoded integer form. but heads up β 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 "close enough, bestie" π not a bug, just the tradeoff.
β¨ ERRORS β¨
vpNormalIndex always returns a valid encoded normal vector. she never misses. periodt π
β¨
vpNormal normally returns the value VP_OK. but the following return value is possible:
VPERROR_BAD_VALUEβ the encoded normal vector is invalid. π yeah. that one.
β¨ SEE ALSO β¨
VolPack(3), vpVolumeNormals(3), vpScanlineNormals(3) β go read these next, they're the friend group π«Άπ
and that's the whole page!! brought to you by VolPack, page vpNormalIndex(3). mwah, go encode something gorgeous ππ
π¦ where this page comes from
- debian bookworm: libvolpack1-dev 1.0b3-9 Β· BSD-3-Clause
- debian trixie: libvolpack1-dev 1.0b3-10 Β· BSD-3-Clause
- ubuntu jammy: libvolpack1-dev 1.0b3-9 Β· BSD-3-Clause
- ubuntu noble: libvolpack1-dev 1.0b3-9.1 Β· BSD-3-Clause
- ubuntu questing: libvolpack1-dev 1.0b3-11
- ubuntu resolute: libvolpack1-dev 1.0b3-11build1 Β· BSD-3-Clause
- ubuntu stonking: libvolpack1-dev 1.0b3-11build1 Β· BSD-3-Clause
- Copyright (c) 1994 The Board of Trustees of The Leland Stanford
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms