Real-Time Shadow Volume Algorithm for Subdivision Surface Based Models Min Tang1, Jin-Xiang Dong1, and Shang-Ching Chou2 1
College of Computer Science, Zhejiang University, 310027, Hangzhou, China {tang_m, djx} @zju.edu 2 Computer Science Department, Wichita State University, 67260-0083, Wichita, KS, USA
[email protected]
Abstract. This paper presents a purely hardware-accelerated shadow volume algorithm for subdivision surface based models. By introducing SP (subdivision patterns), all procedures, including subdivision evaluation, silhouette extraction, shadow volume generation, and shadow rendering are executed on GPU (Graphics Process Units) efficiently. This not only alleviates the burden of CPU, but also guarantees the consistency of data among different processing stages. This also makes it possible to integrate some special effects imposed by other shaders, e.g., displacement mapping or vertex texturing, with the shadow volume algorithm. Experiments show that the algorithm is efficient, robust, and can be easily extended to other subdivision schemes and parametric surfaces.
1 Introduction Shadows emphasize the direction of light source, make the related position of objects obvious, and enhance the reality of scenes. The shadow algorithms can be categorized mainly into two groups: shadow mapping and the shadow volume techniques. The shadow mapping method [1] is an image space algorithm. Its accuracy/resolution is limited by the size of the shadow map. The shadow volume algorithm was first proposed by Crow [2] and is an object space algorithm. For its high accuracy, it has become the de factor standard of shadow generation algorithms. With the gradual evolution of graphics hardware, many researchers have made improvements on the shadow volumes algorithm to boost its efficiency and to enhance its robustness. The shadow volumes algorithm is composed by following stages: silhouette extraction, shadow volume generation, stencil buffer updating, and shadow rendering based on the stencil buffer. In [3], the Z-Fail algorithm is used to overcome the disturbance caused by the font clipping plane which occurs frequently in the Z-Pass algorithm, and a twosided stencil test is taken to improve the efficiency of stencil buffer updating. Currently, all the extensions of the original shadow volume algorithm are mainly focus on dealing with polygonal models, the curved models defined by parametric surfaces or subdivision surfaces have to be converted to facet models before being processed. H.-P. Seidel, T. Nishita, and Q. Peng (Eds.): CGI 2006, LNCS 4035, pp. 538 – 545, 2006. © Springer-Verlag Berlin Heidelberg 2006
Real-Time Shadow Volume Algorithm for Subdivision Surface Based Models
539
Our contribution: We use Subdivision Pattern (SP) as a tool to build a purely hardware-accelerated shadow volume algorithm for subdivision surface based models. By using SPs, the whole pipeline, including subdivision surface evaluation, silhouette extraction, shadow volume generation, and shadowed scene rendering, are fulfilled on GPU. The only data needs transferred from CPU to GPU are the control meshes. No read-back is needed. All the data used in the difference stages are stored on GPU. This not only ensures the data consistency, but also avoids the communication latency between CPU and GPU. Another benefit of our method is that other special effects imposed by GPU shaders, e.g., displacement mapping or vertex texturing, can be integrated naturally and efficiently. This is hard for previous methods. Organization: We first review the related work in Section 2. Then we present an overview of our shadow algorithm (Section 3). As an important component of our algorithm, the silhouette extraction method on GPU is discussed in Section 4. A comparison with previous GPU based silhouette extraction methods will also be made in this Section. Then the shadow volume generation method is presented in Section 5. The implementation details and some experiment results will be presented in Section 6. Conclusions are drawn in Sections 7.
2 Related Work With the maturation of modern GPU, especially its programmability, researchers are striving to implement the whole lifecycle of the shadow volume algorithm on graphics hardware. In [4], the stages including silhouette extraction and shadow volume generation, which are formally implemented on CPU, have been integrated into a purely hardware-accelerated algorithm. But for lacking a fast data read-back mechanism from GPU to CPU, its efficiency is limited. Paper [5] presents an implementation of the shadow volume algorithm on GPU using Cg. All the edges are drawn as degenerated quadrangles. In a vertex shader, silhouette edges are identified, and the corresponding quadrangles are extended to shadow volumes. It can render shadowed scenes at an interactive speed. [6] presents a good survey about shadow volume algorithms, and also discusses some implementation details with OpenGL and DirectX. All the above methods focus on polygonal models. For curved models, they must be facetted before being processed. Subdivision surfaces are widely used in Computer Graphics and Computer Animation fields. Subdivision surfaces have been used as a primitive in many graphics applications. So it makes sense to study the real-time shadow volume algorithm for subdivision surface based models. Recently many works are focus on subdivision on GPU. Then the resultant can be directly used for rendering [7, 8, 9]. In [10], a mesh refinement method using vertex shaders is proposed. By using the local information on vertices, the PN surfaces can be implemented on various graphics hardware. But it is hard to further processing on the refined data.
3 Overview Modern GPU is fast at processing stream data, i.e. at executing the same function on every element of the input data set and produce an output data set. On a stream
540
M. Tang et al.
processor, the function is called “Kernel”, and the data set is called “stream”. For our application and many other GPGPU applications, it is beneficial to make abstractions on the concepts likes vertices, pixels or fragments. It will simplify our design; make the design comprehensible and easy for implementation and extension. Fig. 1 shows the Kernels we have used:
Subdivision Surface Evaluator
Silhouette Marker
Silhouette Extractor
Shadow Volume Generator
Fig. 1. The Kernel chain involved
1. Subdivision surface evaluator evaluates the input subdivision surfaces based on Subdivision Patterns and produces a vertex texture containing limit positions. 2. Silhouette marker determines the silhouettes and marks them into a flag texture. 3. Silhouette extractor extracts the silhouettes from the vertex texture and the flag texture. Result is stored into a silhouette texture. 4. Shadow volume generator generates shadow volumes from the silhouette texture. 3.1 Algorithm Flowchart Our shadow algorithm has following steps: 1. The control mesh of the subdivision surface based model is broken into patches. The data of each patch will be sent to Kernel “Subdivision Surface Evaluator”. 2. Kernel “Subdivision Surface Evaluator” will use SP (Subdivision Pattern) as a tool to generate a vertex texture containing the refined model. 3. Kernel “Silhouette Marker” and “Silhouette Extractor” take the vertex texture as input and produce a silhouette texture containing silhouette information. 4. Kernel “Shadow Volume Generator” will extrude the silhouettes to shadow volumes. 5. Then the shadow volumes will be used for shadow rendering. 3.2 Patching the Control Mesh The control mesh is broken up into many patches on CPU. Each patch will be processed independently. If irregular vertices exist, we need to apply at most two subdivision operations on the initial control mesh to isolate the irregular vertices. By doing so, there is at most one irregular vertex in each patch. A patch consists of a quadrangle or a triangle and their surrounding vertices. For Catmull-Clark subdivision, if all vertices are regular (i.e., their valences equal to 4), we need to store 16 control points for a patch. For Loop subdivision, a regular patch (all vertices with valence equal to 3) consists of 12 control points. We generate one patch for each facet of the control mesh.
Real-Time Shadow Volume Algorithm for Subdivision Surface Based Models
541
3.3 Subdivision Pattern (SP) For a particular subdivision scheme, a specified subdivision level, and the valence of the irregular vertex (if any), we construct a corresponding SP. A SP is a mesh defined in unit space. It contains topological information and parametric information. Vertices of a SP store parametric information and combination coefficients calculated from the parameters. For the Loop subdivision, the vertices of SP contain the barycentric coordinates (u, v, w), where 0