The present invention relates to graphics processing, and more particularly to graphics processing involving transparent or semi-transparent objects.
Alpha blending refers to a process of combining rasterized fragments with a background to create the appearance of partial transparency. Rendering semi-transparent surfaces correctly using an alpha blending equation typically requires sorting fragments from front-to-back or back-to-front.
In real-time applications, this is often performed by sorting primitives using a central processing unit or using depth peeling on a graphics processor. Such depth peeling requires a separate geometry pass for each transparency layer. Unfortunately, this can be quite resource intensive.
For applications that only need a transparency “look and feel,” techniques have been developed for approximating the result of correct depth-sorted alpha blending. One such approximation technique involves a sum of color that is weighted with an alpha value or transparency coefficient. While such techniques are less resource intensive, the resultant quality is less than desired.
There is thus a need for addressing these and/or other issues associated with the prior art.
A system, method, and computer program product are provided for approximating a pixel color. In operation, an average color value and a number of fragments are identified for each of a plurality of pixels. Additionally, a color of each pixel is approximated, based on such average color value and number of fragments.
In the context of the present description, fragments refer to a primitive or portion of a primitive corresponding to a pixel. Such primitives may include points, lines, or triangles. In one embodiment, the number of fragments may include a number of primitives that overlap with a corresponding pixel.
Strictly as an option, the average color value may be a weighted color value. In this case, the average color value may be weighted with an alpha value (i.e. a transparency coefficient), a depth value, a distance value, and/or any other weighting value. To this end, a color of each pixel is approximated, based on the average color value and the number of fragments. See operation 104. In various other embodiments, the color of each pixel may be approximated based on additional criteria. For example, the color of each pixel may be approximated based on an alpha value, a background color value, a depth value of a fragment, a distance value from a first fragment to a second fragment for each of the plurality of pixels, and/or various other various factors. Of course, these factors are only examples and should not be construed as limiting.
More illustrative information will now be set forth regarding various optional architectures and features with which the foregoing framework may or may not be implemented, per the desires of the user. It should be strongly noted that the following information is set forth for illustrative purposes and should not be construed as limiting in any manner. Any of the following features may be optionally incorporated with or without the exclusion of other features described.
As shown, a geometry processing module 202 and a post-processing module 204 are provided. In operation, the geometry processing module 202 accumulates data in a buffer for each of a plurality of pixels. For example, the geometry processing module 202 may accumulate color values (e.g. a red value, a blue value, a green value, etc.), an alpha value, a number of fragments per pixel (e.g. depth complexity, etc.), and/or various other data for each pixel.
In one embodiment, a color value and a number of fragments may be stored for each pixel in the accumulation buffer, during at least one geometry pass. The geometry processing module 202 may accumulate this data for all primitives in a scene. The contents of the accumulation buffer may then be processed during a post-processing pass using the post-processing module 204.
During such post-processing pass, the contents of the accumulation buffer may be utilized to compute an average color, an average alpha value, and an approximate color for each pixel. For example, a red, green, and blue value (RGB value), and an alpha value (A) for each fragment may be utilized to compute a weighted average color (C) for each pixel using Equation #1.
C=Σ[(RGB)A]/ΣA. Equation #1
Of course, it should be noted that the foregoing equation is set forth for illustrative purposes only and should not be construed as limiting in any manner whatsoever.
Additionally, the average alpha value (A) for each pixel may be computed from the accumulated data using the alpha value (A) for each fragment and the total number of fragments (n) from each pixel using Equation #2.
A=ΣA/n. Equation #2
Again, it should be noted that the foregoing equation is set forth for illustrative purposes only and should not be construed as limiting in any manner whatsoever.
In one embodiment, the weighted sum of the RGB value (e.g. Σ[(RGB) A]) and the sum of the alpha values (ΣA) may be stored in the buffer such that the computation of the average weighted color (C) only involves one step of division. For example, as part of the geometry pass, the color value (RGB) for each fragment may be multiplied by the alpha value (A) for each fragment, and this result may be stored and added to results from additional fragments corresponding to the pixel. Similarly, the alpha value may be stored for each of the fragments corresponding to the pixel in an additive manner, resulting in a value which is the sum of all alpha values for fragments corresponding to a pixel. Of course, such implementation is optional and should not be construed as limiting in any manner.
Once the average alpha value and average color for each pixel is obtained, a destination color for each pixel (Cdst) may be approximated using Equation #3.
Cdst=C(1−(1−A)n)+Cbg(1−A)n Equation #3
In Equation #3, C is the weighted average color for each pixel, A is the average alpha value for each pixel, Cbg is the background color value, and n is the number of fragments per pixel. Thus, the blended color for each pixel (Cdst) is a function of C, A, n, and the background color Cbg.
Although the present example utilizes the weighted average color for each pixel, in another embodiment, the average color for each pixel may also be used without weighting. Furthermore, the average color for a pixel may be calculated in a variety of ways using a variety of weighting coefficients. Weighting the average color using the alpha value is only one example and should not be construed as limiting in any manner.
As shown, the data structure 300 stores alpha values 302, color values 304, and a number of fragments 306 for a plurality of pixels 308. It should be noted that, although the data structure 300 is illustrated as including the plurality of pixels 308, in another embodiment, an index corresponding to the data structure 300 may be utilized to determine the pixel. For example, the plurality of pixels 308 may represent a 2-dimensional pixel coordinate in an image. Thus, a pixel coordinate may be determined utilizing an index corresponding to the data structure 300.
In one embodiment, one geometry pass may serve to accumulate and store the alpha values 302, the color values 304, and the number of fragments 306 for each of the pixels 308. For example, for every fragment of “Pixel 1,” the alpha value for such fragment may be added to a total alpha value “A1” for Pixel 1. Additionally, for every fragment of Pixel 1, a weighted red, green, and blue value may be accumulated and stored. In one embodiment, the red, green, and blue value may be weighted using the alpha value for the fragment. For example, the red, green, and blue value for each fragment of Pixel 1 may be multiplied by the corresponding alpha value for each fragment, and the result may be stored and accumulated in the data structure 300.
Further, the number of fragments 306 is incremented and stored. For example, for each fragment corresponding to a pixel, a fragment count may increment by one. The alpha values 302, the color values 304, and the number of fragments 306 for each of the pixels 308 may then be used in a post-processing operation to calculate an approximate color for each of the pixels 308.
It should be noted that, in other embodiments, the data structure 300 may include various other data corresponding to the pixels 308 and/or the corresponding fragments. For example, in one embodiment, depth information for a particular fragment may be stored. In another embodiment, the depth information may be used to weight the color values 304. Such weighting may occur in addition to, or instead of, the alpha value weighting.
Similarly, depth information for a particular fragment may be stored. For example, the depth of a fragment from a top layer or another fragment of a pixel may be stored. As an option, the depth information may be used to weight the colors 304. Such weighting may occur in addition to, or instead of, the alpha value weighting and/or any depth weighting.
As shown, a geometry pass is initiated. See operation 402. After the initiation of the geometry pass, the method 400 selects a next primitive in a primitive stream, and sets up a graphics processor for the next operation (e.g. rasterization, accumulation, etc.). See operation 404.
Once the primitive is selected, data is accumulated in a buffer for each overlapping pixel. See operation 406. In various embodiments, the data may include a color value for each overlapping pixel (e.g. a red value, a blue value, a green value, etc.), a transparency coefficient (e.g. an alpha value, etc.), a depth complexity (e.g. a number of fragments per pixel, etc.), and/or any other data corresponding to each pixel.
For example, an alpha value may be identified for each of the pixels. In this case, the alpha values may be stored in an accumulation buffer. Similarly, the color values and the number of fragments for each pixel may be stored in such accumulation buffer.
In one embodiment, the accumulation may include rendering geometry corresponding to overlapping pixels into an accumulation buffer implemented as a 16-bit floating-point texture. In the context of the present description, an overlapping pixel refers to a pixel corresponding to (e.g. covered by) at least one primitive. In one embodiment, an overlapping pixel may include data from portions of multiple primitives in a layered format. In this case, a number of fragments, color values, and/or transparency coefficients may be accumulated for each layer. Additionally, changes may be implemented in post-processing in order to blend multiple layers together.
Once the data has been accumulated for each overlapping pixel of the primitive, it is determined whether another primitive is available. See decision 408. If there is another primitive, the next primitive is selected and data for each overlapping pixel of the primitive is accumulated in the buffer.
As shown, these operations may repeat until all desired primitives have been selected. Once it is determined that no more primitives are available, post-processing is initiated for each pixel. See operation 410.
Once post-processing is initiated for each pixel, a fragment count (e.g. number of fragments for a pixel, etc.) is inspected. See operation 412. In this case, the fragment count may be a number stored in the accumulation buffer which indicates a total number of fragments corresponding to a pixel. Upon inspection of the fragment count, it is determined whether the fragment count is equal to zero. See decision 414.
If it is determined that the fragment count is equal to zero, the pixel is labeled as a background color. See operation 416. In this case, a fragment count of zero may indicate that the pixel has no corresponding fragments. Thus, a color associated with such pixel may be set or labeled as a background color. It should be noted that the background color may include an actual scene background, as well as an object or image background.
If it is determined that the fragment count is not equal to zero, an average color is computed for each pixel. See operation 418. Additionally, an average alpha value, or transparency coefficient, is computed for each pixel. See operation 420.
As an option, the average color value may be a weighted color value. In one embodiment, the average color value may be weighted with the alpha value. For example, the average color may be computed using Equation #1.
In another embodiment, the average color value may be weighted with a depth value. For example, the average color may be computed using Equation #4.
C=Σ[(RGB)D]/ΣD, Equation #4
In Equation #4, D indicates the depth value for a fragment. In this case, the RGB value for each fragment may be weighted based on a relative depth or a number of fragments from the surface.
In still another embodiment, the average color value may be weighted with a distance value. For example, the RGB value for each fragment may be weighted using the distance of the fragment from a first layer or fragment of the pixel. In this case, a larger distance from the top layer may correspond to a smaller weighted color value.
Using the average alpha value and the average color for each pixel, a destination color is approximated. See operation 422. As an option, the destination color may be approximated using Equation #3.
The system 500 also includes a graphics processor 506 and a display 508, i.e. a computer monitor. In one embodiment, the graphics processor 506 may include a plurality of shader modules, a rasterization module, etc. Each of the foregoing modules may even be situated on a single semiconductor platform to form a graphics processing unit (GPU).
In the present description, a single semiconductor platform may refer to a sole unitary semiconductor-based integrated circuit or chip. It should be noted that the term single semiconductor platform may also refer to multi-chip modules with increased connectivity which simulate on-chip operation, and make substantial improvements over utilizing a conventional central processing unit (CPU) and bus implementation. Of course, the various modules may also be situated separately or in various combinations of semiconductor platforms per the desires of the user.
Computer programs, or computer control logic algorithms, may be stored in the main memory 504 and/or a secondary storage 510. Such computer programs, when executed, enable the system 500 to perform various functions. Memory 504, storage 510 and/or any other storage are possible examples of computer-readable media.
In one embodiment, the architecture and/or functionality of the various previous figures may be implemented in the context of the host processor 501, graphics processor 506, an integrated circuit (not shown) that is capable of at least a portion of the capabilities of both the host processor 501 and the graphics processor 506, a chipset (i.e. a group of integrated circuits designed to work and sold as a unit for performing related functions, etc.), and/or any other integrated circuit for that matter.
Still yet, the architecture and/or functionality of the various previous figures may be implemented in the context of a general computer system, a circuit board system, a game console system dedicated for entertainment purposes, an application-specific system, and/or any other desired system. For example, the system 500 may take the form of a desktop computer, lap-top computer, and/or any other type of logic. Still yet, the system 500 may take the form of various other devices including, but not limited to, a personal digital assistant (PDA) device, a mobile phone device, a television, etc.
While various embodiments have been described above, it should be understood that they have been presented by way of example only, and not limitation. Thus, the breadth and scope of a preferred embodiment should not be limited by any of the above-described exemplary embodiments, but should be defined only in accordance with the following claims and their equivalents.
Number | Name | Date | Kind |
---|---|---|---|
5386509 | Suzuki et al. | Jan 1995 | A |
5974198 | Hamburg et al. | Oct 1999 | A |
7064771 | Jouppi et al. | Jun 2006 | B1 |
20020080141 | Imai et al. | Jun 2002 | A1 |
20020126138 | Shekter | Sep 2002 | A1 |
20030025700 | Sasaki et al. | Feb 2003 | A1 |
20040179020 | Lewis et al. | Sep 2004 | A1 |
20040217974 | Lewis | Nov 2004 | A1 |