Extracting frustum planes from modelview-projection matrix

Extracting viewing frustum planes from the modelview-projection matrix

In this post I’m going to explain how to extract the parameters of each frustum plane in the local space of the object with a certain modelview-projection matrix. Knowing the frustum planes may be useful in some cases. The first one that comes to my mind is to perform frustum culling, which I will explain soon in a separated post.

Continue reading

Anti-aliased lines in OpenGL

In order to draw smooth (anti-aliased) lines in OpenGL, some things must be taken into account:

  • Blending during rendering must be enabled
  • An specific blending function must be explicitly defined
  • Line smoothing must also be enabled
  • In some cases, the proper hint for line smoothing should be specified

The following code are the OpenGL calls needed to obtain anti-aliased rendering of lines:

1
2
3
4
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

In the next image one can see the difference between drawing lines with and without anti-aliasing:

Comparison between non-antialiased lines and antialiased lines

Pixel position reconstruction

Sometimes we need to know, in a fragment program, a pixel’s position in eye space. We usually need this in postprocessing operations, where we will tipically send an eye-facing quad filling the whole screen, executing an specific fragment program along with information about the scene (usually textures that contain surface normals, depth, materials, etc) that has been previously rendered in a previous pass.

So, during this postprocessing step, each fragment belonging to this quad corresponds to a little area on the surface of the previously rendered scene, although by now we only know its position within the eye-facing quad being rendered.

The question is: Which was its exact position in the scene in eye space?
Continue reading