Add a priority parameter to SGLight

In the future this will help choose which lights should be displayed if
the user sets the maximum number of lights to a low enough value.
This commit is contained in:
Fernando García Liñán
2021-01-26 13:41:51 +01:00
parent 3b1eb4a7f7
commit b04cdbc491
3 changed files with 26 additions and 9 deletions

View File

@@ -51,15 +51,23 @@ SGLight::appendLight(const SGPropertyNode *configNode,
if((p = configNode->getNode("type")) != NULL) {
std::string type = p->getStringValue();
if (type == "point")
light->setType(SGLight::Type::POINT);
light->setType(SGLight::POINT);
else if (type == "spot")
light->setType(SGLight::Type::SPOT);
light->setType(SGLight::SPOT);
else
SG_LOG(SG_GENERAL, SG_ALERT, "ignoring unknown light type '" << type << "'");
}
light->setRange(configNode->getFloatValue("range-m"));
std::string priority = configNode->getStringValue("priority", "low");
if (priority == "high")
light->setPriority(SGLight::HIGH);
else if (priority == "medium")
light->setPriority(SGLight::MEDIUM);
else
light->setPriority(SGLight::LOW);
#define SGLIGHT_GET_COLOR_VALUE(n) \
osg::Vec4(configNode->getFloatValue(n "/r"), \
configNode->getFloatValue(n "/g"), \
@@ -166,7 +174,8 @@ SGLight::appendLight(const SGPropertyNode *configNode,
SGLight::SGLight() :
_type(Type::POINT),
_range(0.0f)
_range(0.0f),
_priority(Priority::LOW)
{
// Default values taken from osg::Light
// They don't matter anyway as they are overwritten by the XML config values

View File

@@ -30,6 +30,12 @@ public:
SPOT
};
enum Priority {
LOW,
MEDIUM,
HIGH
};
class UpdateCallback : public osg::NodeCallback {
public:
UpdateCallback(const SGExpressiond *expression,
@@ -106,6 +112,9 @@ public:
void setSpotCutoff(float spot_cutoff) { _spot_cutoff = spot_cutoff; }
float getSpotCutoff() const { return _spot_cutoff; }
void setPriority(Priority priority) { _priority = priority; }
Priority getPriority() const { return _priority; }
protected:
virtual ~SGLight();
@@ -122,6 +131,8 @@ protected:
float _quadratic_attenuation;
float _spot_exponent;
float _spot_cutoff;
Priority _priority;
};
typedef std::vector<osg::ref_ptr<SGLight>> SGLightList;

View File

@@ -191,8 +191,7 @@ ClusteredShading::update(const SGLightList &light_list)
// The parenthesis are very important: if the vector is
// multiplied by the local to world matrix first we'll have
// precision issues
(osg::computeLocalToWorld(light->getParentalNodePaths()[0]) *
_camera->getViewMatrix());
(light->getWorldMatrices()[0] * _camera->getViewMatrix());
point.range = light->getRange();
_point_bounds.push_back(point);
@@ -200,11 +199,9 @@ ClusteredShading::update(const SGLightList &light_list)
SpotlightBound spot;
spot.light = light;
spot.position = osg::Vec4f(0.0f, 0.0f, 0.0f, 1.0f) *
(osg::computeLocalToWorld(light->getParentalNodePaths()[0]) *
_camera->getViewMatrix());
(light->getWorldMatrices()[0] * _camera->getViewMatrix());
spot.direction = osg::Vec4f(0.0f, 0.0f, -1.0f, 0.0f) *
(osg::computeLocalToWorld(light->getParentalNodePaths()[0]) *
_camera->getViewMatrix());
(light->getWorldMatrices()[0] * _camera->getViewMatrix());
spot.direction.normalize();
float range = light->getRange();