Applying viewMatrix to the blackhole camera plane

Co-Authored-By: Emil Wallberg <49481622+EmilWallberg@users.noreply.github.com>
This commit is contained in:
Wilhelm Björkström
2025-02-28 13:56:08 +01:00
parent 7ba7875ba7
commit e6a477c8d2
4 changed files with 18 additions and 7 deletions

View File

@@ -36,6 +36,7 @@ namespace openspace {
void RenderableBlackHole::initialize() {
_viewport = ViewPort(global::navigationHandler->camera());
global::navigationHandler->camera()->setRotation(glm::dquat(0,0,0,0));
cuda_test();
}
@@ -71,6 +72,11 @@ namespace openspace {
if (!bindTexture(_uniformCache.viewGrid, viewGridUnit, _viewport.viewGrid)) {
LWARNING("UniformCache is missing 'viewGrid'");
}
_program->setUniform(
_uniformCache.cameraRotationMatrix,
glm::mat4(global::navigationHandler->camera()->combinedViewMatrix())
);
drawQuad();

View File

@@ -40,7 +40,7 @@ private:
GLuint _quadVao = 0;
GLuint _quadVbo = 0;
UniformCache(enviromentTexture, viewGrid) _uniformCache;
UniformCache(enviromentTexture, viewGrid, cameraRotationMatrix) _uniformCache;
std::unique_ptr<ghoul::opengl::Texture> _enviromentTexture;
};

View File

@@ -18,7 +18,7 @@ namespace openspace {
std::unique_ptr<ghoul::opengl::Texture> viewGrid;
private:
Camera* _camera = nullptr;
float fovHorizontel = glm::radians(120.f);
float fovHorizontel = glm::radians(90.f);
};
} // namespace openspace

View File

@@ -3,6 +3,7 @@ in vec2 TexCoord;
uniform sampler2D enviromentTexture;
uniform sampler2D viewGrid;
uniform mat4 cameraRotationMatrix;
const float PI = 3.1415926535897932384626433832795f;
const float VIEWGRIDZ = -1.0f;
@@ -22,8 +23,8 @@ float atan2(float a, float b){
return 0.0f;
}
vec2 cartisianToSphereical(vec2 cartisian) {
float theta = atan(sqrt(cartisian.x * cartisian.x + cartisian.y * cartisian.y) , VIEWGRIDZ);
vec2 cartisianToSphereical(vec3 cartisian) {
float theta = atan2(sqrt(cartisian.x * cartisian.x + cartisian.y * cartisian.y) , cartisian.z);
float phi = atan2(cartisian.y, cartisian.x);
return vec2(phi, theta);
@@ -31,12 +32,16 @@ vec2 cartisianToSphereical(vec2 cartisian) {
Fragment getFragment() {
Fragment frag;
vec2 cartisianCoords = texture(viewGrid, TexCoord).xy;
vec2 sphereicaleCoords = cartisianToSphereical(cartisianCoords);
vec4 cartisianCoords = normalize(vec4(texture(viewGrid, TexCoord).xy, VIEWGRIDZ, 0.0f));
cartisianCoords = cameraRotationMatrix * cartisianCoords;
vec2 sphereicaleCoords = cartisianToSphereical(cartisianCoords.xyz);
vec2 uv = sphereToUV(sphereicaleCoords);
vec4 texColor = texture(enviromentTexture, uv);
frag.color = texColor;
return frag;
}