Castle Game Engine: CastleSphericalHarmonics

# Unit CastleSphericalHarmonics
Description | Uses | Classes, Interfaces, Objects and Records | Functions and Procedures | Types | Constants | Variables
## Description Spherical harmonic basis functions. ## Uses CastleVectors CastleUtils Math CastleCubeMaps ## Overview ### Functions and Procedures
`function SHBasis(const LM: Cardinal; const PhiTheta: TVector2Single): Float;`
`procedure LMDecode(const LM: Cardinal; out L: Cardinal; out M: Integer);`
`procedure InitializeSHBasisMap;`
`procedure SHVectorFromCubeMap(var SHVector: array of Single; const Map: TCubeMapByte);`
### Types
`TSHVectorSingle = array [0..MaxSHBasis - 1] of Single;`
`PSHVectorSingle = ˆTSHVectorSingle;`
### Constants
`MaxSHBasis = 25;`
`SHBasis0 = 1 / (2 * Sqrt(Pi));`
### Variables
`SHBasisMap: array [0..MaxSHBasis - 1] of TCubeMapFloat;`
## Description ### Functions and Procedures
`function SHBasis(const LM: Cardinal; const PhiTheta: TVector2Single): Float;`
Calculate spherical harmonic basis function for given arguments. LM indicates (L, M) that specify which SH basis to use. LM determines a pair (L, M) in the natural order: for each L, take for each M from -L to L. That is, LM = (0, 1, 2, 3, ...) indicate
        (L, M) =
      ( (0, 0),
        (1, -1), (1, 0), (1, 1),
        (2, -2), (2, -1), (2, 0), (2, 1), (2, 2),
        ... )
)
`procedure LMDecode(const LM: Cardinal; out L: Cardinal; out M: Integer);`
`procedure InitializeSHBasisMap;`
`procedure SHVectorFromCubeMap(var SHVector: array of Single; const Map: TCubeMapByte);`
Calculate SH basis coefficients that approximate function in Map. This uses SHBasisMap, so be sure to initialize it first.
### Types
`TSHVectorSingle = array [0..MaxSHBasis - 1] of Single;`
`PSHVectorSingle = ˆTSHVectorSingle;`
### Constants
`MaxSHBasis = 25;`
How many basis can SHBasis calculate. LM for SHBasis must be within 0 .. SHBasesCount - 1.
`SHBasis0 = 1 / (2 * Sqrt(Pi));`
The first SH basis function is actually constant. This is sometimes useful.
### Variables
`SHBasisMap: array [0..MaxSHBasis - 1] of TCubeMapFloat;`
For each SHBasis function (first index of the array is LM of this function), a precalculated results of basic spherical harmonic functions. Multiplied by solid angle of this cube map pixel, since this is what you usually need. For each side of the cube, and for each pixel on this side (pixels are arranged same as in TGrayscaleImage, that is row-by-row from lower to higher, from left to right) this gives the result of SHBasis for this direction. Multiplied by solid angle. You have to initialize this (once, like at the beginning of your program) by InitializeSHBasisMap. This is useful for calculating sh basis vector from given cube map: since you can just project any function on any basis, so if you have a particular cube map you can project it on each SH basis function. See SHVectorFromCubeMap implementation for code how to use `SHBasisMap` for this, and in simple cases you can just call SHVectorFromCubeMap.
Generated by PasDoc 0.13.0 on 2015-06-15 04:43:12