|
| 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.
|
| |
|
| 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.
Fragment Light Equations
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:
- \(a\) - Distance attenuation factor calculated from distance attenuation LUT.
- \(N\) - Interpolated normal
- \(V\) - View direction vector (fragment <-> camera)
- \(T\) - Tangent direction vector
Inputs, per-pass:
- \(d_{0...4}\) - Configurable LUT inputs - one of the following: \(N \cdot H\), \(V \cdot H_i\), \(N \cdot V\), \(L_i \cdot N\), \(-L_i \cdot P\), \(\cos \phi_i\).
- \(s^{(a)}\) - Scene ambient color
- \(o\) - Shadow attenuation from the shadow map (if there is one). Output is selectable using C3D_LightEnvShadowMode().
- \(h\) - Clamps lighting for \(N \cdot L_i < 0\) if C3D_LightEnvClampHighlights() is enabled
Inputs, per-Light:
- \(P_i\) - Spotlight direction
- \(L_i\) - Light vector (just lightPosition when positional lighting is enabled, lightPosition + view when directional lighting is enabled)
- \(H_i\) - Half-vector between \(L_i\) and \(V\)
- \(\phi_i\) - Angle between the projection of \(H_i\) into the tangent plane and \(T\)
- \(f_i\) - Clamps product of \(N \cdot L_i\) to zero if C3D_LightTwoSideDiffuse() is disabled for the light source, otherwise gets the absolute value
- \(l_i^{(a)}\) - Light ambient color
- \(l_i^{(d)}\) - Light diffuse color
- \(l_i^{(s_0)}\) - Light specular0 color
- \(l_i^{(s_1)}\) - Light specular1 color
- \(G_i^{(0)},G_i^{(1)}\) - Cook-Torrance geometric factor, or 1 when disabled
In citro3d, some inputs may be configured by multiple variables, for example:
- \(s^{(a)}\) = mtl.emission + mtl.ambient * env.ambient
- \(l_i^{(a)}\) = mtl.ambient * light.ambient
- \(l_i^{(d)}\) = mtl.diffuse * light.diffuse
- \(l_i^{(s_0)}\) = mtl.specular0 * light.specular0
- \(l_i^{(s_1)}\) = mtl.specular1 * light.specular1
- See also
- https://github.com/PabloMK7/citra/blob/baca2bfc6bd0af97ce74b911d69af2391815c9d7/src/video_core/renderer_software/sw_lighting.cpp#L26-L332