citro3d
Loading...
Searching...
No Matches
lightlut.h
Go to the documentation of this file.
1/**
2 * @file lightlut.h
3 * @brief Generate lighting lookup tables
4 */
5#pragma once
6#include "types.h"
7#include <math.h>
8
9typedef struct
10{
11 u32 data[256];
13
14typedef struct
15{
16 C3D_LightLut lut;
17 float bias, scale;
19
20typedef float (* C3D_LightLutFunc)(float x, float param);
21typedef float (* C3D_LightLutFuncDA)(float dist, float arg0, float arg1);
22
23static inline float quadratic_dist_attn(float dist, float linear, float quad)
24{
25 return 1.0f / (1.0f + linear*dist + quad*dist*dist);
26}
27
28static inline float spot_step(float angle, float cutoff)
29{
30 return angle >= cutoff ? 1.0f : 0.0f;
31}
32
33/**
34 * @brief Generates lighting lookup table from pre-computed float array.
35 * @param[out] lut Pointer to lighting lookup table structure.
36 * @param[in] data Pointer to pre-computed float array.
37 */
38void LightLut_FromArray(C3D_LightLut* lut, float* data);
39
40/**
41 * @brief Generates lighting lookup table using specified callback function.
42 * @param[out] lut Pointer to light environment structure.
43 * @param[in] func Callback function.
44 * @param[in] param User-specified parameter to callback function.
45 * @param[in] negative If false, x argument of callback function will be in range [0,256]. If true, x argument will be in range [-128,128].
46 */
47void LightLut_FromFunc(C3D_LightLut* lut, C3D_LightLutFunc func, float param, bool negative);
48
49/**
50 * @brief Generates distance attenuation lookup table using specified callback function.
51 * @param[out] lut Pointer to light environment structure.
52 * @param[in] func Callback function.
53 * @param[in] from Starting distance of lighting.
54 * @param[in] to Ending distance of lighting.
55 * @param[in] arg0 User-specified parameter to callback function.
56 * @param[in] arg1 User-specified parameter to callback function.
57 */
58void LightLutDA_Create(C3D_LightLutDA* lut, C3D_LightLutFuncDA func, float from, float to, float arg0, float arg1);
59
60/**
61 * @brief Generates lighting lookup table using powf function (phong lighting).
62 * @param[out] lut Pointer to light environment structure.
63 * @param[in] shininess Shininess value of specular highlights (pow function exponent).
64 */
65#define LightLut_Phong(lut, shininess) LightLut_FromFunc((lut), powf, (shininess), false)
66
67/**
68 * @brief Generates lighting lookup table for spotlights.
69 * @param[out] lut Pointer to light environment structure.
70 * @param[in] angle Beam angle of the spotlight.
71 */
72#define LightLut_Spotlight(lut, angle) LightLut_FromFunc((lut), spot_step, cosf(angle), true)
73
74/**
75 * @brief Generates distance attenuation lookup table.
76 * @param[out] lut Pointer to light environment structure.
77 * @param[in] from Minimum distance from light source.
78 * @param[in] to Maximum distance from light source.
79 * @param[in] linear Linear coefficient.
80 * @param[in] quad Quadratic coefficient.
81 */
82#define LightLutDA_Quadratic(lut, from, to, linear, quad) LightLutDA_Create((lut), quadratic_dist_attn, (from), (to), (linear), (quad))
void LightLut_FromFunc(C3D_LightLut *lut, C3D_LightLutFunc func, float param, bool negative)
Generates lighting lookup table using specified callback function.
void LightLut_FromArray(C3D_LightLut *lut, float *data)
Generates lighting lookup table from pre-computed float array.
void LightLutDA_Create(C3D_LightLutDA *lut, C3D_LightLutFuncDA func, float from, float to, float arg0, float arg1)
Generates distance attenuation lookup table using specified callback function.
Definition lightlut.h:15
Definition lightlut.h:10
uint32_t u32