citro3d/include/c3d/lightlut.h

36 lines
1.1 KiB
C
Raw Normal View History

2015-09-15 23:02:35 +02:00
#pragma once
#include "types.h"
#include <math.h>
typedef struct
{
u32 data[256];
} C3D_LightLut;
typedef struct
{
C3D_LightLut lut;
float bias, scale;
} C3D_LightLutDA;
2015-09-15 23:02:35 +02:00
typedef float (* C3D_LightLutFunc)(float x, float param);
typedef float (* C3D_LightLutFuncDA)(float dist, float arg0, float arg1);
static inline float quadratic_dist_attn(float dist, float linear, float quad)
{
return 1.0f / (1.0f + linear*dist + quad*dist*dist);
}
2015-09-15 23:02:35 +02:00
2017-03-30 23:42:29 +02:00
static inline float spot_step(float angle, float cutoff)
{
return angle >= cutoff ? 1.0f : 0.0f;
}
2015-09-15 23:02:35 +02:00
void LightLut_FromArray(C3D_LightLut* lut, float* data);
void LightLut_FromFunc(C3D_LightLut* lut, C3D_LightLutFunc func, float param, bool negative);
void LightLutDA_Create(C3D_LightLutDA* lut, C3D_LightLutFuncDA func, float from, float to, float arg0, float arg1);
2015-09-15 23:02:35 +02:00
#define LightLut_Phong(lut, shininess) LightLut_FromFunc((lut), powf, (shininess), false)
2017-03-30 23:42:29 +02:00
#define LightLut_Spotlight(lut, angle) LightLut_FromFunc((lut), spot_step, cosf(angle), true)
#define LightLutDA_Quadratic(lut, from, to, linear, quad) LightLutDA_Create((lut), quadratic_dist_attn, (from), (to), (linear), (quad))