Skip to content

Commit

Permalink
shader updates
Browse files Browse the repository at this point in the history
  • Loading branch information
swift502 committed Aug 31, 2024
1 parent 9ee96f1 commit a858bf2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
13 changes: 7 additions & 6 deletions src/shaders/fragment_to_equirectangular.glsl
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#version 330

in vec2 fragCoord;
out vec4 fragColor;
uniform sampler2D texture;
uniform sampler2D textureSampler;

#define M_PI 3.1415926535897932
#define M_E 2.7182818284590452
#define M_MAX 1.4844222297453324
const float M_PI = 3.1415926535897932;
const float M_E = 2.7182818284590452;
const float MERC_MAX = 1.4844222297453324;

float remap(float value, float oldMin, float oldMax, float newMin, float newMax)
{
Expand All @@ -15,7 +16,7 @@ float remap(float value, float oldMin, float oldMax, float newMin, float newMax)
vec2 equi_to_merc(float u, float v)
{
// uv to equirectangular
float lon = remap(v, 0, 1, -M_MAX, M_MAX);
float lon = remap(v, 0, 1, -MERC_MAX, MERC_MAX);

// equirectangular to mercator
float y = log(tan(M_PI / 4 + lon / 2));
Expand All @@ -29,5 +30,5 @@ vec2 equi_to_merc(float u, float v)
void main()
{
vec2 uv = equi_to_merc(fragCoord.x, fragCoord.y);
fragColor = texture2D(texture, uv);
fragColor = texture(textureSampler, uv);
}
13 changes: 7 additions & 6 deletions src/shaders/fragment_to_mercator.glsl
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#version 330

in vec2 fragCoord;
out vec4 fragColor;
uniform sampler2D texture;
uniform sampler2D textureSampler;

#define M_PI 3.1415926535897932
#define M_E 2.7182818284590452
#define M_MAX 1.4844222297453324
const float M_PI = 3.1415926535897932;
const float M_E = 2.7182818284590452;
const float MERC_MAX = 1.4844222297453324;

float remap(float value, float oldMin, float oldMax, float newMin, float newMax)
{
Expand All @@ -21,13 +22,13 @@ vec2 merc_to_equi(float u, float v)
float y = 2 * atan(pow(M_E, lon)) - M_PI * 0.5;

// equirectangular to uv
y = remap(y, -M_MAX, M_MAX, 0, 1);
y = remap(y, -MERC_MAX, MERC_MAX, 0, 1);

return vec2(u, y);
}

void main()
{
vec2 uv = merc_to_equi(fragCoord.x, fragCoord.y);
fragColor = texture2D(texture, uv);
fragColor = texture(textureSampler, uv);
}

0 comments on commit a858bf2

Please sign in to comment.