Hi guys,
This is not strickly a games related question but I was hoping that some of you with more experience than me might be able to shed some light on why I am getting the following results.
Using Opengl, I was able to generate capture the depth of a scene around a viewer location and generate a flat rendering of this scene after using spherical coordinates to sample a previously generated cubemap containing the depth information of a scene.
The result was the resulting image,
At a first glance looks exactly what I was after. However, when this image (containing depths) is differentiated numerically in both the vertical and horizontal direction respectively, we get some artifacts,
You can see at the bottom how it appears to pick up the seams of the cubemap. These will be more or less obvious depending on the viewpoint location. I made sure that glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS)
was included before sampling the cubemap.
My goal is to produce a rendering where each pixel contains the depth of a regular fixed azimuth and pitch. Sampling of the previously created cubemap is done using spherical coordinates (I am using the following fragment shader).
#version 440 core
uniform vec2 display_size;
uniform vec2 offset; // current viewer's camera yaw and pitch
uniform vec2 fov;
uniform samplerCube cube;
out float color;
void main()
{
// Calculate angles used for sampling
float u = (gl_FragCoord.x / display_size.x) * 2 - 1;
float v = (gl_FragCoord.y / display_size.y) * 2 - 1;
float theta = u * radians(fov.x/2) + radians(offset.x);
float phi = v * radians(fov.y/2) + radians(offset.y);
// make sure that phi is between [-89.9, 89.9]
phi = clamp(phi, radians(-89.9), radians(89.9));
// calculate sampling coordinates
vec3 dir;
dir.x = -cos(phi) * cos(theta);
dir.y = sin(phi);
dir.z = cos(phi) * sin(theta);
color = texture(cube, dir).r;
}
Could this due to the sampling scheme I am using? (I do not think so as it appears to be sampling smoothly across the cubemap faces. Artifacts only appear when three faces are used, specifically the bottom Y- face). Is there anyway to resolve this?
Any comments, suggestions will be very welcome!!
Thanks,
M.