mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-03-01 09:08:49 -06:00
Feature/orion changes (#1359)
* Changed RenderableModel to allow user-control depth and blending. * Updated RenderableModel to correctly handle the Orion Nebula model. Co-authored-by: Alexander Bock <mail@alexanderbock.eu>
This commit is contained in:
@@ -34,11 +34,11 @@
|
||||
#include <openspace/util/updatestructures.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
#include <openspace/scene/lightsource.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/misc/invariants.h>
|
||||
#include <ghoul/misc/profiling.h>
|
||||
#include <ghoul/opengl/openglstatecache.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
|
||||
@@ -46,11 +46,25 @@ namespace {
|
||||
constexpr const char* ProgramName = "ModelProgram";
|
||||
constexpr const char* KeyGeometry = "Geometry";
|
||||
|
||||
constexpr const std::array<const char*, 12> UniformNames = {
|
||||
constexpr const int DefaultBlending = 0;
|
||||
constexpr const int AdditiveBlending = 1;
|
||||
constexpr const int PointsAndLinesBlending = 2;
|
||||
constexpr const int PolygonBlending = 3;
|
||||
constexpr const int ColorAddingBlending = 4;
|
||||
|
||||
std::map<std::string, int> BlendingMapping = {
|
||||
{ "Default", DefaultBlending },
|
||||
{ "Additive", AdditiveBlending },
|
||||
{ "Points and Lines", PointsAndLinesBlending },
|
||||
{ "Polygon", PolygonBlending },
|
||||
{ "Color Adding", ColorAddingBlending }
|
||||
};
|
||||
|
||||
constexpr const std::array<const char*, 13> UniformNames = {
|
||||
"opacity", "nLightSources", "lightDirectionsViewSpace", "lightIntensities",
|
||||
"modelViewTransform", "normalTransform", "projectionTransform",
|
||||
"performShading", "texture1", "ambientIntensity", "diffuseIntensity",
|
||||
"specularIntensity"
|
||||
"specularIntensity", "opacityBlending"
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo AmbientIntensityInfo = {
|
||||
@@ -102,6 +116,24 @@ namespace {
|
||||
"Light Sources",
|
||||
"A list of light sources that this model should accept light from."
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo DisableDepthTestInfo = {
|
||||
"DisableDepthTest",
|
||||
"Disable Depth Test",
|
||||
"Disable Depth Testing for the Model."
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo BlendingOptionInfo = {
|
||||
"BledingOption",
|
||||
"Blending Options",
|
||||
"Debug option for blending colors."
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo EnableOpacityBlendingInfo = {
|
||||
"EnableOpacityBlending",
|
||||
"Enable Opacity Blending",
|
||||
"Enable Opacity Blending."
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
@@ -177,7 +209,25 @@ documentation::Documentation RenderableModel::Documentation() {
|
||||
}),
|
||||
Optional::Yes,
|
||||
LightSourcesInfo.description
|
||||
}
|
||||
},
|
||||
{
|
||||
DisableDepthTestInfo.identifier,
|
||||
new BoolVerifier,
|
||||
Optional::Yes,
|
||||
DisableDepthTestInfo.description
|
||||
},
|
||||
{
|
||||
BlendingOptionInfo.identifier,
|
||||
new StringVerifier,
|
||||
Optional::Yes,
|
||||
BlendingOptionInfo.description
|
||||
},
|
||||
{
|
||||
EnableOpacityBlendingInfo.identifier,
|
||||
new BoolVerifier,
|
||||
Optional::Yes,
|
||||
EnableOpacityBlendingInfo.description
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -196,6 +246,12 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary)
|
||||
glm::dmat3(1.0)
|
||||
)
|
||||
, _rotationVec(RotationVecInfo, glm::dvec3(0.0), glm::dvec3(0.0), glm::dvec3(360.0))
|
||||
, _enableOpacityBlending(EnableOpacityBlendingInfo, false)
|
||||
, _disableDepthTest(DisableDepthTestInfo, false)
|
||||
, _blendingFuncOption(
|
||||
BlendingOptionInfo,
|
||||
properties::OptionProperty::DisplayType::Dropdown
|
||||
)
|
||||
, _lightSourcePropertyOwner({ "LightSources", "Light Sources" })
|
||||
{
|
||||
documentation::testSpecificationAndThrow(
|
||||
@@ -235,6 +291,10 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary)
|
||||
_performShading = dictionary.value<bool>(ShadingInfo.identifier);
|
||||
}
|
||||
|
||||
if (dictionary.hasKey(DisableDepthTestInfo.identifier)) {
|
||||
_disableDepthTest = dictionary.value<bool>(DisableDepthTestInfo.identifier);
|
||||
}
|
||||
|
||||
if (dictionary.hasKey(DisableFaceCullingInfo.identifier)) {
|
||||
_disableFaceCulling = dictionary.value<bool>(DisableFaceCullingInfo.identifier);
|
||||
}
|
||||
@@ -252,14 +312,13 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
addPropertySubOwner(_lightSourcePropertyOwner);
|
||||
|
||||
addProperty(_ambientIntensity);
|
||||
addProperty(_diffuseIntensity);
|
||||
addProperty(_specularIntensity);
|
||||
addProperty(_performShading);
|
||||
addProperty(_disableFaceCulling);
|
||||
addProperty(_disableDepthTest);
|
||||
addProperty(_modelTransform);
|
||||
addProperty(_rotationVec);
|
||||
|
||||
@@ -271,6 +330,29 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary)
|
||||
if (dictionary.hasKey(RotationVecInfo.identifier)) {
|
||||
_rotationVec = dictionary.value<glm::vec3>(RotationVecInfo.identifier);
|
||||
}
|
||||
|
||||
_blendingFuncOption.addOption(DefaultBlending, "Default");
|
||||
_blendingFuncOption.addOption(AdditiveBlending, "Additive");
|
||||
_blendingFuncOption.addOption(PointsAndLinesBlending, "Points and Lines");
|
||||
_blendingFuncOption.addOption(PolygonBlending, "Polygon");
|
||||
_blendingFuncOption.addOption(ColorAddingBlending, "Color Adding");
|
||||
|
||||
addProperty(_blendingFuncOption);
|
||||
|
||||
if (dictionary.hasKey(BlendingOptionInfo.identifier)) {
|
||||
const std::string blendingOpt = dictionary.value<std::string>(
|
||||
BlendingOptionInfo.identifier
|
||||
);
|
||||
_blendingFuncOption.set(BlendingMapping[blendingOpt]);
|
||||
}
|
||||
|
||||
if (dictionary.hasKey(DisableDepthTestInfo.identifier)) {
|
||||
_enableOpacityBlending = dictionary.value<bool>(
|
||||
EnableOpacityBlendingInfo.identifier
|
||||
);
|
||||
}
|
||||
|
||||
addProperty(_enableOpacityBlending);
|
||||
}
|
||||
|
||||
bool RenderableModel::isReady() const {
|
||||
@@ -384,11 +466,35 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) {
|
||||
_program->setUniform(_uniformCache.diffuseIntensity, _diffuseIntensity);
|
||||
_program->setUniform(_uniformCache.specularIntensity, _specularIntensity);
|
||||
_program->setUniform(_uniformCache.performShading, _performShading);
|
||||
_program->setUniform(_uniformCache.opacityBlending, _enableOpacityBlending);
|
||||
|
||||
if (_disableFaceCulling) {
|
||||
glDisable(GL_CULL_FACE);
|
||||
}
|
||||
|
||||
glEnablei(GL_BLEND, 0);
|
||||
switch (_blendingFuncOption) {
|
||||
case DefaultBlending:
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
break;
|
||||
case AdditiveBlending:
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
break;
|
||||
case PointsAndLinesBlending:
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
break;
|
||||
case PolygonBlending:
|
||||
glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE);
|
||||
break;
|
||||
case ColorAddingBlending:
|
||||
glBlendFunc(GL_SRC_COLOR, GL_DST_COLOR);
|
||||
break;
|
||||
};
|
||||
|
||||
if (_disableDepthTest) {
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
ghoul::opengl::TextureUnit unit;
|
||||
unit.activate();
|
||||
_program->setUniform(_uniformCache.texture, unit);
|
||||
@@ -401,6 +507,12 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) {
|
||||
glEnable(GL_CULL_FACE);
|
||||
}
|
||||
|
||||
global::renderEngine->openglStateCache().resetBlendState();
|
||||
|
||||
if (_disableDepthTest) {
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
_program->deactivate();
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,8 @@
|
||||
#define __OPENSPACE_MODULE_BASE___RENDERABLEMODEL___H__
|
||||
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
#include <openspace/properties/optionproperty.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/properties/matrix/dmat4property.h>
|
||||
#include <openspace/properties/matrix/mat3property.h>
|
||||
#include <openspace/properties/scalar/boolproperty.h>
|
||||
@@ -79,11 +80,15 @@ private:
|
||||
properties::DMat4Property _modelTransform;
|
||||
properties::Vec3Property _rotationVec;
|
||||
|
||||
properties::BoolProperty _disableDepthTest;
|
||||
properties::BoolProperty _enableOpacityBlending;
|
||||
properties::OptionProperty _blendingFuncOption;
|
||||
|
||||
ghoul::opengl::ProgramObject* _program = nullptr;
|
||||
UniformCache(opacity, nLightSources, lightDirectionsViewSpace, lightIntensities,
|
||||
modelViewTransform, normalTransform, projectionTransform,
|
||||
performShading, texture, ambientIntensity, diffuseIntensity,
|
||||
specularIntensity) _uniformCache;
|
||||
specularIntensity, opacityBlending) _uniformCache;
|
||||
|
||||
std::vector<std::unique_ptr<LightSource>> _lightSources;
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ uniform float diffuseIntensity = 1.0;
|
||||
uniform float specularIntensity = 1.0;
|
||||
|
||||
uniform bool performShading = true;
|
||||
uniform bool opacityBlending = false;
|
||||
|
||||
uniform sampler2D texture1;
|
||||
|
||||
@@ -46,6 +47,10 @@ uniform float opacity = 1.0;
|
||||
const vec3 SpecularAlbedo = vec3(1.0);
|
||||
|
||||
Fragment getFragment() {
|
||||
if (opacity == 0.0) {
|
||||
discard;
|
||||
}
|
||||
|
||||
vec3 diffuseAlbedo = texture(texture1, vs_st).rgb;
|
||||
|
||||
Fragment frag;
|
||||
@@ -84,12 +89,22 @@ Fragment getFragment() {
|
||||
frag.color.rgb = diffuseAlbedo;
|
||||
}
|
||||
|
||||
frag.color.a = opacity;
|
||||
if (opacityBlending) {
|
||||
// frag.color.a = opacity * (frag.color.r + frag.color.g + frag.color.b)/3.0;
|
||||
frag.color.a = opacity * max(max(frag.color.r, frag.color.g), frag.color.b);
|
||||
}
|
||||
else {
|
||||
frag.color.a = opacity;
|
||||
}
|
||||
|
||||
if (frag.color.a < 0.1) {
|
||||
discard;
|
||||
}
|
||||
|
||||
frag.depth = vs_screenSpaceDepth;
|
||||
frag.gPosition = vs_positionCameraSpace;
|
||||
frag.gNormal = vec4(vs_normalViewSpace, 0.0);
|
||||
frag.disableLDR2HDR = true;
|
||||
|
||||
|
||||
return frag;
|
||||
}
|
||||
Reference in New Issue
Block a user