add option to override model rendered color

This commit is contained in:
Joakim Kilby
2025-05-08 15:28:51 +02:00
parent 574b26c3ea
commit 4eccc99c7e
3 changed files with 42 additions and 0 deletions

View File

@@ -223,6 +223,20 @@ namespace {
openspace::properties::Property::Visibility::AdvancedUser
};
constexpr openspace::properties::Property::PropertyInfo UseOverrideColorInfo = {
"UseOverrideColor",
"Use Override Color",
"Wether or not to render model with a single color.",
openspace::properties::Property::Visibility::AdvancedUser
};
constexpr openspace::properties::Property::PropertyInfo OverrideColorInfo = {
"OverrideColor",
"Override Color",
"The single color to use for entire model (RGBA).",
openspace::properties::Property::Visibility::AdvancedUser
};
struct [[codegen::Dictionary(RenderableModel)]] Parameters {
// The file or files that should be loaded in this RenderableModel. The file can
// contain filesystem tokens. This specifies the model that is rendered by
@@ -353,6 +367,12 @@ namespace {
std::optional<std::string> lightSource;
std::optional<std::string> shadowGroup;
// [[codegen::verbatim(UseOverrideColorInfo.description)]]
std::optional<bool> useOverrideColor;
// [[codegen::verbatim(OverrideColorInfo.description)]]
std::optional<glm::vec4> overrideColor;
};
#include "renderablemodel_codegen.cpp"
} // namespace
@@ -396,6 +416,8 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary)
properties::OptionProperty::DisplayType::Dropdown
)
, _lightSourcePropertyOwner({ "LightSources", "Light Sources" })
, _useOverrideColor(UseOverrideColorInfo, false)
, _overrideColor(OverrideColorInfo, glm::vec4(0, 0, 0, 1))
{
const Parameters p = codegen::bake<Parameters>(dictionary);
@@ -515,6 +537,8 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary)
_castShadow = p.castShadow.value_or(_castShadow);
_lightSource = p.lightSource.value_or("");
_shadowGroup = p.shadowGroup.value_or("");
_useOverrideColor = p.useOverrideColor.value_or(_useOverrideColor);
_overrideColor = p.overrideColor.value_or(_overrideColor);
addProperty(_enableAnimation);
addPropertySubOwner(_lightSourcePropertyOwner);
@@ -532,6 +556,8 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary)
addProperty(_pivot);
addProperty(_rotationVec);
addProperty(_useCache);
addProperty(_useOverrideColor);
addProperty(_overrideColor);
addProperty(_modelScale);
_modelScale.setExponent(20.f);
@@ -1059,6 +1085,11 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) {
}
}
_program->setUniform("has_override_color", _useOverrideColor);
if (_useOverrideColor) {
_program->setUniform("override_color", _overrideColor);
}
if (!_shouldRenderTwice) {
// Reset manual depth test
_program->setUniform(

View File

@@ -33,6 +33,7 @@
#include <openspace/properties/scalar/boolproperty.h>
#include <openspace/properties/scalar/floatproperty.h>
#include <openspace/properties/vector/vec3property.h>
#include <openspace/properties/vector/vec4property.h>
#include <ghoul/misc/managedmemoryuniqueptr.h>
#include <ghoul/io/model/modelreader.h>
#include <ghoul/opengl/uniformcache.h>
@@ -124,6 +125,8 @@ private:
properties::BoolProperty _castShadow;
std::string _lightSource;
std::string _shadowGroup;
properties::BoolProperty _useOverrideColor;
properties::Vec4Property _overrideColor;
bool _autoSizeFrustum = false;

View File

@@ -67,6 +67,8 @@ uniform bool has_shadow_depth_map;
uniform sampler2D shadow_depth_map;
in vec4 lightspace_position;
uniform bool has_override_color;
uniform vec4 override_color;
Fragment getFragment() {
Fragment frag;
@@ -199,5 +201,11 @@ Fragment getFragment() {
}
frag.color.a = diffuseAlbedo.a * opacity;
if (has_override_color) {
frag.color = override_color;
}
// frag.color = frag.color * 0.00000000000000000000001 + override_color ;
return frag;
}