mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-03 18:19:38 -06:00
Enable Screenspace renderable to have a multiplicative color; Add new asset to show a target marker (closes #85); Fix bug with wrong documentation shown in RenderablePlane
This commit is contained in:
19
data/assets/util/add_marker.asset
Normal file
19
data/assets/util/add_marker.asset
Normal file
@@ -0,0 +1,19 @@
|
||||
local icons = asset.syncedResource({
|
||||
Name = "Icons",
|
||||
Type = "HttpSynchronization",
|
||||
Identifier = "icons",
|
||||
Version = 1
|
||||
})
|
||||
|
||||
asset.onInitialize(function()
|
||||
openspace.addScreenSpaceRenderable({
|
||||
Identifier = "target-marker",
|
||||
Name = "Target Marker",
|
||||
Type = "ScreenSpaceImageLocal",
|
||||
TexturePath = icons .. '/target.png'
|
||||
})
|
||||
end)
|
||||
|
||||
asset.onDeinitialize(function()
|
||||
openspace.removeScreenSpaceRenderable('target-marker');
|
||||
end)
|
||||
@@ -104,11 +104,12 @@ protected:
|
||||
properties::Vec3Property _localRotation;
|
||||
|
||||
properties::FloatProperty _scale;
|
||||
properties::Vec3Property _multiplyColor;
|
||||
properties::FloatProperty _opacity;
|
||||
properties::TriggerProperty _delete;
|
||||
|
||||
glm::ivec2 _objectSize = glm::ivec2(0);
|
||||
UniformCache(alpha, modelTransform, viewProj, texture) _uniformCache;
|
||||
UniformCache(color, alpha, modelTransform, viewProj, texture) _uniformCache;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _shader;
|
||||
};
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace {
|
||||
// [[codegen::verbatim(BlendModeInfo.description)]]
|
||||
std::optional<BlendMode> blendMode;
|
||||
|
||||
// [[codegen::verbatim(BlendModeInfo.description)]]
|
||||
// [[codegen::verbatim(MultiplyColorInfo.description)]]
|
||||
std::optional<glm::vec3> multiplyColor [[codegen::color()]];
|
||||
};
|
||||
#include "renderableplane_codegen.cpp"
|
||||
|
||||
@@ -75,8 +75,6 @@ RenderablePlaneImageOnline::RenderablePlaneImageOnline(
|
||||
const Parameters p = codegen::bake<Parameters>(dictionary);
|
||||
|
||||
_texturePath.onChange([this]() { _textureIsDirty = true; });
|
||||
addProperty(_texturePath);
|
||||
|
||||
_texturePath = p.url;
|
||||
addProperty(_texturePath);
|
||||
}
|
||||
|
||||
@@ -81,8 +81,8 @@ ScreenSpaceImageOnline::ScreenSpaceImageOnline(const ghoul::Dictionary& dictiona
|
||||
setIdentifier(std::move(identifier));
|
||||
|
||||
_texturePath.onChange([this]() { _textureIsDirty = true; });
|
||||
addProperty(_texturePath);
|
||||
_texturePath = p.url.value_or(_texturePath);
|
||||
addProperty(_texturePath);
|
||||
}
|
||||
|
||||
ScreenSpaceImageOnline::~ScreenSpaceImageOnline() {} // NOLINT
|
||||
|
||||
@@ -29,13 +29,13 @@ in vec2 vs_st;
|
||||
in vec4 vs_position;
|
||||
|
||||
uniform sampler2D texture1;
|
||||
uniform float Alpha;
|
||||
uniform vec3 MultiplyColor = vec3(1.0, 1.0, 1.0);
|
||||
uniform float Alpha = 1.0;
|
||||
|
||||
Fragment getFragment() {
|
||||
Fragment frag;
|
||||
|
||||
frag.color = texture(texture1, vs_st);
|
||||
frag.color.a = Alpha * frag.color.a;
|
||||
frag.color = texture(texture1, vs_st) * vec4(MultiplyColor, Alpha);
|
||||
if (frag.color.a == 0.0) {
|
||||
discard;
|
||||
}
|
||||
|
||||
@@ -42,8 +42,8 @@
|
||||
#include <variant>
|
||||
|
||||
namespace {
|
||||
constexpr const std::array<const char*, 4> UniformNames = {
|
||||
"Alpha", "ModelTransform", "ViewProjectionMatrix", "texture1"
|
||||
constexpr const std::array<const char*, 5> UniformNames = {
|
||||
"MultiplyColor", "Alpha", "ModelTransform", "ViewProjectionMatrix", "texture1"
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo EnabledInfo = {
|
||||
@@ -100,6 +100,12 @@ namespace {
|
||||
"An euler rotation (x, y, z) to apply to the plane."
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo MultiplyColorInfo = {
|
||||
"MultiplyColor",
|
||||
"Multiply Color",
|
||||
"If set, the plane's texture is multiplied with this color. "
|
||||
"Useful for applying a color grayscale images."
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo OpacityInfo = {
|
||||
"Opacity",
|
||||
@@ -245,6 +251,9 @@ namespace {
|
||||
// [[codegen::verbatim(UsePerspectiveProjectionInfo.description)]]
|
||||
std::optional<bool> usePerspectiveProjection;
|
||||
|
||||
// [[codegen::verbatim(MultiplyColorInfo.description)]]
|
||||
std::optional<glm::vec3> multiplyColor [[codegen::color()]];
|
||||
|
||||
// [codegen::verbatim(OpacityInfo.description)]]
|
||||
std::optional<float> opacity [[codegen::inrange(0.f, 1.f)]];
|
||||
|
||||
@@ -324,6 +333,7 @@ ScreenSpaceRenderable::ScreenSpaceRenderable(const ghoul::Dictionary& dictionary
|
||||
glm::vec3(glm::pi<float>())
|
||||
)
|
||||
, _scale(ScaleInfo, 0.25f, 0.f, 2.f)
|
||||
, _multiplyColor(MultiplyColorInfo, glm::vec3(1.f), glm::vec3(0.f), glm::vec3(1.f))
|
||||
, _opacity(OpacityInfo, 1.f, 0.f, 1.f)
|
||||
, _delete(DeleteInfo)
|
||||
{
|
||||
@@ -355,9 +365,14 @@ ScreenSpaceRenderable::ScreenSpaceRenderable(const ghoul::Dictionary& dictionary
|
||||
});
|
||||
|
||||
addProperty(_scale);
|
||||
addProperty(_multiplyColor);
|
||||
addProperty(_opacity);
|
||||
addProperty(_localRotation);
|
||||
|
||||
|
||||
_multiplyColor = p.multiplyColor.value_or(_multiplyColor);
|
||||
_multiplyColor.setViewOption(properties::Property::ViewOptions::Color);
|
||||
|
||||
_enabled = p.enabled.value_or(_enabled);
|
||||
_useRadiusAzimuthElevation =
|
||||
p.useRadiusAzimuthElevation.value_or(_useRadiusAzimuthElevation);
|
||||
@@ -554,6 +569,7 @@ void ScreenSpaceRenderable::draw(glm::mat4 modelTransform) {
|
||||
|
||||
_shader->activate();
|
||||
|
||||
_shader->setUniform(_uniformCache.color, _multiplyColor);
|
||||
_shader->setUniform(_uniformCache.alpha, _opacity);
|
||||
_shader->setUniform(_uniformCache.modelTransform, modelTransform);
|
||||
|
||||
@@ -576,8 +592,6 @@ void ScreenSpaceRenderable::draw(glm::mat4 modelTransform) {
|
||||
unbindTexture();
|
||||
}
|
||||
|
||||
void ScreenSpaceRenderable::unbindTexture() {
|
||||
}
|
||||
|
||||
void ScreenSpaceRenderable::unbindTexture() {}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user