Adding static Settings to Renderable (#2578)

* Add settings to Renderable to control whether the renderbin is updated based on Opacity
* Remove duplicate RenderBin specification for RenderableSphere
* Remove unnecessary RenderBin specifications of Lagrange points
* Don't automatically update the renderbin for RenderableLabel and RenderablePlane
* Remove extra `setRenderBinFromOpacity` from RenderableSpheres
* Move information about whether a renderable should be updated when disabled
* Some cleanup of Renderable class
* Don't update the renderbin automatically if the user specified the renderbin manually
This commit is contained in:
Alexander Bock
2023-04-10 20:49:01 +02:00
committed by GitHub
parent bebac26a7f
commit 9022aad479
33 changed files with 72 additions and 76 deletions

View File

@@ -29,7 +29,6 @@ local wmap = {
Texture = textures .. "wmap_ilc_7yr_v4_200uK_RGB_sos.png",
Orientation = "Both",
MirrorTexture = true,
RenderBinMode = "PreDeferredTransparent",
FadeInThreshold = 0.4
},
GUI = {
@@ -55,7 +54,6 @@ local cbe = {
Texture = textures .. "COBErect.png",
Orientation = "Both",
MirrorTexture = true,
RenderBinMode = "PreDeferredTransparent",
FadeInThreshold = 0.4
},
GUI = {
@@ -81,7 +79,6 @@ local planck = {
Texture = textures .. "cmb4k.jpg",
Orientation = "Both",
MirrorTexture = true,
RenderBinMode = "PreDeferredTransparent",
FadeInThreshold = 0.4
},
GUI = {
@@ -107,7 +104,6 @@ local Halpha = {
Opacity = 0.4,
Texture = textures .. "mwHalpha-f.png",
Orientation = "Inside",
RenderBinMode = "PreDeferredTransparent",
MirrorTexture = true,
FadeOutThreshold = 0.025,
Background = true

View File

@@ -26,7 +26,6 @@ local multiverse_planck_1 = {
Texture = textures .. "cmb4k.jpg",
Orientation = "Both",
MirrorTexture = true,
RenderBinMode = "PreDeferredTransparent",
FadeInThreshold = 0.4
},
GUI = {
@@ -56,7 +55,6 @@ local multiverse_planck_2 = {
Texture = textures .. "cmb4k.jpg",
Orientation = "Both",
MirrorTexture = true,
RenderBinMode = "PreDeferredTransparent",
FadeInThreshold = 0.4
},
GUI = {
@@ -86,7 +84,6 @@ local multiverse_planck_3 = {
Texture = textures .. "cmb4k.jpg",
Orientation = "Both",
MirrorTexture = true,
RenderBinMode = "PreDeferredTransparent",
FadeInThreshold = 0.4
},
GUI = {
@@ -116,7 +113,6 @@ local multiverse_planck_4 = {
Texture = textures .. "cmb4k.jpg",
Orientation = "Both",
MirrorTexture = true,
RenderBinMode = "PreDeferredTransparent",
FadeInThreshold = 0.4
},
GUI = {

View File

@@ -21,7 +21,6 @@ local sphere = {
Opacity = 0.35,
Texture = sphereTextures .. "DarkUniverse_mellinger_4k.jpg",
Orientation = "Inside",
RenderBinMode = "PreDeferredTransparent",
MirrorTexture = true,
FadeOutThreshold = 0.0015,
Background = true,

View File

@@ -19,7 +19,6 @@ local object = {
Segments = 40,
Opacity = 0.4,
Texture = textures .. "eso0932a_blend.png",
RenderBinMode = "PreDeferredTransparent",
Orientation = "Inside",
MirrorTexture = true,
FadeOutThreshold = 0.01,

View File

@@ -48,8 +48,7 @@ local JWSTBand = {
Segments = 50,
DisableFadeInOut = true,
Orientation = "Inside",
Opacity = 0.05,
RenderBinMode = "PreDeferredTransparent",
Opacity = 0.05
},
Tag = { "mission_jwst_fov" },
GUI = {

View File

@@ -39,7 +39,6 @@ local L1 = {
Parent = L1Position.Identifier,
Renderable = {
Type = "RenderablePlaneImageLocal",
RenderBinMode = "Opaque",
Billboard = true,
Size = 700E5,
Texture = circle .. "circle.png",

View File

@@ -64,7 +64,6 @@ local L2Small = {
Parent = L2Position.Identifier,
Renderable = {
Type = "RenderablePlaneImageLocal",
RenderBinMode = "Opaque",
Billboard = true,
Size = 400E4,
Texture = circle .. "circle.png",
@@ -82,7 +81,6 @@ local L2 = {
Parent = L2Position.Identifier,
Renderable = {
Type = "RenderablePlaneImageLocal",
RenderBinMode = "Opaque",
Billboard = true,
Size = 700E5,
Texture = circle .. "circle.png",

View File

@@ -39,7 +39,6 @@ local L4 = {
Parent = L4Position.Identifier,
Renderable = {
Type = "RenderablePlaneImageLocal",
RenderBinMode = "Opaque",
Billboard = true,
Size = 800E6,
Texture = circle .. "circle.png",

View File

@@ -39,7 +39,6 @@ local L5 = {
Parent = L5Position.Identifier,
Renderable = {
Type = "RenderablePlaneImageLocal",
RenderBinMode = "Opaque",
Billboard = true,
Size = 800E6,
Texture = circle .. "circle.png",

View File

@@ -19,8 +19,7 @@ local SunGlare = {
Billboard = true,
Texture = textures .. "halo.png",
BlendMode = "Additive",
Opacity = 0.65,
RenderBinMode = "PreDeferredTransparent"
Opacity = 0.65
},
GUI = {
Name = "Sun Glare",

View File

@@ -48,7 +48,7 @@ public:
virtual bool isVisible() const;
/// Returns the full opacity constructed from the _opacity and _fade property values
virtual float opacity() const;
virtual float opacity() const noexcept;
protected:
properties::FloatProperty _opacity;

View File

@@ -55,6 +55,11 @@ class Camera;
class Renderable : public properties::PropertyOwner, public Fadeable {
public:
struct Settings {
bool automaticallyUpdateRenderBin = true;
bool shouldUpdateIfDisabled = false;
};
enum class RenderBin : int {
Background = 1,
Opaque = 2,
@@ -66,7 +71,7 @@ public:
static ghoul::mm_unique_ptr<Renderable> createFromDictionary(
ghoul::Dictionary dictionary);
Renderable(const ghoul::Dictionary& dictionary);
Renderable(const ghoul::Dictionary& dictionary, Settings settings = Settings());
virtual ~Renderable() override = default;
virtual void initialize();
@@ -76,12 +81,12 @@ public:
virtual bool isReady() const = 0;
bool isEnabled() const;
bool shouldUpdateIfDisabled() const;
bool shouldUpdateIfDisabled() const noexcept;
double boundingSphere() const;
double interactionSphere() const;
double boundingSphere() const noexcept;
double interactionSphere() const noexcept;
std::string_view typeAsString() const;
std::string_view typeAsString() const noexcept;
virtual void update(const UpdateData& data);
virtual void render(const RenderData& data, RendererTasks& rendererTask);
@@ -118,15 +123,14 @@ protected:
void setInteractionSphere(double interactionSphere);
void setRenderBinFromOpacity();
void registerUpdateRenderBinFromOpacity();
/// Returns the full opacity constructed from the _opacity and _fade property values
float opacity() const override;
float opacity() const noexcept override;
SceneGraphNode* parent() const noexcept;
bool automaticallyUpdatesRenderBin() const noexcept;
double _boundingSphere = 0.0;
double _interactionSphere = 0.0;
SceneGraphNode* _parent = nullptr;
bool _shouldUpdateIfDisabled = false;
RenderBin _renderBin = RenderBin::Opaque;
// An optional renderbin that renderables can use for certain components, in cases
@@ -134,6 +138,14 @@ protected:
std::optional<RenderBin> _secondaryRenderBin;
private:
void registerUpdateRenderBinFromOpacity();
double _boundingSphere = 0.0;
double _interactionSphere = 0.0;
SceneGraphNode* _parent = nullptr;
const bool _shouldUpdateIfDisabled = false;
bool _automaticallyUpdateRenderBin = true;
// We only want the SceneGraphNode to be able manipulate the parent, so we don't want
// to provide a set method for this. Otherwise, anyone might mess around with our
// parentage and that's no bueno

View File

@@ -92,7 +92,6 @@ RenderableBoxGrid::RenderableBoxGrid(const ghoul::Dictionary& dictionary)
const Parameters p = codegen::bake<Parameters>(dictionary);
addProperty(_opacity);
registerUpdateRenderBinFromOpacity();
_color = p.color.value_or(_color);
_color.setViewOption(properties::Property::ViewOptions::Color);

View File

@@ -135,7 +135,6 @@ RenderableGrid::RenderableGrid(const ghoul::Dictionary& dictionary)
const Parameters p = codegen::bake<Parameters>(dictionary);
addProperty(_opacity);
registerUpdateRenderBinFromOpacity();
_color = p.color.value_or(_color);
_color.setViewOption(properties::Property::ViewOptions::Color);

View File

@@ -117,7 +117,6 @@ RenderableRadialGrid::RenderableRadialGrid(const ghoul::Dictionary& dictionary)
const Parameters p = codegen::bake<Parameters>(dictionary);
addProperty(_opacity);
registerUpdateRenderBinFromOpacity();
_color = p.color.value_or(_color);
_color.setViewOption(properties::Property::ViewOptions::Color);

View File

@@ -94,7 +94,6 @@ RenderableSphericalGrid::RenderableSphericalGrid(const ghoul::Dictionary& dictio
const Parameters p = codegen::bake<Parameters>(dictionary);
addProperty(_opacity);
registerUpdateRenderBinFromOpacity();
_color = p.color.value_or(_color);
_color.setViewOption(properties::Property::ViewOptions::Color);

View File

@@ -238,7 +238,7 @@ documentation::Documentation RenderableLabel::Documentation() {
}
RenderableLabel::RenderableLabel(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
: Renderable(dictionary, { .automaticallyUpdateRenderBin = false })
, _blendMode(BlendModeInfo, properties::OptionProperty::DisplayType::Dropdown)
, _color(ColorInfo, glm::vec3(1.f), glm::vec3(0.f), glm::vec3(1.f))
, _fontSize(FontSizeInfo, 50.f, 1.f, 100.f)
@@ -260,11 +260,10 @@ RenderableLabel::RenderableLabel(const ghoul::Dictionary& dictionary)
const Parameters p = codegen::bake<Parameters>(dictionary);
addProperty(_opacity);
registerUpdateRenderBinFromOpacity();
_blendMode.addOptions({
{ BlendMode::Normal, "Normal" },
{ BlendMode::Additive, "Additive"}
{ BlendMode::Additive, "Additive" }
});
_blendMode.onChange([&]() {
switch (_blendMode) {

View File

@@ -293,7 +293,6 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary)
const Parameters p = codegen::bake<Parameters>(dictionary);
addProperty(_opacity);
registerUpdateRenderBinFromOpacity();
if (p.forceRenderInvisible.has_value()) {
_forceRenderInvisible = *p.forceRenderInvisible;
@@ -690,7 +689,7 @@ void RenderableModel::update(const UpdateData& data) {
glm::compMax(data.modelTransform.scale)
);
// Set Interaction sphere size to be 10% of the bounding sphere
setInteractionSphere(_boundingSphere * 0.1);
setInteractionSphere(boundingSphere() * 0.1);
if (_geometry->hasAnimation() && !_animationStart.empty()) {
double relativeTime;

View File

@@ -181,7 +181,7 @@ RenderableNodeLine::RenderableNodeLine(const ghoul::Dictionary& dictionary)
"Trying to use relative offsets for start node '{}' that has no "
"bounding sphere. This will result in no offset. Use direct "
"values by setting UseRelativeOffsets to false",
_parent->identifier(), _start
parent()->identifier(), _start
));
}
});
@@ -199,7 +199,7 @@ RenderableNodeLine::RenderableNodeLine(const ghoul::Dictionary& dictionary)
"Trying to use relative offsets for end node '{}' that has no "
"bounding sphere. This will result in no offset. Use direct "
"values by setting UseRelativeOffsets to false",
_parent->identifier(), _end
parent()->identifier(), _end
));
}
});
@@ -212,7 +212,7 @@ RenderableNodeLine::RenderableNodeLine(const ghoul::Dictionary& dictionary)
if (!startNode) {
LERROR(fmt::format(
"Error when recomputing node line offsets for scene graph node '{}'. "
"Could not find start node '{}'", _parent->identifier(), _start.value()
"Could not find start node '{}'", parent()->identifier(), _start.value()
));
return;
}
@@ -220,7 +220,7 @@ RenderableNodeLine::RenderableNodeLine(const ghoul::Dictionary& dictionary)
if (!endNode) {
LERROR(fmt::format(
"Error when recomputing node line offsets for scene graph node '{}'. "
"Could not find end node '{}'", _parent->identifier(), _end.value()
"Could not find end node '{}'", parent()->identifier(), _end.value()
));
return;
}
@@ -229,8 +229,10 @@ RenderableNodeLine::RenderableNodeLine(const ghoul::Dictionary& dictionary)
// Recompute previous offsets to relative values
double startBs = startNode->boundingSphere();
double endBs = endNode->boundingSphere();
_startOffset = startBs > 0.0 ? _startOffset / startBs : 0.0;
_endOffset = endBs > 0.0 ? _endOffset / startBs : 0.0;
_startOffset =
static_cast<float>(startBs > 0.0 ? _startOffset / startBs : 0.0);
_endOffset =
static_cast<float>(endBs > 0.0 ? _endOffset / startBs : 0.0);
}
else {
// Recompute relative values to meters

View File

@@ -113,7 +113,7 @@ documentation::Documentation RenderablePlane::Documentation() {
}
RenderablePlane::RenderablePlane(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
: Renderable(dictionary, { .automaticallyUpdateRenderBin = false })
, _blendMode(BlendModeInfo, properties::OptionProperty::DisplayType::Dropdown)
, _billboard(BillboardInfo, false)
, _mirrorBackside(MirrorBacksideInfo, false)
@@ -123,7 +123,6 @@ RenderablePlane::RenderablePlane(const ghoul::Dictionary& dictionary)
Parameters p = codegen::bake<Parameters>(dictionary);
addProperty(_opacity);
registerUpdateRenderBinFromOpacity();
_size = p.size;
_billboard = p.billboard.value_or(_billboard);

View File

@@ -162,7 +162,6 @@ RenderableSphere::RenderableSphere(const ghoul::Dictionary& dictionary)
const Parameters p = codegen::bake<Parameters>(dictionary);
addProperty(_opacity);
registerUpdateRenderBinFromOpacity();
_size = p.size;
_segments = p.segments;
@@ -208,7 +207,6 @@ RenderableSphere::RenderableSphere(const ghoul::Dictionary& dictionary)
addProperty(_disableFadeInDistance);
setBoundingSphere(_size);
setRenderBinFromOpacity();
}
bool RenderableSphere::isReady() const {

View File

@@ -164,7 +164,6 @@ RenderableTimeVaryingSphere::RenderableTimeVaryingSphere(
const Parameters p = codegen::bake<Parameters>(dictionary);
addProperty(_opacity);
registerUpdateRenderBinFromOpacity();
_size = p.size;
_segments = p.segments;
@@ -208,7 +207,6 @@ RenderableTimeVaryingSphere::RenderableTimeVaryingSphere(
}
setBoundingSphere(_size);
setRenderBinFromOpacity();
}
bool RenderableTimeVaryingSphere::isReady() const {

View File

@@ -433,7 +433,7 @@ void RenderableTrail::render(const RenderData& data, RendererTasks&) {
);
const double distance = glm::distance(trailPosWorld, data.camera.eyePositionVec3());
if (distance > _boundingSphere * DISTANCE_CULLING_RADII) {
if (distance > boundingSphere() * DISTANCE_CULLING_RADII) {
return;
}

View File

@@ -189,7 +189,6 @@ RenderableDUMeshes::RenderableDUMeshes(const ghoul::Dictionary& dictionary)
const Parameters p = codegen::bake<Parameters>(dictionary);
addProperty(_opacity);
registerUpdateRenderBinFromOpacity();
_speckFile = absPath(p.file).string();
_hasSpeckFile = true;

View File

@@ -130,7 +130,6 @@ RenderablePoints::RenderablePoints(const ghoul::Dictionary& dictionary)
const Parameters p = codegen::bake<Parameters>(dictionary);
addProperty(_opacity);
registerUpdateRenderBinFromOpacity();
_speckFile = absPath(p.file);

View File

@@ -46,7 +46,7 @@ public:
void render() override;
void update() override;
float opacity() const;
float opacity() const noexcept;
glm::dvec2 fineTuneVector(const glm::dvec2& drag);
bool isInitialized() const;
bool isPointingSpacecraft() const;

View File

@@ -377,7 +377,7 @@ void ScreenSpaceSkyBrowser::setOpacity(float opacity) {
_opacity = opacity;
}
float ScreenSpaceSkyBrowser::opacity() const {
float ScreenSpaceSkyBrowser::opacity() const noexcept {
return _opacity;
}

View File

@@ -96,7 +96,6 @@ RenderableConstellationsBase::RenderableConstellationsBase(
const Parameters p = codegen::bake<Parameters>(dictionary);
addProperty(_opacity);
registerUpdateRenderBinFromOpacity();
// Avoid reading files here, instead do it in multithreaded initialize()
if (p.namesFile.has_value()) {

View File

@@ -541,7 +541,6 @@ RenderableStars::RenderableStars(const ghoul::Dictionary& dictionary)
const Parameters p = codegen::bake<Parameters>(dictionary);
addProperty(_opacity);
registerUpdateRenderBinFromOpacity();
_dataMapping.bvColor = p.dataMapping.bv.value_or("");
_dataMapping.bvColor.onChange([this]() { _dataIsDirty = true; });

View File

@@ -259,7 +259,7 @@ void RenderableTravelSpeed::update(const UpdateData& data) {
}
_targetPosition = _targetNode->worldPosition();
SceneGraphNode* mySGNPointer = _parent;
SceneGraphNode* mySGNPointer = parent();
ghoul_assert(mySGNPointer, "Renderable have to be owned by scene graph node");
_sourcePosition = mySGNPointer->worldPosition();

View File

@@ -161,7 +161,6 @@ RenderableShadowCylinder::RenderableShadowCylinder(const ghoul::Dictionary& dict
const Parameters p = codegen::bake<Parameters>(dictionary);
addProperty(_opacity);
registerUpdateRenderBinFromOpacity();
_numberOfPoints = p.numberOfPoints.value_or(_numberOfPoints);
addProperty(_numberOfPoints);

View File

@@ -75,7 +75,7 @@ bool Fadeable::isVisible() const {
return opacity() > 0.f;
}
float Fadeable::opacity() const {
float Fadeable::opacity() const noexcept {
float fadeFromParent = 1.f;
if (_parentFadeable) {
// Note that we only care about the fade here, not the full opacity of the

View File

@@ -135,20 +135,29 @@ ghoul::mm_unique_ptr<Renderable> Renderable::createFromDictionary(
Renderable::Renderable(const ghoul::Dictionary& dictionary)
Renderable::Renderable(const ghoul::Dictionary& dictionary, Settings settings)
: properties::PropertyOwner({ "Renderable" })
, Fadeable()
, _enabled(EnabledInfo, true)
, _renderableType(RenderableTypeInfo, "Renderable")
, _dimInAtmosphere(DimInAtmosphereInfo, false)
, _shouldUpdateIfDisabled(settings.shouldUpdateIfDisabled)
, _automaticallyUpdateRenderBin(settings.automaticallyUpdateRenderBin)
{
ZoneScoped;
// I can't come up with a good reason not to do this for all renderables
registerUpdateRenderBinFromOpacity();
const Parameters p = codegen::bake<Parameters>(dictionary);
if (p.renderBinMode.has_value()) {
_automaticallyUpdateRenderBin = false;
setRenderBin(codegen::map<Renderable::RenderBin>(*p.renderBinMode));
}
if (_automaticallyUpdateRenderBin) {
ghoul_assert(!p.renderBinMode.has_value(), "Something misfired in constructor");
registerUpdateRenderBinFromOpacity();
}
if (p.tag.has_value()) {
if (std::holds_alternative<std::string>(*p.tag)) {
if (!std::get<std::string>(*p.tag).empty()) {
@@ -184,11 +193,6 @@ Renderable::Renderable(const ghoul::Dictionary& dictionary)
_renderableType = p.type.value_or(_renderableType);
addProperty(_renderableType);
// only used by a few classes such as RenderableTrail and RenderableSphere
if (p.renderBinMode.has_value()) {
setRenderBin(codegen::map<Renderable::RenderBin>(*p.renderBinMode));
}
_dimInAtmosphere = p.dimInAtmosphere.value_or(_dimInAtmosphere);
addProperty(_dimInAtmosphere);
}
@@ -211,7 +215,7 @@ void Renderable::setBoundingSphere(double boundingSphere) {
_boundingSphere = boundingSphere;
}
double Renderable::boundingSphere() const {
double Renderable::boundingSphere() const noexcept {
return _boundingSphere;
}
@@ -219,11 +223,11 @@ void Renderable::setInteractionSphere(double interactionSphere) {
_interactionSphere = interactionSphere;
}
double Renderable::interactionSphere() const {
double Renderable::interactionSphere() const noexcept {
return _interactionSphere;
}
std::string_view Renderable::typeAsString() const {
std::string_view Renderable::typeAsString() const noexcept {
return _renderableType;
}
@@ -273,7 +277,7 @@ bool Renderable::isEnabled() const {
return _enabled;
}
bool Renderable::shouldUpdateIfDisabled() const {
bool Renderable::shouldUpdateIfDisabled() const noexcept {
return _shouldUpdateIfDisabled;
}
@@ -300,9 +304,11 @@ void Renderable::setRenderBinFromOpacity() {
void Renderable::registerUpdateRenderBinFromOpacity() {
_opacity.onChange([this]() { setRenderBinFromOpacity(); });
_fade.onChange([this]() { setRenderBinFromOpacity(); });
_automaticallyUpdateRenderBin = true;
}
float Renderable::opacity() const {
float Renderable::opacity() const noexcept {
// Rendering should depend on if camera is in the atmosphere and if camera is at the
// dark part of the globe
const float dimming = _dimInAtmosphere ?
@@ -311,4 +317,13 @@ float Renderable::opacity() const {
return dimming * Fadeable::opacity();
}
SceneGraphNode* Renderable::parent() const noexcept {
ghoul_assert(dynamic_cast<SceneGraphNode*>(owner()), "Owner is not a SceneGraphNode");
return static_cast<SceneGraphNode*>(owner());
}
bool Renderable::automaticallyUpdatesRenderBin() const noexcept {
return _automaticallyUpdateRenderBin;
}
} // namespace openspace