I finally fixed the impostor bug. The formula i used was wrong, i was not calculating the frustum field of view angle correctly. It was a bit tricky to understand why, but revising my trigonometry helped a bit. For those interesting, the code looks like this: for a viewer position located at ViewPos, the impostored object being represented as its bounding sphere Center, Radius,
float d = distance(ViewPos, Center)
float fov = asin(Radius / d)
float l = d * tan(fov)
matrix4x4 viewMatrix = buildLookAtMatrix(ViewPos, Center)
viewMatrix = buildTranslateMatrix(-ViewPos) * viewMatrix.transpose()
matrix4x4 projMatrix = buildProjectionMatrix(fov, 1, znear, zfar)
matrix4x4 worldMatrix = buildIdentityMatrix()
To render the impostor, set your camera properties to projMatrix (the argument 1.0 is the aspect ratio, it's 1.0 since the impostor texture is square), viewMatrix and worldMatrix and render your object in a texture.
To display the object as a textured quad, use this:
matrix4x4 rotMatrix = buildLookAtMatrix(ViewPos, Center)
vector3d xAxis = vector3d(l, 0, 0) * rotMatrix
vector3d yAxis = vector3d(0, l, 0) * rotMatrix
vector3d vertex0 = -xAxis - yAxis + Center;
vector3d vertex1 = xAxis - yAxis + Center;
vector3d vertex2 = xAxis + yAxis + Center;
vector3d vertex3 = -xAxis + yAxis + Center;
The quad being defined by (vertex0, vertex1, vertex2, vertex3) with tex coords (0, 0), (1, 0), (1, 1) and (0, 1) respectively.