Detailed description of the invention
Below in conjunction with the accompanying drawing in the embodiment of the present invention, the technical scheme in the embodiment of the present invention is carried outClear, complete description, obvious described embodiment is only a part of embodiment of the present invention, is notWhole embodiment, based on the embodiment in the present invention, those of ordinary skill in the art are not paying woundThe every other embodiment obtaining under the property made work prerequisite, belongs to the scope of protection of the invention.
Anti-aliasing improving one's methods of the present invention is the rasterization stage that is applied in graph rendering streamline, isCan not rely on GPU, the independent render engine that can realize. In addition, because rasterization stage adopts scanningLine algorithm, thus to realize the anti-aliasing of rasterization stage, X, Y-direction sampled point adopts regular m*nMode. Sampled point mode comprises 2X (1*2) as required at present, 4X (2*2), and 8X (2*4),16X (4*4), the sample modes such as 32X (4*8). As taking 8X as example, directions X adopts two samplingsPoint, Y-direction adopts 4 sampled points.
The embodiment of the present invention provides on the one hand in a kind of graph rendering streamline rasterization stage anti-aliasingImprove one's methods, implementing procedure as shown in Figure 1, is specially:
Step S1: prepare color buffer district and the depth buffer of anti-aliasing needs and initialize. Obtain and work asThe data on first three three summit of gusset plate, the position vPos in screen space, depth value fDepth, summit lightAccording to color vColor, the uv coordinate vUV[8 of every layer texture] (maximum eight layer texture). Realize anti-aliasing,The X of vertex position vPos, Y component are multiplied by respectively to X, the anti-aliasing multiple m of Y-direction, n orBe called sample mode, be designated as m*n.
Step S2: calculate the bounding box of triangular plate, and the directions X border of this bounding box is the integer of mDoubly, Y-direction border is the integral multiple of n.
Step S3: calculate the starting and terminal point position of the scan line in bounding box region and the degree of depth of starting and terminal pointValue, the depth value of above-mentioned starting and terminal point position and starting and terminal point be position by three summits of triangular plate andDepth value interpolation obtains.
Step S4: taking the zonule of m*n as unit, in triangular plate inside and depth value to be greater than the degree of depth slowRush the x of the pixel of the depth value in district, the weighted value (relative position in region) of y direction is added respectivelyBe designated as fSumX, fSumY, and total number iCount is added to 1, and this pixel of mark is TRUE.Wherein fSumX, fSumY, iCount initial value is all designated as 0. If iCount is 0, continue to repeatStep S4, otherwise carry out step S5.
Step S5: by fSumX, fSumY is divided by total iCount according to the weighted value obtaining in step S4Obtain x, the value of y direction, and calculate with respect to a position in sampled point zonule, this position conductNeed to calculate the position of color.
Step S6: obtain current summit according to the position of the color of triangular plate vertex position and above-mentioned calculatingAfter illumination color and texture coordinate value, calculate the color of current location.
Step S7: the color of the current location calculating is assigned to and is positioned at triangular plate and depth value in S4Be greater than the pixel of the depth value in depth buffer.
Step S8: after according to the method described above all triangular plates all being handled, color buffer district is dwindledTo original size, obtain anti-aliasing rendering result.
Embodiments of the present invention by first preparing anti-aliasing required color buffer before anti-aliasing processingDistrict, then the color of an assigned address in calculating sampling point regional extent gives region by this color valueSub-pixel in scope, then carries out rasterization process to triangular plate and after rasterization process completesColor buffer district is narrowed down to original size anti-aliasing improve one's methods to improve having in texture situationComputational efficiency, better realizes the anti-aliasing effect of 3 d rendering engine.
Below taking sampled point as 8X as example and in conjunction with Fig. 2 the graph rendering streamline to the embodiment of the present invention oneWhat middle rasterization stage was anti-aliasing improve one's methods carries out more detailed elaboration, is specially:
Step S1: by the X of vPos, it is that directions X is multiplied by 2, Y that Y-direction is multiplied by respectively anti-aliasing multipleDirection is multiplied by 4, and to make color buffer district and depth buffer canned data amount be 8 need not be anti-aliasing timeDoubly. Before rasterization stage, prepare color buffer district and the depth buffer initial of anti-aliasing needsChange.
Step S2: calculate the minimum bounding box of triangular plate, directions X border is 2 multiple, and Y-direction is4 multiple.
Step S3: according to 8X sampled point calculate the scan line in bounding box region starting and terminal point position andThe depth value of starting and terminal point, and be to obtain by position and the depth value interpolation on three summits.
Step S4: note fSumX, fSumY is 0, iCount=0; The 8X of the present embodiment anti-aliasing withThe zonule of 2*4 is unit, by position and the depth value of 3 scan lines, and specifically can be shown in Figure 3.Judge in this region that each pixel is whether in triangular plate, and calculate the depth value of each pixel, enterRow depth detection (namely with depth buffer in depth value compare, as be greater than this value, representClose to observer, be not blocked). In this way, use the depth value of this pixel is replaced to the phase in depth bufferAnswer the depth value of position, and by the X of this pixel, the weight of Y-direction (with respect to whole 2*4 region)Add fSumX, fSumY, and iCount adds 1, and this pixel of mark bFlag is TRUE.
Step S5: if iCount=0 continues to calculate next 2*4 zonule; Otherwise carry out step S6.
Step S6: by fSumX, fSumY, divided by iCount, obtains X, the value of Y-direction, and beWith respect to the positional value of zonule, according to the position of zonule, calculate the absolute value of this position, be designated asvTempPos。
Step S7: the color of calculating current location. According to position and the vTempPos on three summits of triangular plateValue, determine the weight on three summits of triangular plate, be multiplied by phase by color and the texture coordinate value on three summitsAnswer the weight on summit and be added, obtaining illumination color and the texture coordinate value at current location vTempPos place(if any texture). Illumination color is mixed with texture color, ground floor texture and illumination blend of colors meterCalculation obtains color value color, if there is second layer texture, does mixed juice with color value color above againCalculate, the rest may be inferred, until obtain final color value.
Step S8: the color that step 7 is calculated be assigned in 2*4 lattice and at triangular plate inner andBe that the pixel that is labeled as TRUE in step S4 is carried out filling out of color buffer district by the sub-pixel of depth testFill.
Step S9: after all triangular plates are all handled, it is 8 that color buffer district is narrowed down to original sizeIndividual sampled point color is synthesized a color, obtains anti-aliasing rendering effect.
Embodiments of the present invention by first preparing anti-aliasing required color buffer before anti-aliasing processingDistrict, then the color of an assigned address in calculating sampling point regional extent gives region by this color valueSub-pixel in scope, then carries out rasterization process to triangular plate and after rasterization process completesColor buffer district is narrowed down to original size anti-aliasing improve one's methods to improve having in texture situationComputational efficiency, and edge and intersect boundary to object have good treatment effect, better realizes threeThe anti-aliasing effect of dimension render engine.
Through the above description of the embodiments, those skilled in the art can be well understood to thisBright can realization by software, the mode that also can add necessary general hardware platform by software realizes.Based on such understanding, technical scheme of the present invention can embody with the form of software product, and this is softPart product can be stored in a non-volatile memory medium, and (can be CD-ROM, USB flash disk, moves hardDish etc.) in, comprise that some instructions are in order to make a computer equipment (can be personal computer, takeBusiness device, or the network equipment etc.) carry out the method described in each embodiment of the present invention.
The above, be only a best specific embodiment of the present invention, but not office of feature of the present inventionBe limited to this, any people who is familiar with this technology in field of the present invention, the variation that can expect easily or modification,All should be encompassed in following claim of the present invention.