I have a problem with my perspective function call. I tried that but my picture looks like black hole at the center. Stretched scene around the center. It show stars in background but stretched away from the center. I tried that commented codes in middle of function call. It worked fine but… Stars in background are clipped out because they are trillion kilometers (miles) away. I tried near and far values (1.0 and 1e10).
I looked at standard perspective formula from OpenGL reference or computer graphics books and tried that. It did not work.
template <typename T> glm::dmat4 perspective(T fov, T aspect, T zNear, T zFar)
{
const T half = fov / static_cast<T>(2.0);
const T ctg = cos(half) / sin(half); // cot(half)
const T zDelta = zFar - zNear;
glm::dmat4 m(1.0);
m[0][0] = ctg / aspect;
m[1][1] = ctg;
// m[2][2] = zFar / (zNear - zFar);
// m[2][3] = static_cast<T>(-1.0);
// m[3][2] = zNear * zFar / (zNear - zFar);
m[2][2] = -(zFar + zNear) / zDelta;
m[2][3] = static_cast<T>(-2.0) * zNear * zFar / zDelta;
m[3][2] = static_cast<T>(-1.0);
m[3][3] = static_cast<T>(0);
return m;
}
Also I tried infinite perspective. It worked fine but local area are clipped out.
// Indefinite perspective for rendering stars
template <typename T> glm::dmat4 infinitePerspective(T fov, T aspect, T zNear)
{
const T angle = fov / static_cast<T>(2.0);
const T ctg = cos(angle) / sin(angle); // cot(angle)
glm::dmat4 m(1.0);
m[0][0] = ctg / aspect;
m[1][1] = ctg;
m[2][2] = static_cast<T>(0.0);
m[2][3] = static_cast<T>(-1.0);
m[3][2] = zNear;
// m[2][2] = static_cast<T>(-1.0);
// m[2][3] = static_cast<T>(-2.0) * zNear;
// m[3][2] = static_cast<T>(-1.0);
return m;
}
Does anyone have any solutions for both perspective function calls?