$darkmode
Suckless OGL 1.0.0
A lean, high-performance C11 PBR Renderer
sh_math.c File Reference
#include "sh_math.h"
#include <math.h>
#include <string.h>
Include dependency graph for sh_math.c:

Macros

#define M_PI   3.14159265358979323846
 
#define Y00   0.28209479177387814347f /* 0.5 * sqrt(1/pi) */
 
#define Y1n1   0.48860251190291992159f /* -sqrt(3/4pi) * y */
 
#define Y10   0.48860251190291992159f /* sqrt(3/4pi) * z */
 
#define Y11   0.48860251190291992159f /* -sqrt(3/4pi) * x */
 
#define Y2n2   1.09254843059207907054f /* 0.5 * sqrt(15/pi) * xy */
 
#define Y2n1   1.09254843059207907054f /* -0.5 * sqrt(15/pi) * yz */
 
#define Y20   0.31539156525251999825f /* 0.25 * sqrt(5/pi) * (3z^2 - 1) */
 
#define Y21   1.09254843059207907054f /* -0.5 * sqrt(15/pi) * xz */
 
#define Y22   0.54627421529603953527f /* 0.25 * sqrt(15/pi) * (x^2 - y^2) */
 
#define A0   3.14159265359f /* PI */
 
#define A1   2.09439510239f /* 2PI/3 */
 
#define A2   0.78539816339f /* PI/4 */
 

Functions

void sh_zero (SH9 *sh_ptr)
 Initialize SH coefficients to zero. More...
 
void sh_project_directional (const vec3 dir, const vec3 color, SH9 *out_sh)
 Projects a directional light into SH coefficients. More...
 
void sh_eval_irradiance (const vec3 normal, const SH9 *sh_ptr, vec3 out_color)
 Evaluates the irradiance from SH coefficients in a given direction. More...
 

Macro Definition Documentation

◆ A0

#define A0   3.14159265359f /* PI */

◆ A1

#define A1   2.09439510239f /* 2PI/3 */

◆ A2

#define A2   0.78539816339f /* PI/4 */

◆ M_PI

#define M_PI   3.14159265358979323846

◆ Y00

#define Y00   0.28209479177387814347f /* 0.5 * sqrt(1/pi) */

◆ Y10

#define Y10   0.48860251190291992159f /* sqrt(3/4pi) * z */

◆ Y11

#define Y11   0.48860251190291992159f /* -sqrt(3/4pi) * x */

◆ Y1n1

#define Y1n1   0.48860251190291992159f /* -sqrt(3/4pi) * y */

◆ Y20

#define Y20   0.31539156525251999825f /* 0.25 * sqrt(5/pi) * (3z^2 - 1) */

◆ Y21

#define Y21   1.09254843059207907054f /* -0.5 * sqrt(15/pi) * xz */

◆ Y22

#define Y22   0.54627421529603953527f /* 0.25 * sqrt(15/pi) * (x^2 - y^2) */

◆ Y2n1

#define Y2n1   1.09254843059207907054f /* -0.5 * sqrt(15/pi) * yz */

◆ Y2n2

#define Y2n2   1.09254843059207907054f /* 0.5 * sqrt(15/pi) * xy */

Function Documentation

◆ sh_eval_irradiance()

void sh_eval_irradiance ( const vec3  normal,
const SH9 sh_ptr,
vec3  out_color 
)

Evaluates the irradiance from SH coefficients in a given direction.

Parameters
normalNormalized surface normal.
sh_ptrPointer to the SH structure.
out_colorOutput color (vec3).

◆ sh_project_directional()

void sh_project_directional ( const vec3  dir,
const vec3  color,
SH9 out_sh 
)

Projects a directional light into SH coefficients.

Parameters
dirNormalized direction vector pointing TOWARDS the light source.
colorLinear RGB color/intensity of the light.
out_shPointer to the SH structure to accumulate into.

◆ sh_zero()

void sh_zero ( SH9 sh_ptr)

Initialize SH coefficients to zero.