Alex Rivera | Logout

Rendering infinitely large plane

Asked 2012-10-18T23:15:52.873
18

I want to render a plane so that it looks as if it goes to infinity in all directions. I want the plane boundary in the distance to be the horizon.

Using a simple mesh does not work - the computer can't render infinitely many triangles. Even if this was possible, the camera frustum would cut out the distant polygons and create a gap between the plane boundary and the horizon.

A workaround is to compute the horizon mathematically: finding points on the plane, which also lie on the plane at infinity. Connecting these points and two corners of the viewport creates a trapezoid which represents the sought plane. However, this way the plane can not be lit properly, or applied a texture, or anything else which requires a fine triangulation...

Edit
Report

1 Answer

24

You can draw an infinite plane using the standard rasterization pipeline. The homogeneous coordinates it uses can represent "ideal" points (otherwise known as vanishing points or points at infinity) just as happily as regular Euclidean points, and likewise it is perfectly practical to set up a projection matrix which places the far plane at infinity.

A simple way to do this would be to use one triangle per quadrant, as follows:

vertices [x,y,z,w], for drawing an (x,y) coordinate plane, at (z==0):
  0: [ 0, 0, 0, 1 ]
  1: [ 1, 0, 0, 0 ]
  2: [ 0, 1, 0, 0 ]
  3: [-1, 0, 0, 0 ]
  4: [ 0,-1, 0, 0 ]

draw 4 triangles using indices:
  (0,1,2); (0,2,3); (0,3,4); (0,4,1)

If you want a test pattern (like an infinite checkerboard), you will have to deal with the fact that stretching your triangles to infinity will distort any standard texture. However, you can write a pixel shader that determines the color based on the actual 3D point (i.e., use x and y from the worldspace (x,y,z) coordinates), ignoring the (distorted) texture coords altogether.

You could choose between two constant colors based on parity (for a checkerboard), or tile a texture by sampling it based on the fractional part of your chosen coordinates.


Note that OpenGL's clip space is [-1..1] for each of x, y, and z. You can compute the appropriate projection matrix by evaluating the limits as far clip distance f increases without bound:

clip coords: [x]  =  [ n/r             ]  * view coords [x]
             [y]     [     n/t         ]                [y]
             [z]     [          -1 -2n ]                [z]
             [w]     [          -1   0 ]                [w]

Where (as in the link): n is the near clip plane, r is half the frustum width a

answered 2012-10-19T00:24:29.117

Your Answer