Add the ability to specify a custom shader for the RenderableGalaxy class

This commit is contained in:
Alexander Bock
2023-09-28 09:40:51 +02:00
parent 38308a4cde
commit 46ed8382e8
6 changed files with 168 additions and 4 deletions
+4 -2
View File
@@ -43,10 +43,12 @@ namespace {
namespace openspace {
GalaxyRaycaster::GalaxyRaycaster(ghoul::opengl::Texture& texture)
GalaxyRaycaster::GalaxyRaycaster(ghoul::opengl::Texture& texture,
std::optional<std::filesystem::path> raycastingShader)
: _boundingBox(glm::vec3(1.f))
, _texture(texture)
, _textureUnit(nullptr)
, _raycastingShader(raycastingShader.value_or(GlslRaycastPath))
{}
void GalaxyRaycaster::initialize() {
@@ -149,7 +151,7 @@ std::string GalaxyRaycaster::boundsFragmentShaderPath() const {
}
std::string GalaxyRaycaster::raycasterPath() const {
return std::string(GlslRaycastPath);
return _raycastingShader.string();
}
std::string GalaxyRaycaster::helperPath() const {
+3 -1
View File
@@ -45,7 +45,8 @@ struct RaycastData;
class GalaxyRaycaster : public VolumeRaycaster {
public:
GalaxyRaycaster(ghoul::opengl::Texture& texture);
GalaxyRaycaster(ghoul::opengl::Texture& texture,
std::optional<std::filesystem::path> raycastingShader = std::nullopt);
~GalaxyRaycaster() override = default;
void initialize();
@@ -87,6 +88,7 @@ private:
float _emissionMultiply = 0.f;
ghoul::opengl::Texture& _texture;
std::unique_ptr<ghoul::opengl::TextureUnit> _textureUnit;
std::filesystem::path _raycastingShader;
}; // GalaxyRaycaster
+11 -1
View File
@@ -175,6 +175,10 @@ namespace {
// [[codegen::verbatim(EmissionMultiplyInfo.description)]]
std::optional<float> emissionMultiply;
// If this value is specified, the default raycasting shader is overwritten and
// the shader found at the provided location is used instead
std::optional<std::filesystem::path> raycastingShader;
enum class [[codegen::map(StarRenderingMethod)]] StarRenderingMethod {
Points,
Billboards
@@ -285,6 +289,7 @@ RenderableGalaxy::RenderableGalaxy(const ghoul::Dictionary& dictionary)
_stepSize = p.stepSizeInfo.value_or(_stepSize);
_absorptionMultiply = p.absorptionMultiply.value_or(_absorptionMultiply);
_emissionMultiply = p.emissionMultiply.value_or(_emissionMultiply);
_raycastingShader = p.raycastingShader.value_or(_raycastingShader);
_starRenderingMethod.addOptions({
{ StarRenderingMethod::Points, "Points" },
@@ -417,7 +422,12 @@ void RenderableGalaxy::initializeGL() {
_texture->setDimensions(_volume->dimensions());
_texture->uploadTexture();
_raycaster = std::make_unique<GalaxyRaycaster>(*_texture);
if (_raycastingShader.empty()) {
_raycaster = std::make_unique<GalaxyRaycaster>(*_texture);
}
else {
_raycaster = std::make_unique<GalaxyRaycaster>(*_texture, _raycastingShader);
}
_raycaster->initialize();
// We no longer need the data
@@ -88,6 +88,7 @@ private:
glm::ivec3 _volumeDimensions = glm::ivec3(0);
std::string _pointsFilename;
std::string _pointSpreadFunctionTexturePath;
std::filesystem::path _raycastingShader;
std::unique_ptr<GalaxyRaycaster> _raycaster;
std::unique_ptr<volume::RawVolume<glm::tvec4<GLubyte>>> _volume;