Skip to content

Commit

Permalink
Adding support for setting light attenuation in ADF file (#227)
Browse files Browse the repository at this point in the history
Usage: In the light data, set the three normalized variables as

attenuation: {constant: 1.0, linear: 0.0, quadratic: 0.0}
  • Loading branch information
adnanmunawar authored Mar 13, 2024
1 parent 54c466e commit 2d674b6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
8 changes: 8 additions & 0 deletions adf_loader/version_1_0/adf_loader_1_0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,7 @@ bool ADFLoader_1_0::loadLightAttribs(YAML::Node *a_node, afLightAttributes *attr
YAML::Node spotExponentNode = node["spot exponent"];
YAML::Node shadowQualityNode = node["shadow quality"];
YAML::Node cuttOffAngleNode = node["cutoff angle"];
YAML::Node attenuationNode = node["attenuation"];

bool valid = true;

Expand Down Expand Up @@ -1214,6 +1215,13 @@ bool ADFLoader_1_0::loadLightAttribs(YAML::Node *a_node, afLightAttributes *attr
attribs->m_cuttoffAngle = cuttOffAngleNode.as<double>();
}

if (attenuationNode.IsDefined()){
attribs->m_attenuationDefined = true;
if (attenuationNode["constant"].IsDefined()) attribs->m_constantAttenuation = attenuationNode["constant"].as<double>();
if (attenuationNode["linear"].IsDefined()) attribs->m_linearAttenuation = attenuationNode["linear"].as<double>();
if (attenuationNode["quadratic"].IsDefined()) attribs->m_quadraticAttenuation = attenuationNode["quadratic"].as<double>();
}

return valid;
}

Expand Down
8 changes: 8 additions & 0 deletions ambf_framework/afAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -623,10 +623,18 @@ struct afLightAttributes: public afBaseObjectAttributes
afLightAttributes(){
m_spotExponent = 0.7;
m_cuttoffAngle = 0.7;
m_constantAttenuation = 1.0;
m_linearAttenuation = 0.0;
m_quadraticAttenuation = 0.0;
m_attenuationDefined = false;
}

double m_spotExponent;
double m_cuttoffAngle;
double m_constantAttenuation;
double m_linearAttenuation;
double m_quadraticAttenuation;
bool m_attenuationDefined;
afVector3d m_direction;

afShadowQualityType m_shadowQuality;
Expand Down
8 changes: 7 additions & 1 deletion ambf_framework/afFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7216,6 +7216,12 @@ bool afLight::createFromAttribs(afLightAttributes *a_attribs)
m_spotLight->setCutOffAngleDeg(a_attribs->m_cuttoffAngle * (180/3.14));
m_spotLight->setShadowMapEnabled(true);

if (a_attribs->m_attenuationDefined){
m_spotLight->setAttConstant(a_attribs->m_constantAttenuation);
m_spotLight->setAttLinear(a_attribs->m_linearAttenuation);
m_spotLight->setAttQuadratic(a_attribs->m_quadraticAttenuation);
}

switch (a_attribs->m_shadowQuality) {
case afShadowQualityType::NO_SHADOW:
m_spotLight->setShadowMapEnabled(false);
Expand Down Expand Up @@ -8302,7 +8308,7 @@ bool afVolume::createFromAttribs(afVolumeAttributes *a_attribs)
m_voxelObject = new cVoxelObject();
// Setting transparency before setting the texture ensures that the rendering does not show empty spaces as black
// and the depth point cloud is able to see the volume
m_voxelObject->setTransparencyLevel(1.0);
// m_voxelObject->setTransparencyLevel(1.0);

cTexture3dPtr texture = cTexture3d::create();
texture->setImage(m_multiImage);
Expand Down
5 changes: 5 additions & 0 deletions external/chai3d/src/lighting/CSpotLight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ void cSpotLight::renderLightSource(cRenderOptions& a_options)
// set cutoff angle
glLightf(m_glLightNumber, GL_SPOT_CUTOFF, m_cutOffAngleDeg);

// Set Attenuation Constants
glLightf(m_glLightNumber, GL_CONSTANT_ATTENUATION, getAttConstant());
glLightf(m_glLightNumber, GL_LINEAR_ATTENUATION, getAttLinear());
glLightf(m_glLightNumber, GL_QUADRATIC_ATTENUATION, getAttQuadratic());

#endif
}

Expand Down

0 comments on commit 2d674b6

Please sign in to comment.