From f4d8da9cb1a39e61ddce9dd2cc4fcd3e5ed78c2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wilhelm=20Bj=C3=B6rkstr=C3=B6m?= <143391787+Grantallkotten@users.noreply.github.com> Date: Tue, 20 May 2025 14:34:29 +0200 Subject: [PATCH] Divided uniform cache between Kerr and Schwarzschild Co-Authored-By: Emil Wallberg <49481622+EmilWallberg@users.noreply.github.com> --- .../rendering/renderableblackhole.cpp | 48 +++++++++++-------- .../blackhole/rendering/renderableblackhole.h | 7 +-- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/modules/blackhole/rendering/renderableblackhole.cpp b/modules/blackhole/rendering/renderableblackhole.cpp index 6d5186fe04..84f2fc898f 100644 --- a/modules/blackhole/rendering/renderableblackhole.cpp +++ b/modules/blackhole/rendering/renderableblackhole.cpp @@ -55,7 +55,7 @@ namespace { "StarMapRanges", "Star Map Ranges", "temp description", - openspace::properties::Property::Visibility::User + openspace::properties::Property::Visibility::AdvancedUser }; constexpr openspace::properties::Property::PropertyInfo ColorTextureInfo = { @@ -173,9 +173,10 @@ namespace openspace { } void RenderableBlackHole::deinitializeGL() { - _warpTableTex = nullptr; _environmentTexture = nullptr; _viewport.viewGrid = nullptr; + _accretionDiskTexture = nullptr; + _colorBVMapTexture = nullptr; for (const auto& [_, config] : RenderableBlackHole::BlackHoleShaderConfigs) { BaseModule::ProgramObjectManager.release(config.programName); } @@ -248,6 +249,7 @@ namespace openspace { glDisable(GL_DEPTH_TEST); + ghoul::opengl::TextureUnit enviromentUnit; if (!bindTexture(_uniformCache.environmentTexture, enviromentUnit, _environmentTexture)) { LWARNING("UniformCache is missing 'environmentTexture'"); @@ -262,14 +264,7 @@ namespace openspace { LWARNING("UniformCache is missing 'colorBVMap'"); } - if (_blackholeType.value() == static_cast(BlackHoleType::kerr)) { - ghoul::opengl::TextureUnit accretionDiskUnit; - if (!bindTexture(_uniformCache.accretionDisk, accretionDiskUnit, _accretionDiskTexture)) { - LWARNING("UniformCache is missing 'accretionDisk'"); - } - } - - SendSchwarzschildTableToShader(); + SendLookupTableToShader(); if (_starKDTree.isDirty) { SendStarKDTreeToShader(); @@ -290,28 +285,31 @@ namespace openspace { if (_blackholeType.value() == static_cast(BlackHoleType::kerr)) { _program->setUniform( - _uniformCache.cameraRotationMatrix, + _uniformKerrCache.cameraRotationMatrix, glm::mat4(glm::mat4_cast(camRot.globalRotation * camRot.localRotation)) * CameraPlaneRotation ); + + ghoul::opengl::TextureUnit accretionDiskUnit; + if (!bindTexture(_uniformKerrCache.accretionDisk, accretionDiskUnit, _accretionDiskTexture)) { + LWARNING("UniformCache is missing 'accretionDisk'"); + } } if (_blackholeType.value() == static_cast(BlackHoleType::schwarzschild)) { _program->setUniform( - _uniformCache.cameraRotationMatrix, + _uniformSchwarzschildCache.cameraRotationMatrix, glm::mat4(glm::mat4_cast(camRot.localRotation)) * CameraPlaneRotation ); _program->setUniform( - _uniformCache.worldRotationMatrix, + _uniformSchwarzschildCache.worldRotationMatrix, glm::mat4(glm::mat4_cast(camRot.globalRotation)) ); - if (_uniformCache.r_0 != -1) { - _program->setUniform( - _uniformCache.r_0, - _rCamera - ); - } + _program->setUniform( + _uniformSchwarzschildCache.r_0, + _rCamera + ); } drawQuad(); @@ -322,7 +320,7 @@ namespace openspace { glBindTexture(GL_TEXTURE_2D, 0); } - void RenderableBlackHole::SendSchwarzschildTableToShader() + void RenderableBlackHole::SendLookupTableToShader() { glBindBuffer(GL_SHADER_STORAGE_BUFFER, _ssboBlackHoleWarpTable); @@ -396,6 +394,16 @@ namespace openspace { throw ghoul::RuntimeError("Shader program creation failed", "setupShaders"); } + switch (bhType) + { + case BlackHoleType::kerr: + ghoul::opengl::updateUniformLocations(*_program, _uniformKerrCache); + break; + default: + ghoul::opengl::updateUniformLocations(*_program, _uniformSchwarzschildCache); + break; + } + ghoul::opengl::updateUniformLocations(*_program, _uniformCache); bindSSBOData(_program, "ssbo_warp_table", _ssboBlackHoleDataBinding, _ssboBlackHoleWarpTable); diff --git a/modules/blackhole/rendering/renderableblackhole.h b/modules/blackhole/rendering/renderableblackhole.h index e98384f033..9f0decb711 100644 --- a/modules/blackhole/rendering/renderableblackhole.h +++ b/modules/blackhole/rendering/renderableblackhole.h @@ -38,7 +38,7 @@ namespace openspace { static documentation::Documentation Documentation(); private: - void SendSchwarzschildTableToShader(); + void SendLookupTableToShader(); void SendStarKDTreeToShader(); void bindSSBOData(ghoul::opengl::ProgramObject* program, const std::string& ssboName, @@ -118,9 +118,10 @@ namespace openspace { GLuint _ssboStarKDTree = 0; GLuint _ssboStarKDTreeIndices = 0; - UniformCache(environmentTexture, viewGrid, worldRotationMatrix, cameraRotationMatrix, colorBVMap, r_0, accretionDisk) _uniformCache; + UniformCache(environmentTexture, viewGrid, colorBVMap) _uniformCache; + UniformCache(worldRotationMatrix, cameraRotationMatrix, r_0) _uniformSchwarzschildCache; + UniformCache(cameraRotationMatrix, accretionDisk) _uniformKerrCache; - std::unique_ptr _warpTableTex; std::unique_ptr _environmentTexture; std::unique_ptr _colorBVMapTexture; std::unique_ptr _accretionDiskTexture;