Maryann Simmons and Dave Shreinerâ. Silicon Graphics, Inc. Figure 1: LOD shader for a watermelon: There are 3 discrete levels that are blended on a ...
Per-Pixel Smooth Shader Level of Detail Maryann Simmons and Dave Shreiner∗ Silicon Graphics, Inc.
Figure 1:
LOD shader for a watermelon: There are 3 discrete levels that are blended on a per-pixel level. The highest level shader has diffuse, specular, and ambient computations, and various calculations to construct the stripes and add noise (about 40 lines of high level ISL code including 5 texture accesses). The noise calculations are faded out, then the lighting, reducing the computation and texture needs at each level. The final shader is a single, constant operation.
Programmable hardware fragment shaders are subject to resource limitations, restricting the complexity of the shader, or number of shaded objects that can be rendered at interactive rates. In graphics, there is a rich tradition of Level of Detail (LOD) techniques for geometric models [Akenine-Moller and Haines 2002]. Similarly, shader LOD [Olano and Kuehne 2002], has recently been shown to improve performance when using shaders. Three important aspects illustrated by geometric LOD techniques are relevant: 1) the definition/generation of appropriate shaders for each level of detail, 2) the choice of LOD at run-time, 3) smooth transitioning between levels to avoid distracting “popping” effects.This sketch investigates per-pixel shader LOD for interactive applications. The focus here is on the latter two aspects presented above. A prototype solution is presented using the OpenGL Shader framework (which evolved from [Peercy et al. 2000]). In OpenGL Shader, shaders can be hand-crafted or generated automatically by the compiler to peform LOD with a series of if-else statements that switch between the levels based on a user-defined run-time parameter (usually distance from the viewer). There are two problems with this base technique: first, the same level is used for the entire object, instead of per-pixel level selection; and second, the transitions between levels are sharp, resulting in visual artifacts. In this sketch we present a solution that produces smooth transitions between levels, and finer grain level selection. Figure 1 shows an example. If the shader has access to the sampling rate at each pixel, it can use this information to choose which LOD to use, and to blend smoothly between levels. The derivation of sampling rate for an arbitrary shader is difficult, and the shader may not have sufficient information to calculate derivatives. If the shader, however, is structured as a procedural texture generator, we can assign texture coordinates to the vertices of the object being shaded, along with proxy texture(s) that approximate the sampling rate of the shader. We then utilize MIP-mapping hardware to determine the appropriate LOD and blend factor, all on a per-pixel basis. OpenGL Shader’s high-level language (ISL) supports conditional if-else blocks, as well as per-pixel framebuffer queries. We construct a proxy MIP texture where the base (most detailed) level contains the value 1.0 at each pixel, at a resolution that approximates the desired shader sampling rate. The subsequent MIP levels interpolate smoothly down to 0.0. The LOD parameter (e.g. distance value) used to choose the LOD level is replaced by a query of the proxy MIP texture. With MIP inter-level linear interpolation, the MIP value will vary smoothly between levels, and therefore can ∗ e-mail:
be used as a scale value to transition to the next LOD. To avoid the cost in the transition phases of blending two complete levels, we organize the shader sequentially as a base low-level shader plus a series of detail δ operations that build up the desired appearance. The fractional MIP proxy value is used to smoothly blend in the δ effect of the next level during the transition phase. Many shaders map easily to this type of layered building up of detail.
Figure 2: On the left, the example wood shader has as the lowest complexity level a solid brown color, then grain detail is added in, and finally noise and highlights. On the right, per-pixel LOD values are color-coded to show the smooth transition from high detail (red) to medium (green) to low (blue). Note how the level is not just distancebased : the top of the table is viewed at an angle and is therefore at a lower level. This prototype implementation suggests numerous avenues of further work. Currently we instrument the shaders by hand, but this could be incorporated into the existing automatic compilerbased framework. The implementation presented is based on multiple-passes of the fixed-function OpenGL pipeline. On going work involves implementing per-pixel smooth shader LOD on programmable graphics hardware, and investigating possible future hardware designs to optimize this task. Combined geometric/shader LOD is also an interesting research topic.
References A KENINE -M OLLER , T., AND H AINES , E. 2002. Real-time Rendering, second ed. AK Peters. O LANO , M., AND K UEHNE , B. 2002. SGI OpenGL Shader levelof-detail shader white paper. Tech. rep., SGI. P EERCY, M. S., O LANO , M., A IREY, J., AND U NGAR , P. J. 2000. Interactive multi-pass programmable shading. In Proceedings of SIGGRAPH 2000, Computer Graphics Proceedings, Annual Conference Series, ACM, 425–432.
{maryanns,shreiner}@sgi.com
Copyright held by the author
1