citro3d
|
Configure dynamic light, shading, and shadows. More...
Go to the source code of this file.
Data Structures | |
struct | C3D_Material |
Material. More... | |
struct | C3D_LightLutInputConf |
struct | C3D_LightEnvConf |
struct | C3D_LightEnv_t |
struct | C3D_LightMatConf |
struct | C3D_LightConf |
struct | C3D_Light_t |
Macros | |
#define | C3DF_LightEnv_IsCP(n) BIT(18+(n)) |
#define | C3DF_LightEnv_IsCP_Any (0xFF<<18) |
#define | C3DF_LightEnv_LutDirty(n) BIT(26+(n)) |
#define | C3DF_LightEnv_LutDirtyAll (0x3F<<26) |
Light Environment | |
enum | { C3DF_LightEnv_Dirty = BIT(0) , C3DF_LightEnv_MtlDirty = BIT(1) , C3DF_LightEnv_LCDirty = BIT(2) } |
enum | { GPU_SHADOW_PRIMARY = BIT(16) , GPU_SHADOW_SECONDARY = BIT(17) , GPU_INVERT_SHADOW = BIT(18) , GPU_SHADOW_ALPHA = BIT(19) } |
typedef struct C3D_Light_t | C3D_Light |
typedef struct C3D_LightEnv_t | C3D_LightEnv |
void | C3D_LightEnvInit (C3D_LightEnv *env) |
Resets and initializes C3D_LightEnv structure to default values. | |
void | C3D_LightEnvBind (C3D_LightEnv *env) |
Binds C3D_LightEnv pointer to be used for configuring internal state. | |
void | C3D_LightEnvMaterial (C3D_LightEnv *env, const C3D_Material *mtl) |
Coppies material properties to C3D_LightEnv. | |
void | C3D_LightEnvAmbient (C3D_LightEnv *env, float r, float g, float b) |
Sets global ambient lighting. | |
void | C3D_LightEnvLut (C3D_LightEnv *env, GPU_LIGHTLUTID lutId, GPU_LIGHTLUTINPUT input, bool negative, C3D_LightLut *lut) |
Uploads pre-calculated lighting lookup table for specified function. | |
void | C3D_LightEnvFresnel (C3D_LightEnv *env, GPU_FRESNELSEL selector) |
Enables or disables writing fresnel and shadow alpha component to GPU_FRAGMENT_PRIMARY_COLOR and GPU_FRAGMENT_SECONDARY_COLOR. | |
void | C3D_LightEnvBumpMode (C3D_LightEnv *env, GPU_BUMPMODE mode) |
Configures bump map texture properties. | |
void | C3D_LightEnvBumpSel (C3D_LightEnv *env, int texUnit) |
Configures bump map texture unit id. | |
void | C3D_LightEnvBumpNormalZ (C3D_LightEnv *env, bool enable) |
Configures whether to use the z component of the normal map. | |
void | C3D_LightEnvShadowMode (C3D_LightEnv *env, u32 mode) |
Configures shadow mapping behavior. | |
void | C3D_LightEnvShadowSel (C3D_LightEnv *env, int texUnit) |
Configures shadow mapping texture. | |
void | C3D_LightEnvClampHighlights (C3D_LightEnv *env, bool clamp) |
Enables or disables clamping specular highlights. | |
Light | |
enum | { C3DF_Light_Enabled = BIT(0) , C3DF_Light_Dirty = BIT(1) , C3DF_Light_MatDirty = BIT(2) , C3DF_Light_SPDirty = BIT(14) , C3DF_Light_DADirty = BIT(15) } |
int | C3D_LightInit (C3D_Light *light, C3D_LightEnv *env) |
Adds light to C3D_LightEnv. | |
void | C3D_LightEnable (C3D_Light *light, bool enable) |
Enables or disables light source. | |
void | C3D_LightTwoSideDiffuse (C3D_Light *light, bool enable) |
Enables or disables light source. | |
void | C3D_LightGeoFactor (C3D_Light *light, int id, bool enable) |
Enables or disables cock-torrance geometric factor. | |
void | C3D_LightAmbient (C3D_Light *light, float r, float g, float b) |
Configures global ambient color emitted by light source. | |
void | C3D_LightDiffuse (C3D_Light *light, float r, float g, float b) |
Configures diffuse lighting color emitted by light source. | |
void | C3D_LightSpecular0 (C3D_Light *light, float r, float g, float b) |
Configures specular0 lighting color emitted by light source. | |
void | C3D_LightSpecular1 (C3D_Light *light, float r, float g, float b) |
Configures specular1 lighting color emitted by light source. | |
void | C3D_LightPosition (C3D_Light *light, C3D_FVec *pos) |
Configures light position vector. | |
void | C3D_LightShadowEnable (C3D_Light *light, bool enable) |
Enables or disables shadow mapping on light source. | |
void | C3D_LightSpotEnable (C3D_Light *light, bool enable) |
Enables or disables spot light for specified light source. | |
void | C3D_LightSpotDir (C3D_Light *light, float x, float y, float z) |
Configures spot light direction vector for specified light source. | |
void | C3D_LightSpotLut (C3D_Light *light, C3D_LightLut *lut) |
Configures spotlight lookup table. | |
void | C3D_LightDistAttnEnable (C3D_Light *light, bool enable) |
Enables or disables distance attenuation for specified light source. | |
void | C3D_LightDistAttn (C3D_Light *light, C3D_LightLutDA *lut) |
Uploads pre-calculated distance attenuation lookup table for specified light source. | |
static void | C3D_LightColor (C3D_Light *light, float r, float g, float b) |
Configures diffuse and specular0/1 color emitted by light source. | |
Configure dynamic light, shading, and shadows.
The equations used for calculating fragment lighting appears to be as follows:
\[ C_{pri} = s^{(a)} + \sum_{i = 0}^{\#lights} a * SpotlightLut(d_0) * o * (l_i^{(d)} * f_i(L_i \cdot N) + l_i^{(a)}) \]
\[ C_{sec} = \sum_{i = 0}^{\#lights} a * SpotlightLut(d_0) * h * o * (l_i^{(s_0)}LutD_0(d_1)*G_i^{(0)} + l_i^{(s_1)}LutD_1(d_3)*G_i^{(1)}*ReflectionLutsRGB(d_2)) \]
\[ C_{alpha} = FresnelLut(d_4) \]
Outputs:
Inputs, per-fragment:
Inputs, per-pass:
Inputs, per-Light:
In citro3d, some inputs may be configured by multiple variables, for example:
void C3D_LightAmbient | ( | C3D_Light * | light, |
float | r, | ||
float | g, | ||
float | b | ||
) |
Configures global ambient color emitted by light source.
[out] | light | Light source structure. |
[in] | r | Red component. |
[in] | g | Green component. |
[in] | b | Blue component. |
|
inlinestatic |
Configures diffuse and specular0/1 color emitted by light source.
[out] | light | Light source structure. |
[in] | r | Red component. |
[in] | g | Green component. |
[in] | b | Blue component. |
void C3D_LightDiffuse | ( | C3D_Light * | light, |
float | r, | ||
float | g, | ||
float | b | ||
) |
Configures diffuse lighting color emitted by light source.
[out] | light | Light source structure. |
[in] | r | Red component. |
[in] | g | Green component. |
[in] | b | Blue component. |
void C3D_LightDistAttn | ( | C3D_Light * | light, |
C3D_LightLutDA * | lut | ||
) |
Uploads pre-calculated distance attenuation lookup table for specified light source.
[out] | light | Light source structure. |
[in] | lut | Pointer to pre-computed distance attenuation lookup table. |
void C3D_LightDistAttnEnable | ( | C3D_Light * | light, |
bool | enable | ||
) |
Enables or disables distance attenuation for specified light source.
[out] | light | Light source structure. |
[in] | enable | Enable distance attenuation factor for light source. |
void C3D_LightEnable | ( | C3D_Light * | light, |
bool | enable | ||
) |
Enables or disables light source.
[out] | light | Light source structure. |
[in] | enable | true to enable light source, false to disable light source. |
void C3D_LightEnvAmbient | ( | C3D_LightEnv * | env, |
float | r, | ||
float | g, | ||
float | b | ||
) |
Sets global ambient lighting.
[out] | env | Pointer to light environment structure. |
[in] | r | Red component. |
[in] | g | Green component. |
[in] | b | Blue component. |
void C3D_LightEnvBind | ( | C3D_LightEnv * | env | ) |
Binds C3D_LightEnv pointer to be used for configuring internal state.
[in] | env | Pointer to light environment structure or NULL to disable the fragment lighting stage altogether. |
void C3D_LightEnvBumpMode | ( | C3D_LightEnv * | env, |
GPU_BUMPMODE | mode | ||
) |
Configures bump map texture properties.
[out] | env | Pointer to light environment structure. |
[in] | mode | Bump map type. Use GPU_BUMP_AS_BUMP to specify normal map, use GPU_BUMP_AS_TANG to specify tangent map, or use GPU_BUMP_NOT_USED to disable bump mapping. |
void C3D_LightEnvBumpNormalZ | ( | C3D_LightEnv * | env, |
bool | enable | ||
) |
Configures whether to use the z component of the normal map.
[out] | env | Pointer to light environment structure. |
[in] | enable | true enables using the z component from the normal map, false enables z component reconstruction from the xy components of the normal map. |
void C3D_LightEnvBumpSel | ( | C3D_LightEnv * | env, |
int | texUnit | ||
) |
Configures bump map texture unit id.
[out] | env | Pointer to light environment structure. |
[in] | texUnit | Id of texture unit the bump texture is bound to (IDs 0 through 2). |
void C3D_LightEnvClampHighlights | ( | C3D_LightEnv * | env, |
bool | clamp | ||
) |
Enables or disables clamping specular highlights.
[out] | env | Pointer to light environment structure. |
[in] | clamp | true to enable clamping specular highlights based on the normal vector, false to disable clamping specular highlights. |
void C3D_LightEnvFresnel | ( | C3D_LightEnv * | env, |
GPU_FRESNELSEL | selector | ||
) |
Enables or disables writing fresnel and shadow alpha component to GPU_FRAGMENT_PRIMARY_COLOR and GPU_FRAGMENT_SECONDARY_COLOR.
[out] | env | Light environment. |
[in] | selector | Output selector, or GPU_NO_FRESNEL to disable writing the alpha component to both GPU_FRAGMENT_PRIMARY_COLOR and GPU_FRAGMENT_SECONDARY_COLOR. |
void C3D_LightEnvInit | ( | C3D_LightEnv * | env | ) |
Resets and initializes C3D_LightEnv structure to default values.
[out] | env | Pointer to light environment structure. |
void C3D_LightEnvLut | ( | C3D_LightEnv * | env, |
GPU_LIGHTLUTID | lutId, | ||
GPU_LIGHTLUTINPUT | input, | ||
bool | negative, | ||
C3D_LightLut * | lut | ||
) |
Uploads pre-calculated lighting lookup table for specified function.
[out] | env | Pointer to light environment structure. |
[in] | lutId | Specify function of the lookup table. |
[in] | input | Specify arguments of the function. |
[in] | negative | If true, the LUT inputs can be read as positive or negative, if false the absolute value of the lut inputs will be used. |
[in] | lut | Pointer to pre-computed lookup table, or NULL to disable the function. |
void C3D_LightEnvMaterial | ( | C3D_LightEnv * | env, |
const C3D_Material * | mtl | ||
) |
Coppies material properties to C3D_LightEnv.
[out] | env | Pointer to light environment structure. |
[in] | mtl | Pointer to material properties structure. |
void C3D_LightEnvShadowMode | ( | C3D_LightEnv * | env, |
u32 | mode | ||
) |
Configures shadow mapping behavior.
[out] | env | Pointer to light environment structure. |
[in] | mode | One or more of the following bitflags, GPU_SHADOW_PRIMARY, GPU_SHADOW_SECONDARY, GPU_INVERT_SHADOW, and GPU_SHADOW_ALPHA. |
void C3D_LightEnvShadowSel | ( | C3D_LightEnv * | env, |
int | texUnit | ||
) |
Configures shadow mapping texture.
[out] | env | Pointer to light environment structure. |
[in] | texUnit | Id of texture unit the shadow texture is bound to (IDs 0 through 2). |
void C3D_LightGeoFactor | ( | C3D_Light * | light, |
int | id, | ||
bool | enable | ||
) |
Enables or disables cock-torrance geometric factor.
[out] | light | Light source structure. |
[in] | id | Geometric factor id. (0 or 1) |
[in] | enable | true to enable geometric factor id, false to disable it. |
int C3D_LightInit | ( | C3D_Light * | light, |
C3D_LightEnv * | env | ||
) |
Adds light to C3D_LightEnv.
[in] | light | Light struct to add to light environment. |
[out] | env | Light environment. |
Configures light position vector.
[out] | light | Light source structure. |
[in] | pos | Position vector. |
void C3D_LightShadowEnable | ( | C3D_Light * | light, |
bool | enable | ||
) |
Enables or disables shadow mapping on light source.
[out] | light | Light source structure. |
[in] | enable | true to enable shadow mapping, false to disable shadow mapping. |
void C3D_LightSpecular0 | ( | C3D_Light * | light, |
float | r, | ||
float | g, | ||
float | b | ||
) |
Configures specular0 lighting color emitted by light source.
[out] | light | Light source structure. |
[in] | r | Red component. |
[in] | g | Green component. |
[in] | b | Blue component. |
void C3D_LightSpecular1 | ( | C3D_Light * | light, |
float | r, | ||
float | g, | ||
float | b | ||
) |
Configures specular1 lighting color emitted by light source.
[out] | light | Light source structure. |
[in] | r | Red component. |
[in] | g | Green component. |
[in] | b | Blue component. |
void C3D_LightSpotDir | ( | C3D_Light * | light, |
float | x, | ||
float | y, | ||
float | z | ||
) |
Configures spot light direction vector for specified light source.
[out] | light | Light source structure. |
[in] | x | X component. |
[in] | y | Y component. |
[in] | z | Z component. |
void C3D_LightSpotEnable | ( | C3D_Light * | light, |
bool | enable | ||
) |
Enables or disables spot light for specified light source.
[out] | light | Light source structure. |
[in] | enable | true to enable spot light, false to disable spot light. |
void C3D_LightSpotLut | ( | C3D_Light * | light, |
C3D_LightLut * | lut | ||
) |
Configures spotlight lookup table.
[out] | light | Light source structure. |
[in] | lut | Pointer to pre-computed lighting lookup table. |
void C3D_LightTwoSideDiffuse | ( | C3D_Light * | light, |
bool | enable | ||
) |
Enables or disables light source.
[out] | light | Light source structure. |
[in] | enable | true to enable two sided lighting (illuminates both the inside and outside of a mesh), false to disable two sided lighting. |