Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for setting light attenuation in ADF file #227

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading