Graphics Reference
In-Depth Information
It is clear that this approach maps very well to the GPU. Note, however,
that an iteration only permits a single split or merge operation per node. Thus
when more are needed, multiple buffer iterations should be performed. At each
new iteration, we swap the first and second buffer so that the newest hierarchy is
processed by the geometry shader. This strategy is also known as double, or ping-
pong, buffering. In our implementation, a single buffer iteration is performed at
the beginning of each frame.
3.3 Scalable Grids on the GPU
So far, we have only discussed a parallel implementation of a quadtree. In this
section, we present a complete OpenGL pipeline to extract a scalable grid from
this representation, which in turn can be used to render terrains, as well as
parametric surfaces.
3.3.1 LOD Function
Similarly to [Strugar 09], we essentially exploit the quadtree to build the final grid
by drawing multiple copies of a static grid mesh. Each copy is associated with a
node, so that it can be translated and scaled to the correct location. Listing 3.4
shows how the transformations are extracted from the codes and applied to each
vertex of the instanced grid in a vertex shader.
layout ( location =0) in vec2 i_mesh ; // instanced vertices
layout ( location =1) in uint i_node ; // per instance data
// retrieve normalized coordinates and size of the cell
void lt_cell_2_15 ( in uint key , out vec2 p , out float size )
{
uvec2 pos ;
uint level ;
lt_decode_2_15 ( key , level , pos );
size =1.0/ float (1 u << level ); // in [0 ,1]
p = pos ￿ size ; // in [0 ,1)
}
void main () {
vec2 translation ;
float scale ;
// pass on vertex position and scale
lt_cell_2_15 ( i_node , translation , scale );
vec2 p = i_mesh
scale + translation ;
gl_Position = vec4 ( p , scale ,1.0);
}
Listing 3.4. GLSL vertex shader for rendering a scalable grid.
Search WWH ::




Custom Search