Lights
 
 
 

Creating a Light

Lights in the FBX SDK are abstracted by the KFbxLight class. A KFbxLight is created like any other object in a scene.

By default, a KFbxLight points along a node's negative Y axis.

// Create a node for our light in the scene.
KFbxNode* lLightNode = KFbxNode::Create(pScene, "lightNode");

// Create a light.
KFbxLight* lLight = KFbxLight::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.
KFbxNode* lRootNode = pScene->GetRootNode();
lRootNode->AddChild(lLightNode);
NoteA scene's ambient lighting is defined in its global settings, accessible via KFbxScene::GetGlobalSettings(). Consult the KFbxGlobalSettings class documentation for more information.

Light Type

The behavior of the light can be defined by setting its KFbxLight::LightType property.

// Set the type of the light to a spotlight.
lLight->LightType.Set(KFbxLight::eSPOT);

The following table summarizes the behavior of each light type.

Light Type (KFbxLight::ELightType) Description
KFbxLight::eSPOT

Light spreads in a conical shape from its origin, like a spotlight.

The KFbxLight::InnerAngle and KFbxLight::OuterAngle properties determine the parameters of the cone in degrees.

KFbxLight::ePOINT Light spreads uniformly in all directions from its origin.
KFbxLight::eDIRECTIONAL Light spreads in a cylindrical shape from its origin.

Pointing a Light

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 KFbxNode::SetTarget(). The KFbxMarker node attribute is used in the target node.

// Create a node to contain the marker. This will be our target node.
KFbxNode* lTargetNode = KFbxNode::Create(pScene, "targetNode");

// Create a marker node attribute.
KFbxMarker* lMarker = KFbxMarker::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 KFbxNode 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 KFbxNode::SetPostTargetRotation(). Consult the "Node Target Management" section in the KFbxNode class documentation for more information.

Color and Intensity

A light's color is defined in its KFbxLight::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 KFbxLight::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)

Light Decay

The decay type of the light is defined in its KFbxLight::DecayType property.

// Set the decay type of the light to quadratic decay.
lLight->DecayType.Set(KFbxLight::eQUADRATIC);

The following table summarizes the decay types available.

Decay Type (KFbxLight::EDecayType) Description
KFbxLight::eNONE No decay. The light's intensity will not diminish with distance.
KFbxLight::eLINEAR Linear decay. The light's intensity will diminish linearly with the distance from the light.
KFbxLight::eQUADRATIC Quadratic decay. The light's intensity will diminish with the squared distance from the light. This is the most physically accurate decay rate.
KFbxLight::eCUBIC Cubic decay. The light's intensity will diminish with the cubed distance from the light.

NoteOther distance-based attenuation properties are available such as KFbxLight::EnableNearAttenuation and KFbxLight::EnableFarAttenuation. Consult the KFbxLight class documentation for more information.

Shadows

Shadows are enabled using the KFbxLight::CastShadows boolean property. The color of the light's shadow is defined in the KFbxLight::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 KFbxLight::SetShadowTexture().