The invention relates generally to computers, and more particularly to images.
Anti-aliasing is used to reduce aliasing artifacts common with diagonal or curved edges in computer images. Current techniques for anti-aliased rasterization of 3D models either require an excessive amount of time, special hardware support, or result in unacceptable artifacts, such as object bloating. Furthermore, anti-aliasing for 3D models varies in quality and performance from one graphics card to another. What is needed is a method for accelerating anti-aliasing for 3D models. Ideally, such a method would provide consistent results across graphics cards.
Briefly, the present invention provides a method and system for anti-aliased rasterization of objects. From a particular viewpoint of an object represented by shapes, a shape is selected having an edge on a silhouette of the object. An edge geometry is created at the edge of the shape that is on the silhouette of the object. The edge geometry is rendered. Either the shape is rendered after the edge geometry is rendered with the depth test set so as to not allow portions of the shape to overlap the edge geometry, or the shape itself is modified to remove any portion that overlaps the edge geometry. This may be repeated for each edge of each shape that lies on the silhouette of the object.
In one aspect of the invention, the edge geometry is textured with the texture that matches the texture at the edge of the shape. The edge geometry also has a texture placed thereon that has a varying transparency from opaque to completely transparent. This causes colors from pixels underneath the edge geometry to be mixed with colors from pixels of the edge geometry. This has the effect of anti-aliasing the silhouette of the object.
Other aspects will become apparent from the following detailed description when taken in conjunction with the drawings, in which:
Exemplary Operating Environment
The invention is operational with numerous other general purpose or special purpose computing system environments or configurations. Examples of well known computing systems, environments, and/or configurations that may be suitable for use with the invention include, but are not limited to, personal computers, server computers, hand-held or laptop devices, multiprocessor systems, microcontroller-based systems, set top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments that include any of the above systems or devices, and the like.
The invention may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, and so forth, which perform particular tasks or implement particular abstract data types. The invention may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
With reference to
Computer 110 typically includes a variety of computer-readable media. Computer-readable media can be any available media that can be accessed by the computer 110 and includes both volatile and nonvolatile media, and removable and non-removable media. By way of example, and not limitation, computer-readable media may comprise computer storage media and communication media. Computer storage media includes both volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storage of information such as computer-readable instructions, data structures, program modules, or other data. Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital versatile disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other medium which can be used to store the desired information and which can accessed by the computer 110. Communication media typically embodies computer-readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism and includes any information delivery media. The term “modulated data signal” means a signal that has one or more of its characteristics set or changed in such a manner as to encode information in the signal. By way of example, and not limitation, communication media includes wired media such as a wired network or direct-wired connection, and wireless media such as acoustic, RF, infrared and other wireless media. Combinations of the any of the above should also be included within the scope of computer-readable media.
The system memory 130 includes computer storage media in the form of volatile and/or nonvolatile memory such as read only memory (ROM) 131 and random access memory (RAM) 132. A basic input/output system 133 (BIOS), containing the basic routines that help to transfer information between elements within computer 110, such as during start-up, is typically stored in ROM 131. RAM 132 typically contains data and/or program modules that are immediately accessible to and/or presently being operated on by processing unit 120. By way of example, and not limitation,
The computer 110 may also include other removable/non-removable, volatile/nonvolatile computer storage media. By way of example only,
The drives and their associated computer storage media, discussed above and illustrated in
The computer 110 may operate in a networked environment using logical connections to one or more remote computers, such as a remote computer 180. The remote computer 180 may be a personal computer, a server, a router, a network PC, a peer device or other common network node, and typically includes many or all of the elements described above relative to the computer 110, although only a memory storage device 181 has been illustrated in
When used in a LAN networking environment, the computer 110 is connected to the LAN 171 through a network interface or adapter 170. When used in a WAN networking environment, the computer 110 typically includes a modem 172 or other means for establishing communications over the WAN 173, such as the Internet. The modem 172, which may be internal or external, may be connected to the system bus 121 via the user input interface 160 or other appropriate mechanism. In a networked environment, program modules depicted relative to the computer 110, or portions thereof, may be stored in the remote memory storage device. By way of example, and not limitation,
Accelerated Anti-Aliasing in 3D
Pixels with pixel centers located within the triangle 210 may be caused to display colors associated with the triangle 210 while pixels with pixel centers outside of the triangle may be caused to display a background color such as black. Without anti-aliasing, this may result in a stair-stepping pattern of pixels at the borders of the triangle 210.
Objects, including three-dimensional (3D) objects, may be represented by a collection of shapes. In practice, each shape may be a triangle or be divided into triangles. Some of these triangles may lie totally within the boundaries of an object, while other triangles may lie at the edge of the object when the object is viewed from a particular viewpoint. Triangles that lie at the edge of an object (from a particular viewpoint) may have one or more edges that form a portion of a silhouette edge of the object. For 3D objects comprised of triangles, a silhouette edge is an edge that touches both a triangle that faces a viewpoint and a triangle that faces away from the viewpoint. A triangle faces a viewpoint if the normal of the plane in which the triangle resides points towards the viewpoint.
In one embodiment of the invention, anywhere a discontinuity edge occurs is treated as being on the silhouette. It will be recognized that treating such edges as being on the silhouette may allow anti-aliasing to be performed of sharp edges that do not lie on the actual silhouette of the object.
At block 415, the triangles that comprise the object are sorted from back to front with respect to the viewpoint. At block 420, the Z-Test function is set to be “strictly less than.” Setting the Z-Test function to be strictly less than has the effect of making sure a pixel is not drawn over an existing pixel unless the new pixel's Z value is strictly less than the existing pixel's Z value.
At block 425, the triangles are rendered as described in more detail in conjunction with
At block 520, new edge geometry is created for the edge of the triangle that lies on the silhouette of the object.
The edge geometry 605 may be created in the same plane as the plane that includes the triangle 305. This guarantees that it will have the same Z values as the pixels of the triangle that it overlaps. Furthermore, because the edge geometry 605 is drawn before the triangle 305, when the triangle 305 is drawn, it will not overdraw any pixels in the edge geometry 605 because of the “strictly less than” setting of the Z test.
Alternatively to setting the Z-Test function to be “strictly less than,” the edge geometry 605 may be biased such that its Z values indicate that the edge geometry 605 is slightly in front of the triangle pixels that the edge geometry 605 overlaps. In addition, the Z-Test function may be set to not overdraw a pixel with another pixel if the other pixel has a Z buffer value that is less than or equal to the pixel. This may be done to ensure that when rendering the triangle, that the pixels of the triangle are not overdrawn over any pixels affected by the edge geometry 605.
In another embodiment of the invention, instead of using the “strictly less than” setting of the Z test to prevent the rendering of the triangle 305 from overdrawing pixels of the edge geometry 605, the triangle 305 may be modified so that it no longer overlaps the edge geometry 605. In addition, the edge geometry 605 may be positioned in the plane of the viewpoint or in the plane of the triangle. Positioning the edge geometry 605 in the plane of the viewpoint instead of the plane of the triangle may avoid errors that may occur if the edge geometry 605 extends in front of the near clipping plane. To avoid visual discontinuities between the texturing of the triangle and the texturing of the edge geometry when modifying the triangle 305 in this manner, the texture coordinates of the triangle may also need to be modified.
The edge geometry 605 may be textured with two textures that are modulated together. The two textures may be modulated together by providing a renderer with the two textures and indicating that each texture should be applied to the edge geometry 605. One of the textures may be the same texture as the triangle, so that colors along the edge geometry 605 match the colors of the triangle 305. The other texture of the edge geometry may be an alpha gradient that ranges continuously from opaque (i.e., not transparent at all) on the side of the edge geometry 605 that is inside of the triangle to transparent on the side of the edge geometry 605 that is outside the triangle 305.
Placing the alpha gradient on the edge geometry 605 causes a pixel that has a center on the inside edge of the edge geometry 605 to be opaque, a pixel that has a center on the edge of the triangle 305 within the edge geometry 605 to be half transparent, and a pixel that has a center on the outside edge of the edge geometry 605 to be completely transparent.
In another embodiment of the invention, the edge geometry 605 may be more than one pixel in width. Furthermore, instead of a ramp between transparent and opaque, the transparency of each part of the edge geometry 605 may be determined by a function (e.g., sin(x)/x). In such cases such a function combined with a wider edge geometry may reconstruct the silhouette of an object more correctly than a linear transparency in combination with a pixel-width edge geometry.
Texture is one form of interpolation mechanism that may be used to determine the colors of pixels associated with an edge geometry. In other embodiments of the invention, other interpolation mechanisms may be used to determine the colors of pixels associated with an edge geometry. Some exemplary interpolation mechanisms include Gouraud shading, texture, pixel shaders, and the like.
More than one pixel shader may be applied to pixels associated with an edge geometry. This may be done by applying one pixel shader to the pixels and then afterwards applying another pixel shader to the pixels and so on. A pixel shader may comprise a component or process that calculates colors for each pixel associated with a geometry.
Although shown as a rectangle, the edge geometry 605 may be another geometry or size without departing from the spirit or scope of the invention. For example, an edge geometry may be fashioned as shown by the edge geometry 705 of
Furthermore, for triangles close to one pixel in size or smaller, an edge geometry may not be created.
Referring to
At block 540, the next triangle to render is obtained. The selection of triangles goes from those furthest from a viewpoint to those closest to the viewpoint. This may be done at least in part so that colors from pixels of triangles further away are blended with colors from overlapping partially transparent pixels of triangles that are closer.
At block 545, the process returns.
Referring again to
As can be seen from the foregoing detailed description, there is provided an improved method for hardware accelerated anti-aliasing in 3D. While the invention is susceptible to various modifications and alternative constructions, certain illustrated embodiments thereof are shown in the drawings and have been described above in detail. It should be understood, however, that there is no intention to limit the invention to the specific forms disclosed, but on the contrary, the intention is to cover all modifications, alternative constructions, and equivalents falling within the spirit and scope of the invention.