Divided uniform cache between Kerr and Schwarzschild

Co-Authored-By: Emil Wallberg <49481622+EmilWallberg@users.noreply.github.com>
This commit is contained in:
Wilhelm Björkström
2025-05-20 14:34:29 +02:00
parent 72cd2bdbe8
commit f4d8da9cb1
2 changed files with 32 additions and 23 deletions

View File

@@ -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<int>(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<int>(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<int>(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);

View File

@@ -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<ghoul::opengl::Texture> _warpTableTex;
std::unique_ptr<ghoul::opengl::Texture> _environmentTexture;
std::unique_ptr<ghoul::opengl::Texture> _colorBVMapTexture;
std::unique_ptr<ghoul::opengl::Texture> _accretionDiskTexture;