Lights in the FBX SDK are abstracted by the FbxLight class. A FbxLight is created like any other object in a scene.
By default, a FbxLight points along a node's negative Y axis.
// Create a node for our light in the scene. FbxNode* lLightNode = FbxNode::Create(pScene, "lightNode"); // Create a light. FbxLight* lLight = FbxLight::Create(pScene, "light"); // Set the node attribute of the light node. lLightNode->SetNodeAttribute(lLight); // Add the light node to the root node in the scene. FbxNode* lRootNode = pScene->GetRootNode(); lRootNode->AddChild(lLightNode);
The behavior of the light can be defined by setting its FbxLight::LightType property.
// Set the type of the light to a spotlight. lLight->LightType.Set(FbxLight::eSpot);
The following table summarizes the behavior of each light type.
Light Type (FbxLight::ELightType) | Description |
---|---|
FbxLight::eSpot | Light spreads in a conical shape from its origin, like a spotlight. The FbxLight::InnerAngle and FbxLight::OuterAngle properties determine the parameters of the cone in degrees. |
FbxLight::ePoint | Light spreads uniformly in all directions from its origin. |
FbxLight::eDirectional | Light spreads in a cylindrical shape from its origin. |
A spotlight or a directional light can be forced to consistently point towards a specific target in the scene. To do this, the light's node must have its target set using FbxNode::SetTarget(). The FbxMarker node attribute is used in the target node.
// Create a node to contain the marker. This will be our target node. FbxNode* lTargetNode = FbxNode::Create(pScene, "targetNode"); // Create a marker node attribute. FbxMarker* lMarker = FbxMarker::Create(pScene, "lightMarker"); // Set the marker as the target node's attribute. lTargetNode->SetNodeAttribute(lMarker); // Set our light node's target. lLightNode->SetTarget(lTargetNode);
By default, a FbxNode uses its positive X axis as the aiming constraint. Recall that a newly created light points along the node's negative Y axis by default. To make the light point along the node's positive X axis, a rotation offset of 90 degrees must be applied to the light's node using FbxNode::SetPostTargetRotation(). Consult the "Node Target Management" section in the FbxNode class documentation for more information.
A light's color is defined in its FbxLight::Color property. The default RGB value of a light is (1.0, 1.0, 1.0), represented as a FbxDouble3.
// Set the light's color to (0, 1, 0.5). lLight->Color.Set(FbxDouble3(0.0, 1.0, 0.5));
The intensity of a light is defined in its FbxLight::Intensity property. The default value of the intensity is 100.0, represented as a FbxDouble1.
// Set the light's intensity to 50.0 lLight->Intensity.Set(50.0)
The decay type of the light is defined in its FbxLight::DecayType property.
// Set the decay type of the light to quadratic decay. lLight->DecayType.Set(FbxLight::eQuadratic);
The following table summarizes the decay types available.
Decay Type (FbxLight::EDecayType) | Description |
---|---|
FbxLight::eNone | No decay. The light's intensity will not diminish with distance. |
FbxLight::eLinear | Linear decay. The light's intensity will diminish linearly with the distance from the light. |
FbxLight::eQuadratic | Quadratic decay. The light's intensity will diminish with the squared distance from the light. This is the most physically accurate decay rate. |
FbxLight::eCubic | Cubic decay. The light's intensity will diminish with the cubed distance from the light. |
Shadows are enabled using the FbxLight::CastShadows boolean property. The color of the light's shadow is defined in the FbxLight::ShadowColor property. The default RGB value of a light's shadow is (0.0, 0.0, 0.0), represented as a FbxDouble3. A shadow texture may also be applied using FbxLight::SetShadowTexture().