Equirectangular projection mapping problem

Hello,
I’m currently working on a projection mapping project where I need to map 360-degree images onto the walls of a real-world space. I’m using a GLSL shader to sample the colors via the camera’s rays and render them onto the UV coordinates. However, I’m encountering a problem: there’s a visible black line in the sampling results, as shown in the red-circled area in the attached image. It seems like the sampling hasn’t achieved seamless stitching. What could be causing this issue, and how can I resolve it?

Here’s my glsl code:

``````// Example Pixel Shader

// uniform vec4 exampleUniform;
#define M_PI 3.14159265358979
uniform sampler2D tEquirect;
uniform vec4 cameraPos;
uniform vec4 axis;
uniform vec4 uvScale;
out vec4 fragColor;
in vec3 pos;

vec2 worldToEquirectangularUV(vec3 flatCoord) {
vec2 uv = vec2(
atan(flatCoord.x, flatCoord.z),
acos(flatCoord.y)
) / vec2(2.0 * M_PI, M_PI);

return vec2(mod(uv.x, 1.0),1.0- uv.y);
}

vec3 rotateAxis (vec3 pos, vec3 Axis, float rotation)
{
float s = sin(rotation);
float c = cos(rotation);
float one_minus_c = 1.0 - c;

Axis = normalize(Axis);

mat3 rot_mat = mat3(
one_minus_c * Axis.x * Axis.x + c,            one_minus_c * Axis.x * Axis.y - Axis.z * s,     one_minus_c * Axis.z * Axis.x + Axis.y * s,
one_minus_c * Axis.x * Axis.y + Axis.z * s,   one_minus_c * Axis.y * Axis.y + c,              one_minus_c * Axis.y * Axis.z - Axis.x * s,
one_minus_c * Axis.z * Axis.x - Axis.y * s,   one_minus_c * Axis.y * Axis.z + Axis.x * s,     one_minus_c * Axis.z * Axis.z + c
);

return rot_mat * pos;
}

void main()
{
TDCheckDiscard();
vec3 newPos = rotateAxis(pos, vec3(axis.x, axis.y, axis.z), M_PI * 1.5);
vec2 uv = worldToEquirectangularUV(normalize(newPos-cameraPos.xyz));
uv.x -= (uv.x - 0.5) * 0.7 * fract(1.0);
vec4 color = texture(tEquirect, vec2(-mod(uv.x, 1.0), uv.y));
TDAlphaTest(color.a);
fragColor = TDOutputSwizzle(color);
}

``````

Thank you
Best regard.

Hi @RoyLin,

usually this has something to do with the uv coordinates going outside the 0-1 bounds. What are your extend conditions on the material for the texture? Might also help to render out the uv and inspect in detail to find the underlying issue.

cheers
Markus

Hi @snaut
Thanks for your reply. As you mentioned that the problem might be with the UV coordinates, I checked the UV sampling and modified my GLSL code for testing.

I added boundary detection and realized that sampling the UV coordinates was causing edge issues. Here are some tests I conducted:

``````void main()
{
TDCheckDiscard();
vec3 newPos = rotateAxis(pos, vec3(axis.x, axis.y, axis.z), M_PI * 1.5);
vec2 uv = worldToEquirectangularUV(normalize(newPos-cameraPos.xyz));
vec4 color = texture(tEquirect, uv);
vec4 red = vec4(1.0, .0, .0, .5);
vec4 blue = vec4(.0, .0, 1., .5);

if(uv.x >= 0.4999){
color += red;
}
if(uv.x <= -0.4999){
color += blue;
}

TDAlphaTest(color.a);
fragColor = TDOutputSwizzle(color);
}
``````

After testing this behavior, I modified my code as follows and achieved the desired result:

``````#define boundary 0.49

void main()
{
TDCheckDiscard();
vec3 newPos = rotateAxis(pos, vec3(axis.x, axis.y, axis.z), M_PI * 1.5);
vec2 uv = worldToEquirectangularUV(normalize(newPos-cameraPos.xyz));
vec4 color = texture(tEquirect, uv);
if(uv.x >= boundary || uv.x <= -boundary ){
color = texture(tEquirect, vec2(mod(uv.x, 1.0), uv.y));
}
TDAlphaTest(color.a);
fragColor = TDOutputSwizzle(color);
}
``````

But I still don’t know why cause this problem

Thank you,
Best Regards

Roy