So I have successfully generated a cubemap containing the rendering of a scene. I am interested in the user to be able to generate a flat rendering of the scene ‘captured’ on the cubemap. The user is allowed to specify the following information:
- Where they are looking towards, i.e orientation (yaw) and pitch angles
- A horizontal angular range (e.g. 120 degrees)
- A vertical angular range (e.g. 60 degrees)
I am using the following fragment shader to generate to sample my cubemap in order to great this flat rendering,
#version 440 core
uniform vec2 display_size;
uniform vec2 offset;
uniform float hrange;
uniform float vrange;
uniform samplerCube cube;
out float color;
void main()
{
// scale coordinates (0,1)
vec2 scaleCoord = gl_FragCoord.xy / display_size;
// convert offset to radians
vec2 off = vec2(radians(offset.x), radians(offset.y));
// center the view
vec2 angles = ((scaleCoord * 2.0) - vec2(1.0)) * vec2(radians(hrange/2), radians(vrange/2)) + off;
// sampling vector
vec3 samplingVec = vec3(-cos(angles.y) * cos(angles.x), sin(angles.y), cos(angles.y) * sin(angles.x));
// output
color = texture(cube, samplingVec).r;
}
I am creating my sampling using spherical coordinates. My results appear to be okay, except when I choose a largervertical angular range or when the pitch angle is small (or negative). Then I start getting gaps in the bottom (as if I was running out of cubemap to sample), see below. Is this a problem with my sampling? Is it because of the near plane? Is there a way I could avoid this result??
Any comments or ideas to resolve this are welcome!
Thanks,
M.