mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-25 13:58:55 -05:00
Moved spherical coordinates conversion to shader.
Co-Authored-By: Emil Wallberg <49481622+EmilWallberg@users.noreply.github.com>
This commit is contained in:
@@ -35,18 +35,15 @@ namespace openspace {
|
||||
|
||||
std::vector<float> data(screenSize.x * screenSize.y * 2, 0.0f);
|
||||
|
||||
float z = -1.0f;
|
||||
|
||||
for (int i = 0; i < screenSize.y; i++) {
|
||||
float y = (i - screenSize.y / 2) * stepSize;
|
||||
for (int j = 0; j < screenSize.x; j++) {
|
||||
float x = (j - screenSize.x / 2) * stepSize;
|
||||
|
||||
float theta = atan2(sqrt(x * x + y * y) , z);
|
||||
float phi = atan2(y, x);
|
||||
|
||||
int index = (screenSize.x * i + j) * 2;
|
||||
data[index] = phi;
|
||||
data[index + 1] = theta;
|
||||
|
||||
data[index] = x;
|
||||
data[index + 1] = y;
|
||||
}
|
||||
}
|
||||
updateViewGridTexture(data, screenSize);
|
||||
|
||||
@@ -5,6 +5,7 @@ uniform sampler2D enviromentTexture;
|
||||
uniform sampler2D viewGrid;
|
||||
|
||||
const float PI = 3.1415926535897932384626433832795f;
|
||||
const float VIEWGRIDZ = -1.0f;
|
||||
|
||||
vec2 sphereToUV(vec2 sphereCoords){
|
||||
float u = sphereCoords.x / (2.0f * PI) + 0.5f;
|
||||
@@ -13,10 +14,28 @@ vec2 sphereToUV(vec2 sphereCoords){
|
||||
return vec2(u, v);
|
||||
}
|
||||
|
||||
float atan2(float a, float b){
|
||||
if (b != 0.0f) return atan(a, b);
|
||||
if (a > 0.0f) return PI / 2.0f;
|
||||
if (a < 0.0f) return -PI / 2.0f;
|
||||
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
vec2 cartisianToSphereical(vec2 cartisian) {
|
||||
float theta = atan(sqrt(cartisian.x * cartisian.x + cartisian.y * cartisian.y) , VIEWGRIDZ);
|
||||
float phi = atan2(cartisian.y, cartisian.x);
|
||||
|
||||
return vec2(phi, theta);
|
||||
}
|
||||
|
||||
Fragment getFragment() {
|
||||
Fragment frag;
|
||||
vec2 sphereCoords = texture(viewGrid, TexCoord).rg;
|
||||
vec4 texColor = texture(enviromentTexture, sphereToUV(sphereCoords));
|
||||
vec2 cartisianCoords = texture(viewGrid, TexCoord).xy;
|
||||
vec2 sphereicaleCoords = cartisianToSphereical(cartisianCoords);
|
||||
vec2 uv = sphereToUV(sphereicaleCoords);
|
||||
|
||||
vec4 texColor = texture(enviromentTexture, uv);
|
||||
|
||||
frag.color = texColor;
|
||||
return frag;
|
||||
|
||||
Reference in New Issue
Block a user