Blackhole as background decupled blackhole from anchor.

Fix so that the blackhole can be used as a background to other 3D Objects and there for had to make it so that the blackhole rendering is independet of the camera anchor node
This commit is contained in:
Emil Wallberg
2025-03-31 19:31:43 +02:00
parent 033aee83b9
commit be3a301dc0
3 changed files with 23 additions and 15 deletions
+9 -5
View File
@@ -6,10 +6,10 @@
#include <queue>
namespace {
glm::vec3 cartesianToSpherical(glm::vec3 const& cartesian) {
float radius = glm::length(cartesian);
float theta = std::atan2(glm::sqrt(cartesian.x * cartesian.x + cartesian.y * cartesian.y), cartesian.z);
float phi = std::atan2(cartesian.y, cartesian.x);
glm::vec3 cartesianToSpherical(glm::dvec3 const& cartesian) {
double radius = glm::length(cartesian);
double theta = std::atan2(glm::sqrt(cartesian.x * cartesian.x + cartesian.y * cartesian.y), cartesian.z);
double phi = std::atan2(cartesian.y, cartesian.x);
return glm::vec3(radius, theta, phi);
}
@@ -25,6 +25,10 @@ namespace openspace {
const std::filesystem::path file{ absPath(filePath) };
dataloader::Dataset dataset = dataloader::data::loadFileWithCache(file);
// Clear without deallocating memory
_flatTrees.clear();
_treeStartIndices.clear();
// Convert positions to spherical coordinates
#pragma omp parallel for
for (auto& entry : dataset.entries) {
@@ -69,8 +73,8 @@ namespace openspace {
};
for (size_t i = 0; i < kdTrees.size(); ++i) {
if (kdTrees[i].empty()) continue;
_treeStartIndices.push_back(_flatTrees.size()); // Mark start index of this KD-tree
if (kdTrees[i].empty()) continue;
std::queue<NodeInfo> q;
q.emplace(0, 0, 0, kdTrees[i].size());
@@ -64,7 +64,8 @@ namespace {
namespace openspace {
RenderableBlackHole::RenderableBlackHole(const ghoul::Dictionary& dictionary)
: Renderable(dictionary, { .automaticallyUpdateRenderBin = false }), _solarMass(SolarMassInfo, 4.297e6f), _colorBVMapTexturePath(ColorTextureInfo) {
: Renderable(dictionary), _solarMass(SolarMassInfo, 4.297e6f), _colorBVMapTexturePath(ColorTextureInfo) {
setRenderBin(Renderable::RenderBin::Background);
const Parameters p = codegen::bake<Parameters>(dictionary);
@@ -112,18 +113,16 @@ namespace openspace {
}
void RenderableBlackHole::update(const UpdateData& data) {
if (data.modelTransform.translation != _lastTranslation) {
_starKDTree.build("${BASE}/sync/http/stars_du/6/stars.speck", data.modelTransform.translation, { {0, 25 }, {25, 50}, { 50, 100 } });
_lastTranslation = data.modelTransform.translation;
if (data.modelTransform.translation != _chachedTranslation) {
_chachedTranslation = data.modelTransform.translation;
_starKDTree.build("${BASE}/sync/http/stars_du/6/stars.speck", _chachedTranslation, { {0, 25 }, {25, 50}, { 50, 100 } });
}
_viewport.updateViewGrid(global::renderEngine->renderingResolution());
glm::vec3 cameraPosition = global::navigationHandler->camera()->positionVec3();
glm::vec3 anchorNodePosition = global::navigationHandler->anchorNode()->position();
float distanceToAnchor = glm::distance(cameraPosition, anchorNodePosition) / static_cast<float>(distanceconstants::LightYear);
glm::dvec3 cameraPosition = global::navigationHandler->camera()->positionVec3();
float distanceToAnchor = static_cast<float>(glm::distance(cameraPosition, _chachedTranslation) / distanceconstants::LightYear);
if (abs(_rCamera - distanceToAnchor) > _rs * 0.01) {
_rCamera = distanceToAnchor;
_rEnvmap = 2 * _rCamera;
@@ -137,6 +136,9 @@ namespace openspace {
void RenderableBlackHole::render(const RenderData& renderData, RendererTasks&) {
_program->activate();
bindFramebuffer();
glDisable(GL_DEPTH_TEST);
ghoul::opengl::TextureUnit enviromentUnit;
if (!bindTexture(_uniformCache.environmentTexture, enviromentUnit, _environmentTexture)) {
LWARNING("UniformCache is missing 'environmentTexture'");
@@ -157,7 +159,7 @@ namespace openspace {
interaction::OrbitalNavigator::CameraRotationDecomposition camRot = global::navigationHandler->orbitalNavigator().decomposeCameraRotationSurface(
CameraPose{renderData.camera.positionVec3(), renderData.camera.rotationQuaternion()},
*global::navigationHandler->anchorNode()
*parent()
);
// Calculate the camera planes rotation to make sure fisheye works correcly (dcm in sgct projection.cpp)
@@ -179,6 +181,8 @@ namespace openspace {
drawQuad();
glEnable(GL_DEPTH_TEST);
_program->deactivate();
glBindTexture(GL_TEXTURE_2D, 0);
}
@@ -43,7 +43,7 @@ namespace openspace {
void loadEnvironmentTexture();
ghoul::opengl::ProgramObject* _program = nullptr;
glm::dvec3 _lastTranslation{};
glm::dvec3 _chachedTranslation{};
size_t _rayCount = 1000;
size_t _stepsCount = 50000;
float _stepLength = 0.001f;