Rasterization method, and processor, system and electronic device
By using the principle of ratio relationship between the external rectangles and similar triangles of triangle primitives during the rasterization process, the calculation of judging pixels in the triangle is simplified, the problem of wasted hardware resources and power consumption is solved, and the computing efficiency is improved.
Patent Information
- Application Number
- PCT/CN2024/083198
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2024-01-19
- Filing Date
- 2024-03-22
- Publication Date
- 2025-07-24
AI Technical Summary
During the existing rasterization process, hardware resources and power consumption are severely wasted, and existing algorithms require complex operations such as calculating linear slopes or equation values, resulting in excessive resource and energy consumption.
By determining the external rectangle of the triangle element and using the principle of similar triangle equal-to-ratio relationships to determine whether the pixel points are in the triangle element, simplifying the computing process and reducing hardware resources and power consumption.
It effectively reduces the consumption of hardware resources and power consumption during the rasterization process and improves computing efficiency.
Smart Images

Figure CN2024083198_24072025_PF_FP_ABST
Abstract
Description
Rasterization method, processor, system and electronic device
[0001] CROSS-REFERENCE TO RELATED APPLICATIONS
[0002] This application is based on the Chinese patent application with application number 202410084765.1 and application date of January 19, 2024, and claims the priority of the Chinese patent application. The entire content of the Chinese patent application is hereby introduced into this application as a reference. Technical Field
[0003] The present application relates to the field of graphics processor technology, and in particular, to a rasterization method, processor, system, and electronic device. Background Art
[0004] Rasterization refers to mapping an image in 3D space to a 2D plane in some way, and is an important function in the graphics processing unit (GPU) pipeline.
[0005] There are many rasterization algorithms available, and their hardware implementation requires calculating the slope of a line or the value of an equation. For example, in triangle rasterization, determining whether a pixel is within a triangle requires solving the equations of the lines corresponding to the three sides of the triangle. These complex calculations consume significant hardware resources and power.
[0006] Summary of the Invention
[0007] The purpose of the present disclosure is to provide a rasterization method, processor, system and electronic device, which solve the technical problems of hardware resource and power consumption waste caused by the rasterization process in the prior art.
[0008] According to one aspect of the present disclosure, a rasterization method is provided, comprising:
[0009] Determine vertex coordinates of a first rectangle according to vertex coordinates of a triangle primitive to be rasterized and vertex coordinates of a circumscribed rectangle of the triangle primitive, where the circumscribed rectangle is divided into at least one first rectangle by a first tangent and a second tangent, where the first tangent is an X-direction tangent of a first vertex of the triangle primitive, the second tangent is a Y-direction tangent of a second vertex of the triangle primitive, the first vertex is a vertex in the triangle primitive with a center Y coordinate value or a same Y coordinate value, and the second vertex is a vertex in the triangle primitive with a center X coordinate value or a same X coordinate value;
[0010] For some or all of the pixels within each first rectangle, determine whether they are inside the triangle primitive using the following methods:
[0011] For a pixel point located within a first rectangle of a first type, determining that the pixel point is outside the triangle primitive, where the first rectangle of the first type refers to a first rectangle that does not overlap with the triangle primitive;
[0012] For pixel points located in the first rectangle that is not of the first type, determine whether the pixel point is inside the triangle primitive based on the distance from the pixel point to the two right-angled sides of the target right triangle and the principle of geometric proportion of similar triangles. The right-angled side of the target right triangle coincides with the side of the corresponding first rectangle, and the hypotenuse of the target right triangle is the target side of the triangle primitive. The target side of the triangle primitive is the side covered by the first rectangle corresponding to the target right triangle.
[0013] In some embodiments, in the above rasterization method, for a pixel point located within a first rectangle that is not of the first type, determining whether the pixel point is inside the triangle primitive based on the distance between the pixel point and two right-angled sides of the target right triangle and the principle of geometric proportions of similar triangles includes:
[0014] For a pixel point located within the first rectangle of the second type, determine whether (D1 / (L1-D2)) is greater than (L2 / L1) based on the distance D1 from the pixel point to the first right-angled side and the distance D2 from the second right-angled side to the target right triangle, as well as the length L1 of the first right-angled side and the length L2 of the second right-angled side. If so, determine that the pixel point is outside the triangle primitive; otherwise, determine that the pixel point is inside the triangle primitive. The first rectangle of the second type refers to the first rectangle whose overlapping part with the triangle primitive is a right triangle, and the target right triangle is the overlapping part or the first similar triangle of the overlapping part; the first similar triangle covers the overlapping part.
[0015] In some embodiments, in the above rasterization method, for a pixel point located within a first rectangle that is not of the first type, determining whether the pixel point is inside the triangle primitive based on the distance between the pixel point and two right-angled sides of the target right triangle and the principle of geometric proportions of similar triangles includes:
[0016] For a pixel point located within the first rectangle of the second type, determine whether (D1' / (L1-D2')) is less than (L2 / L1) based on the distance D1' and the distance D2' from the pixel point to the first right-angled side and the second right-angled side of the target right triangle, as well as the length L1 of the first right-angled side and the length L2 of the second right-angled side. If so, determine that the pixel point is outside the triangle primitive; otherwise, determine that the pixel point is inside the triangle primitive. The first rectangle of the second type refers to the first rectangle whose overlapping part with the triangle primitive is a right triangle, and the target right triangle is the second similar triangle of the overlapping part; the second similar triangle does not cover the overlapping part.
[0017] In some embodiments, in the above rasterization method, for a pixel point located within a first rectangle that is not of the first type, determining whether the pixel point is inside the triangle primitive based on the distance between the pixel point and two right-angled sides of the target right triangle and the principle of geometric proportions of similar triangles includes:
[0018] For a pixel point located within the first rectangle of the third type, determine whether (D1 / (L1-D2)) is less than (L2 / L1) based on the distance D1 and the distance D2 from the pixel point to the first right-angled side and the second right-angled side of the target right triangle, as well as the length L1 of the first right-angled side and the length L2 of the second right-angled side. If so, determine that the pixel point is outside the triangle primitive. The first rectangle of the third type refers to a first rectangle whose overlapping part with the triangle primitive is a non-right triangle, and the target right triangle is the non-overlapping part of the corresponding first rectangle and the triangle primitive or the first similar triangle of the non-overlapping part; the first similar triangle covers the non-overlapping part and does not cover the overlapping part of the corresponding first rectangle and the triangle primitive.
[0019] In some embodiments, in the above rasterization method, for a pixel point located within a first rectangle that is not of the first type, determining whether the pixel point is inside the triangle primitive based on the distance between the pixel point and two right-angled sides of the target right triangle and the principle of geometric proportions of similar triangles includes:
[0020] For a pixel point located within the first rectangle of the third type, determine whether (D1' / (L1-D2')) is greater than (L2 / L1) based on the distance D1' and the distance D2' from the pixel point to the first right-angled side and the second right-angled side of the target right triangle, as well as the length L1 of the first right-angled side and the length L2 of the second right-angled side. If so, determine that the pixel point is outside the triangle primitive. The first rectangle of the third type refers to a first rectangle whose overlapping part with the triangle primitive is a non-right triangle, and the target right triangle is a second similar triangle of the non-overlapping part of the corresponding first rectangle and the triangle primitive; the second similar triangle covers the overlapping part of the corresponding first rectangle and the triangle primitive.
[0021] In some embodiments, the above rasterization method further includes:
[0022] Determine, based on the vertex coordinates of the triangle primitive, the vertex coordinates of the circumscribed rectangle, and the vertex coordinates of each first rectangle, the number of overlapping vertices between each first rectangle and the triangle primitive, and the positional relationship between the overlapping vertices and the first tangent and the second tangent;
[0023] Determining the type of each first rectangle based on the number of overlapping vertices between each first rectangle and the triangle primitive, and the positional relationship between the overlapping vertices and the first tangent and the second tangent, and determining, for each pixel located within a first rectangle that is not of the first type, two right-angled sides of the corresponding target right triangle;
[0024] When the number of overlapping vertices between a first rectangle and a triangle primitive is 1, the overlapping vertex is located on both the first tangent and the second tangent, and the corresponding ((Wx-Lx) / Ly) is less than (Wx / Wy) and (Lx / (Wy-Ly)) is greater than (Wx / Wy), the first rectangle is a first rectangle of the second type, and for a pixel point within the first rectangle, the two right-angled sides of the corresponding target right triangle are respectively the first Y-direction side and the first X-direction side of the circumscribed rectangle; the first Y-direction side and the first X-direction side are respectively the Y-direction side and the X-direction side of the circumscribed rectangle that do not overlap with the first rectangle; the Y-direction side and the X-direction side of the circumscribed rectangle that overlap with the first rectangle are respectively the second Y-direction side and the second X-direction side; Lx and Ly are respectively the side lengths of the X-direction side and the Y-direction side of the first rectangle, and Wx and Wy are respectively the side lengths of the X-direction side and the Y-direction side of the circumscribed rectangle;
[0025] When the number of coincident vertices between a first rectangle and a triangle primitive is 1 and the coincident vertex is located on the first tangent line but not on the second tangent line, the first rectangle is a first rectangle of the second type, and the two right-angled sides of the corresponding target right triangle are the line segment on the corresponding first Y-direction side aligned with the Y-direction side of the first rectangle and the first tangent line, respectively;
[0026] When the number of coincident vertices between a first rectangle and a triangle primitive is one and the coincident vertex is located on the second tangent line but not on the first tangent line, the first rectangle is a first rectangle of the second type, and the two right-angled sides of the corresponding target right triangle are respectively the second tangent line and a line segment on the corresponding first X-direction side that is aligned with the X-direction side of the first rectangle;
[0027] When the number of overlapping vertices between a first rectangle and a triangle primitive is 2 and the two overlapping vertices are both located on the first tangent line, the first rectangle is a first rectangle of the second type, and the two right-angled sides of the corresponding target right triangle are the corresponding first Y-direction side and the first tangent line, respectively. When the number of overlapping vertices between a first rectangle and a triangle primitive is 2 and the two overlapping vertices are both located on the second tangent line, the first rectangle is a first rectangle of the second type, and the two right-angled sides of the corresponding target right triangle are the second tangent line and the corresponding first X-direction side, respectively.
[0028] When the number of overlapping vertices between a first rectangle and a triangle primitive is 2 and the two overlapping vertices are located on the first tangent and the second tangent, respectively, or the number of overlapping vertices between a first rectangle and a triangle primitive is 3, the first rectangle is a first rectangle of the second type, and the two right-angled sides of the corresponding target right triangle are the Y-direction side of the first rectangle overlapping with the second tangent and the X-direction side overlapping with the first tangent, respectively.
[0029] In some embodiments, the above rasterization method further includes:
[0030] Determine, based on the vertex coordinates of the triangle primitive, the vertex coordinates of the circumscribed rectangle, and the vertex coordinates of each first rectangle, the number of overlapping vertices between each first rectangle and the triangle primitive, and the positional relationship between the overlapping vertices and the first tangent and the second tangent;
[0031] Determining the type of each first rectangle based on the number of overlapping vertices between each first rectangle and the triangle primitive, and the positional relationship between the overlapping vertices and the first tangent and the second tangent, and determining, for each pixel located within a first rectangle that is not of the first type, two right-angled sides of the corresponding target right triangle;
[0032] When the number of overlapping vertices between a first rectangle and a triangle primitive is 1, the overlapping vertex is located on both the first tangent and the second tangent, and the corresponding ((Wx-Lx) / Ly) is less than (Wx / Wy) and (Lx / (Wy-Ly)) is greater than (Wx / Wy), the first rectangle is a first rectangle of the second type, and for a pixel point within the first rectangle, the two right-angled sides of the corresponding target right triangle are respectively the second Y-direction side and the second X-direction side of the circumscribed rectangle; the second Y-direction side and the second X-direction side are respectively the Y-direction side and the X-direction side of the circumscribed rectangle that overlap with the first rectangle; the Y-direction side and the X-direction side of the circumscribed rectangle that do not overlap with the first rectangle are respectively the first Y-direction side and the first X-direction side; Lx and Ly are respectively the side lengths of the X-direction side and the Y-direction side of the first rectangle, and Wx and Wy are respectively the side lengths of the X-direction side and the Y-direction side of the circumscribed rectangle;
[0033] When the number of coincident vertices between a first rectangle and a triangle primitive is 1 and the coincident vertex is located on the first tangent line but not on the second tangent line, the first rectangle is a first rectangle of the second type, and the two right-angled sides of the corresponding target right triangle are respectively the Y-direction side of the first rectangle that does not coincide with the second tangent line and the second X-direction side;
[0034] When the number of coincident vertices between a first rectangle and a triangle primitive is 1 and the coincident vertex is located on the second tangent line but not on the first tangent line, the first rectangle is a first rectangle of the second type, and the two right-angled sides of the corresponding target right triangle are respectively the second Y-direction side and the X-direction side of the first rectangle that does not coincide with the first tangent line;
[0035] When the number of overlapping vertices between a first rectangle and a triangle primitive is 2 and the two overlapping vertices are both located on the first tangent line, the first rectangle is a first rectangle of the second type, and the two right-angled sides of the corresponding target right triangle are respectively the corresponding second Y-direction side and the X-direction side of the circumscribed rectangle that does not overlap with the first tangent line; when the number of overlapping vertices between a first rectangle and a triangle primitive is 2 and the two overlapping vertices are both located on the second tangent line, the first rectangle is a first rectangle of the second type, and the two right-angled sides of the corresponding target right triangle are respectively the Y-direction side of the circumscribed rectangle that does not overlap with the second tangent line and the corresponding second X-direction side;
[0036] When the number of overlapping vertices between a first rectangle and a triangle primitive is 2 and the two overlapping vertices are located on the first tangent and the second tangent, respectively, or the number of overlapping vertices between a first rectangle and a triangle primitive is 3, the first rectangle is a first rectangle of the second type, and the two right-angled sides of the corresponding target right triangle are the Y-direction side of the first rectangle that does not overlap with the second tangent and the X-direction side that does not overlap with the first tangent, respectively.
[0037] In some embodiments, the above rasterization method further includes:
[0038] Determine, based on the vertex coordinates of the triangle primitive, the vertex coordinates of the circumscribed rectangle, and the vertex coordinates of each first rectangle, the number of overlapping vertices between each first rectangle and the triangle primitive, and the positional relationship between the overlapping vertices and the first tangent and the second tangent;
[0039] Determining the type of each first rectangle based on the number of overlapping vertices between each first rectangle and the triangle primitive, and the positional relationship between the overlapping vertices and the first tangent and the second tangent, and determining, for a pixel point located within a first rectangle that is not of the first type, two right-angled sides of the corresponding target right triangle;
[0040] When the number of overlapping vertices between a first rectangle and a triangle primitive is one and the overlapping vertex is not located on the first tangent line or the second tangent line, the first rectangle is a first rectangle of the third type, and the two right-angled sides of the corresponding target right triangle are respectively the second Y-direction side of the circumscribed rectangle and a line segment on the first X-direction side of the circumscribed rectangle that is aligned with the X-direction side of the first rectangle; or, the two right-angled sides of the corresponding target right triangle are respectively the line segment on the first Y-direction side of the circumscribed rectangle that is aligned with the Y-direction side of the first rectangle and the second X-direction side of the circumscribed rectangle; the first Y-direction side and the first X-direction side are respectively the Y-direction side and the X-direction side of the circumscribed rectangle that do not overlap with the first rectangle; the second Y-direction side and the second X-direction side are respectively the Y-direction side and the X-direction side of the circumscribed rectangle that overlap with the first rectangle;
[0041] When the number of coincident vertices between a first rectangle and a triangle primitive is 2, and one coincident vertex is located on both the first and second tangents, the other coincident vertex is not located on the first and second tangents, and the corresponding (Lx / Ly) is less than (Wx / Wy), the first rectangle is a first rectangle of the third type, and the two right-angled sides of the corresponding target right triangle are respectively the corresponding first Y-direction side and the corresponding second X-direction side; or, the two right-angled sides of the corresponding target right triangle are respectively the Y-direction side of the first rectangle that does not coincide with the second tangent and the X-direction side that coincides with the first tangent; Lx and Ly are respectively the lengths of the X-direction side and the Y-direction side of the first rectangle, and Wx and Wy are respectively the lengths of the X-direction side and the Y-direction side of the circumscribed rectangle;
[0042] When the number of overlapping vertices between a first rectangle and a triangle primitive is two, one overlapping vertex is located on both the first and second tangent lines, the other overlapping vertex is not located on the first and second tangent lines, and the corresponding (Lx / Ly) is greater than (Wx / Wy), the first rectangle is a first rectangle of the third type, and the two right-angled sides of the corresponding target right triangle are the corresponding second Y-direction side and the first X-direction side, respectively; or, the two right-angled sides of the corresponding target right triangle are the Y-direction side of the first rectangle that overlaps with the second tangent line and the X-direction side that does not overlap with the first tangent line.
[0043] In some embodiments, the above rasterization method further includes:
[0044] Determine, based on the vertex coordinates of the triangle primitive, the vertex coordinates of the circumscribed rectangle, and the vertex coordinates of each first rectangle, the number of overlapping vertices between each first rectangle and the triangle primitive, and the positional relationship between the overlapping vertices and the first tangent and the second tangent;
[0045] Determining the type of each first rectangle based on the number of overlapping vertices between each first rectangle and the triangle primitive, and the positional relationship between the overlapping vertices and the first tangent and the second tangent, and determining, for a pixel point located within a first rectangle that is not of the first type, two right-angled sides of the corresponding target right triangle;
[0046] When the number of overlapping vertices between a first rectangle and a triangle primitive is 1 and the overlapping vertex is not located on the first tangent or the second tangent, the first rectangle is a third type first rectangle, and the two right-angled sides of the corresponding target right triangle are the second tangent and the X-direction side of the first rectangle that does not overlap with the first tangent; or, the two right-angled sides of the corresponding target right triangle are the Y-direction side of the first rectangle that does not overlap with the second tangent and the first tangent;
[0047] When the number of coincident vertices between a first rectangle and a triangle primitive is 2, and one coincident vertex is located on both the first tangent and the second tangent, the other coincident vertex is not located on the first tangent and the second tangent, and the corresponding (Lx / Ly) is less than (Wx / Wy), the first rectangle is a first rectangle of the third type, and the two right-angled sides of the corresponding target right triangle are respectively the second Y-direction side and the first X-direction side of the circumscribed rectangle; or, the two right-angled sides of the corresponding target right triangle are respectively the Y-direction side of the first rectangle that coincides with the second tangent and the X-direction side that does not coincide with the first tangent;
[0048] When the number of coincident vertices between a first rectangle and a triangle primitive is 2, and one coincident vertex is located on both the first and second tangent lines, the other coincident vertex is not located on the first and second tangent lines, and the corresponding (Lx / Ly) is greater than (Wx / Wy), the first rectangle is a first rectangle of the third type, and the two right-angled sides of the corresponding target right triangle are respectively the first Y-direction side and the second X-direction side of the circumscribed rectangle; or, the two right-angled sides of the corresponding target right triangle are respectively the Y-direction side of the first rectangle that does not coincide with the second tangent line and the X-direction side that coincides with the first tangent line;
[0049] The first Y-direction side and the first X-direction side are respectively the Y-direction side and the X-direction side of the circumscribed rectangle that do not overlap with the first rectangle; the second Y-direction side and the second X-direction side are respectively the Y-direction side and the X-direction side of the circumscribed rectangle that overlap with the first rectangle.
[0050] In some embodiments, in the above-mentioned rasterization method, when the number of overlapping vertices between a first rectangle and a triangle primitive is 1, and the overlapping vertex is located on both the first tangent and the second tangent, and the corresponding (Lx / (Wy-Ly)) is less than (Wx / Wy) and ((Wx-Lx) / Ly) is greater than (Wx / Wy), the first rectangle is a first rectangle of the first type; Lx and Ly are the lengths of the X-direction side and the Y-direction side of the first rectangle, respectively, and Wx and Wy are the lengths of the X-direction side and the Y-direction side of the circumscribed rectangle, respectively.
[0051] In some embodiments, the above-mentioned rasterization method further includes: determining the first rectangle where each pixel point in the circumscribed rectangle is located according to the vertex coordinates of each first rectangle.
[0052] In some embodiments, in the above rasterization method, determining whether some or all pixels within each first rectangle are inside a triangle primitive includes the following steps:
[0053] The pixels within the circumscribed rectangle are scanned row by row or column by column. For each scanned pixel, the first rectangle in which it is located is determined, and it is judged whether it is inside the triangle primitive.
[0054] In some embodiments, the above rasterization method scans the pixels within the circumscribed rectangle row by row, determines the first rectangle in which each scanned pixel lies, and determines whether the pixel is inside the triangle primitive, including the following steps:
[0055] Scan the pixels within the circumscribed rectangle line by line;
[0056] Scan the current row from one edge of the circumscribed rectangle to the other. For each scanned pixel, determine the first rectangle it is in and whether it is inside the triangle primitive. If so, stop scanning in that direction and the current pixel becomes the first pixel.
[0057] Scan the current row in reverse from the other edge. For each pixel found, determine the first rectangle it is in and whether it is inside the triangle primitive. If so, end scanning the current row and the current pixel becomes the second pixel.
[0058] The first pixel point, the second pixel point, and all pixel points between the first pixel point and the second pixel point in the current row are all inside the triangle primitive.
[0059] In some embodiments, the above rasterization method scans the pixels within the circumscribed rectangle column by column, determines the first rectangle in which each scanned pixel lies, and determines whether the pixel is inside the triangle primitive, including the following steps:
[0060] Scan the pixels within the circumscribed rectangle column by column;
[0061] Scan the current column from one edge of the circumscribed rectangle to the other. For each target pixel found, determine the first rectangle it is in and whether it is inside the triangle primitive. If so, stop scanning in that direction and the current pixel becomes the first pixel.
[0062] Scan the current column in reverse from the other edge. For each pixel found, determine the first rectangle it is in and whether it is inside the triangle primitive. If so, end scanning the current column and the current pixel becomes the second pixel.
[0063] The first pixel point, the second pixel point, and all pixel points between the first pixel point and the second pixel point in the current column are all inside the triangle primitive.
[0064] According to another aspect of the present disclosure, a rasterization processor is provided, comprising:
[0065] an information acquisition module configured to determine vertex coordinates of a first rectangle based on vertex coordinates of a triangle primitive to be rasterized and vertex coordinates of a circumscribed rectangle of the triangle primitive, wherein the circumscribed rectangle is divided into at least one first rectangle by a first tangent and a second tangent, wherein the first tangent is an X-direction tangent at a first vertex of the triangle primitive, and the second tangent is a Y-direction tangent at a second vertex of the triangle primitive, wherein the first vertex is a vertex in the triangle primitive having a center Y coordinate value or having the same Y coordinate value, and the second vertex is a vertex in the triangle primitive having a center X coordinate value or having the same X coordinate value;
[0066] The judgment module is configured to judge whether some or all of the pixels in each first rectangle are inside the triangle primitive using the following methods:
[0067] For a pixel point located within a first rectangle of a first type, determining that the pixel point is outside the triangle primitive, where the first rectangle of the first type refers to a first rectangle that does not overlap with the triangle primitive;
[0068] For pixel points located in the first rectangle that is not of the first type, determine whether the pixel point is inside the triangle primitive based on the distance from the pixel point to the two right-angled sides of the target right triangle and the principle of geometric proportion of similar triangles. The right-angled side of the target right triangle coincides with the side of the corresponding first rectangle, and the hypotenuse of the target right triangle is the target side of the triangle primitive. The target side of the triangle primitive is the side covered by the first rectangle corresponding to the target right triangle.
[0069] According to another aspect of the present disclosure, a graphics processing system is provided, comprising the graphics processor according to any one of the above embodiments.
[0070] According to another aspect of the present disclosure, an electronic component is provided, comprising the graphics processing system according to any one of the above embodiments.
[0071] According to another aspect of the present disclosure, an electronic device is provided, comprising the electronic component of any one of the above embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0072] FIG1 is a schematic diagram of a flow chart of a rasterization method provided by one embodiment of the present disclosure;
[0073] FIG2 is a schematic diagram of dividing a circumscribed rectangle of a triangle primitive according to an embodiment of the present disclosure;
[0074] FIG3 is a schematic diagram of dividing the circumscribed rectangle of another triangle primitive provided by an embodiment of the present disclosure;
[0075] FIG4 is a schematic diagram of dividing the circumscribed rectangle of another triangle primitive provided by an embodiment of the present disclosure;
[0076] FIG5 is a schematic diagram of dividing the circumscribed rectangle of another triangle primitive provided by one embodiment of the present disclosure;
[0077] FIG6 is a schematic diagram showing the division of the circumscribed rectangle of another triangle primitive provided by an embodiment of the present disclosure;
[0078] FIG7 is a schematic diagram of the positional relationship between a target pixel and a triangle primitive provided by one embodiment of the present disclosure;
[0079] FIG8 is a schematic diagram of the positional relationship between another target pixel point and a triangle primitive provided by an embodiment of the present disclosure;
[0080] FIG9 is a schematic diagram of the positional relationship between another target pixel point and a triangle primitive provided by an embodiment of the present disclosure;
[0081] FIG10 is a schematic diagram of the positional relationship between another target pixel point and a triangle primitive provided by an embodiment of the present disclosure;
[0082] FIG11 is a schematic diagram of the positional relationship between another target pixel point and a triangle primitive provided by an embodiment of the present disclosure;
[0083] FIG12 is a schematic diagram of the positional relationship between another target pixel point and a triangle primitive provided by an embodiment of the present disclosure;
[0084] FIG13 is a schematic diagram of the positional relationship between another target pixel point and a triangle primitive provided by an embodiment of the present disclosure;
[0085] FIG14 is a schematic diagram of the positional relationship between another target pixel point and a triangle primitive provided by an embodiment of the present disclosure;
[0086] FIG15 is a schematic diagram of pixel scanning according to an embodiment of the present disclosure;
[0087] FIG16 is a schematic diagram of the structure of a graphics processor provided by an embodiment of the present disclosure. DETAILED DESCRIPTION
[0088] Before introducing the embodiments of the present disclosure, it should be noted that:
[0089] Some embodiments of the present disclosure are described as processing flows. Although the various operation steps of the flow may be given sequential step numbers, the operation steps therein may be implemented in parallel, concurrently, or simultaneously.
[0090] In the embodiments of the present disclosure, the terms "first", "second", etc. may be used to describe various features, but these features should not be limited by these terms. These terms are used only to distinguish one feature from another.
[0091] The term “and / or” may be used in embodiments of the present disclosure. “And / or” includes any and all combinations of one or more of the listed associated features.
[0092] It should be understood that when describing the connection relationship or communication relationship between two components, unless it is explicitly stated that the two components are directly connected or directly communicating, the connection or communication between the two components can be understood as direct connection or communication, or as indirect connection or communication through an intermediate component.
[0093] In order to make the technical solutions and advantages of the embodiments of the present disclosure more clearly understood, the exemplary embodiments of the present disclosure are further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present disclosure, and are not an exhaustive list of all the embodiments. It should be noted that the embodiments and features in the embodiments of the present disclosure can be combined with each other unless they conflict.
[0094] The purpose of the present disclosure is to provide a rasterization method, processor, system and electronic device, the method comprising: determining the vertex coordinates of a first rectangle according to the vertex coordinates of a triangle primitive to be rasterized and the vertex coordinates of a circumscribed rectangle of the triangle primitive, the circumscribed rectangle being divided into at least one first rectangle by a first tangent and a second tangent; for some or all of the pixel points within each first rectangle, judging whether they are inside the triangle primitive in the following manner: for a pixel point located within a first rectangle of a first type, determining whether the pixel point is outside the triangle primitive, the first rectangle of the first type refers to a first rectangle that does not overlap with the triangle primitive; for a pixel point located within a first rectangle that is not of the first type, judging whether the pixel point is inside the triangle primitive based on the distance from the pixel point to the two right-angled sides of a target right triangle and the principle of geometric proportion of similar triangles, the right-angled side of the target right triangle coincides with the side of the corresponding first rectangle, and the hypotenuse of the target right triangle is the target side of the triangle primitive, and the target side of the triangle primitive is the side covered by the first rectangle corresponding to the target right triangle.
[0095] In other words, for the triangular primitives to be rasterized, based on the principle of geometric relationship of similar triangles, simple addition, subtraction, multiplication and division operations can be used to determine whether the pixel point is inside the triangular primitive, reducing complex calculations and greatly saving the hardware resources and power consumption required for the rasterization process.
[0096] An embodiment of the present disclosure provides a rasterization method, as shown in FIG1 , including:
[0097] Step S110: determining vertex coordinates of a first rectangle according to vertex coordinates of a triangle primitive to be rasterized and vertex coordinates of a circumscribed rectangle of the triangle primitive, wherein the circumscribed rectangle is divided into at least one first rectangle by a first tangent and a second tangent, wherein the first tangent is an X-direction tangent of a first vertex of the triangle primitive, and the second tangent is a Y-direction tangent of a second vertex of the triangle primitive, wherein the first vertex is a vertex in the triangle primitive having a center Y coordinate value or having the same Y coordinate value, and the second vertex is a vertex in the triangle primitive having a center X coordinate value or having the same X coordinate value;
[0098] Step S120: For each pixel point in the first rectangle, determine whether it is inside the triangle primitive using the following method:
[0099] For a pixel point located within a first rectangle of a first type, determining that the pixel point is outside the triangle primitive, where the first rectangle of the first type refers to a first rectangle that does not overlap with the triangle primitive;
[0100] For pixel points located in the first rectangle that is not of the first type, determine whether the pixel point is inside the triangle primitive based on the distance from the pixel point to the two right-angled sides of the target right triangle and the principle of geometric proportion of similar triangles. The right-angled side of the target right triangle coincides with the side of the corresponding first rectangle, and the hypotenuse of the target right triangle is the target side of the triangle primitive. The target side of the triangle primitive is the side covered by the first rectangle corresponding to the target right triangle.
[0101] Among them, in the graphics rendering process of the GPU, usually in the vertex shading stage (vertex shading), all graphics in the image to be rendered in space are divided into multiple primitives, such as triangle primitives. At the same time, the two-dimensional coordinates of each vertex of the primitive are obtained, that is, the X-axis coordinate and the Y coordinate. Then, the depth information (that is, the Z coordinate) of the three vertices of each triangle primitive is calculated and stored in the video memory. Then, in the fragment shading stage (Fragment Shading), the two-dimensional coordinates (X coordinate and Y coordinate) and depth information (Z coordinate) of the vertices of the triangle primitive are read from the video memory for rasterization, and the 3D graphics are mapped to the 2D plane. On the 2D plane, only the pixels in the triangle primitive will be rendered by the GPU in the subsequent logic.
[0102] It should be noted that the vertex coordinates or point coordinates mentioned in this disclosure refer to two-dimensional coordinates on a 2D plane.
[0103] In step S110 , the vertex coordinates of the triangle primitive to be rasterized are read from the video memory.
[0104] The vertex coordinates of the circumscribed rectangle are calculated in advance based on the vertex coordinates of the triangle primitive.
[0105] The sides of the circumscribed rectangle are along the X and Y directions respectively. The vertex coordinates of the circumscribed rectangle of the triangle primitive are calculated as follows: by comparing the X coordinates of the three vertices of the triangle primitive, the minimum X coordinate Xmin and the maximum X coordinate Xmax are obtained; by comparing the Y coordinates of the three vertices of the triangle primitive, the minimum Y coordinate Ymin and the maximum Y coordinate Ymax are obtained. The four vertices of the circumscribed rectangle are (Xmin, Ymin), (Xmin, Ymax), (Xmax, Ymin), and (Xmax, Ymax).
[0106] In some embodiments, the vertex coordinates of the circumscribed rectangle of the triangle primitive, the coordinates of the intersection of the first tangent and the second tangent, and the vertex coordinates of each first rectangle obtained during the above-mentioned rasterization method can be temporarily stored inside the GPU hardware, such as in various registers, after determination. When the corresponding coordinate information is needed, it can be read from the corresponding register.
[0107] It should be noted that there is no obvious order restriction relationship between the above-mentioned steps S110 and S120. All the first rectangles can be divided first (the vertex coordinates of each first rectangle are determined) and then step S120 is performed. Alternatively, the vertex coordinates of a first rectangle can be obtained to determine whether the pixel points in the first rectangle are inside the triangle primitive.
[0108] In step S110, the process of determining the first tangent line is also the process of determining the coordinates of the first tangent line (Y=Ymid) based on the Y coordinates of the three vertices of the triangle primitive. The process of determining the second tangent line is also the process of determining the coordinates of the second tangent line (X=Xmid) based on the X coordinates of the three vertices of the triangle primitive.
[0109] Specifically, when two of the three vertices of the triangle primitive have the same X coordinate, Xmid in the coordinates of the second tangent line (X=Xmid) is equal to the X coordinates of the two vertices; when the three vertices of the triangle primitive have different X coordinates, Xmid in the coordinates of the second tangent line (X=Xmid) is equal to the median of the X coordinates of the three vertices of the triangle primitive;
[0110] When there are two vertices with the same Y coordinate among the three vertices of the triangle primitive, the Ymid in the first tangent coordinate (Y=Ymid) is equal to the Y coordinates of the two vertices. When the Y coordinates of the three vertices of the triangle primitive are different, the Ymid in the first tangent coordinate (Y=Ymid) is equal to the median of the Y coordinates of the three vertices of the triangle primitive.
[0111] For example, as shown in Figure 2, the vertex coordinates of the triangle primitive are A(X1, Y1), B(X2, Y2), and C(X3, Y3). If the X coordinates of points A, B, and C are arranged in ascending order, X2<X1<X3, and if the Y coordinates of points A, B, and C are arranged in ascending order, Y2<Y3<Y1, then the vertex coordinates of the circumscribed rectangle of the triangle primitive are E(X2, Y1), B(X2, Y2), F(X3, Y1), and G(X3, Y2). The coordinate of the first tangent is Y=Y3, and the coordinate of the second tangent is X=X1.
[0112] In actual application, tangents are not actually made. Instead, the vertex coordinates of the first rectangle are determined by determining the coordinates of the first tangent and the second tangent. That is, in step S110, the process of dividing the circumscribed rectangle into at least one first rectangle by the first tangent and the second tangent is the process of determining the vertex coordinates of the first rectangle.
[0113] In some embodiments, based on the coordinates Y=Ymid of the first tangent and X=Xmid of the second tangent, the vertices and their coordinates among the four vertices of the circumscribed rectangle whose X coordinates are not equal to Xmid and whose Y coordinates are not equal to Ymid can be determined as target vertices, that is, the target vertices do not coincide with the intersection of the first tangent and the second tangent. Then, for each target vertex, the vertex coordinates of the first rectangle are obtained by taking the target vertex and the intersection of the first tangent and the second tangent as the diagonal points of the corresponding first rectangle. The sides of the first rectangle are respectively along the X direction and the Y direction.
[0114] For example, as shown in Figure 2, the vertex coordinates of the circumscribed rectangle of the triangle primitive ABC are E(X2, Y1), B(X2, Y2), F(X3, Y1), and G(X3, Y2), the coordinates of the first tangent are Y=Y3, the coordinates of the second tangent are X=X1, the coordinates of the intersection of the first tangent and the second tangent are K(X1, Y3), and the four vertices of the circumscribed rectangle do not coincide with the intersection of the first tangent and the second tangent. Then the four vertices of the circumscribed rectangle are all target vertices. Then, the target vertex F(X3, Y1) and the intersection point K(X1, Y3) are used as the diagonal points of the corresponding first rectangle, and the coordinates of the other two vertices of the first rectangle are obtained, namely (X1, Y1) and (X3, Y3), respectively. For point A and point C, the first rectangle is also the first rectangle AFCK in Figure 2, that is, the vertex coordinates of the first rectangle AFCK are A(X1, Y1), F(X3, Y1), C(X3, Y3), and K(X1, Y3); similarly, the vertex coordinates of the first rectangle DEAK are D(X2, Y3), E(X2, Y1), A(X1, Y1), and K(X1, Y3), the vertex coordinates of the first rectangle CGHK are C(X3, Y3), G(X3, Y2), H(X1, Y2), and K(X1, Y3), and the vertex coordinates of the first rectangle BDKH are B(X2, Y2), D(X2, Y3), K(X1, Y3), and H(X1, Y2).
[0115] For example, as shown in Figure 3, the vertex coordinates of the triangle primitive ABC are A(X1, Y1), B(X2, Y2), and C(X3, Y3), and the vertex coordinates of the circumscribed rectangle are A(X1, Y1), E(X2, Y1), B(X2, Y2), and G(X1, Y2). The coordinate of the first tangent is Y=Y3, the coordinate of the second tangent is X=X3, and the intersection of the first tangent and the second tangent is C(X3, Y3). The four vertices of the circumscribed rectangle do not coincide with the intersection of the first tangent and the second tangent. Then the four vertices of the circumscribed rectangle are all target vertices. Then, the target vertex A(X1, Y1) and the intersection point C(X3, Y3) are used as the diagonal points of the corresponding first rectangle, and the coordinates of the other two vertices of the first rectangle are obtained. 3), and the vertex coordinates of the first rectangle BDCH are B(X2,Y2), D(X2,Y3), C(X3,Y3), and H(X3,Y2).
[0116] In some embodiments, according to the above-mentioned division method of the first rectangle, when the intersection point of the first tangent line and the second tangent line coincides with a vertex of the circumscribed rectangle, the first rectangle coincides with the circumscribed rectangle;
[0117] When the intersection of the first tangent and the second tangent does not coincide with any vertex of the circumscribed rectangle, but one side of the circumscribed rectangle coincides with the first tangent or the second tangent, the number of first rectangles is 2;
[0118] When the intersection point of the first tangent line and the second tangent line does not coincide with any vertex of the circumscribed rectangle and the side of the circumscribed rectangle does not coincide with the first tangent line or the second tangent line, the number of first rectangles is 4.
[0119] For example, when the intersection of the first tangent and the second tangent coincides with a vertex of the circumscribed rectangle, it means that among the three vertices of the triangle primitive, the X coordinate and Y coordinate of one vertex are respectively the same as the X coordinate and Y coordinate of the other two vertices, as shown in Figure 4, that is, the triangle primitive is a right triangle, and its right angles are respectively along the X direction and the Y direction, and the right angle vertex is the intersection of the first tangent and the second tangent. In Figure 4, the vertex coordinates of the triangle primitive are A(X1, Y1), B(X1, Y3), and C(X3, Y3), the coordinates of the first tangent are Y=Y3, the coordinates of the second tangent are X=X1, the coordinates of the intersection of the first tangent and the second tangent are B(X1, Y3), the vertex coordinates of the circumscribed rectangle are A(X1, Y1), B(X1, Y3), C(X3, Y3), and E(X3, Y1), and the first rectangle coincides with the circumscribed rectangle.
[0120] When the intersection of the first and second tangents does not coincide with any vertex of the circumscribed rectangle, but one side of the circumscribed rectangle coincides with the first or second tangent, it indicates that one side of the triangle primitive is along the X or Y direction. That is, two of the three vertices have the same X coordinate or the same Y coordinate, as shown in Figures 5 and 6. In Figure 5, the vertex coordinates of the triangle primitive are A(X1, Y1), B(X2, Y3), and C(X3, Y3), the coordinates of the first tangent are Y=Y3, the coordinates of the second tangent are X=X1, the coordinates of the intersection of the first and second tangents are K(X1, Y3), and the coordinates of the vertices of the circumscribed rectangle are E(X2, Y1), B(X2, Y3), C(X3, Y3), and F(X3, Y1). The vertex coordinates of one first rectangle AEBK are A(X1, Y1), E(X2, Y1), B(X2, Y3), and K(X1, Y3). The vertex coordinates of the other first rectangle AFCK are A(X1, Y1), F(X3, Y1), C(X3, Y3), and K(X1, Y3). In Figure 6, the vertex coordinates of the triangle primitive are A(X1, Y1), B(X2, Y2), and C(X3, Y2). The coordinates of the first tangent are Y=Y2, the coordinates of the second tangent are X=X3, the intersection of the first and second tangents is C(X3, Y2), and the vertex coordinates of the circumscribed rectangle are A(X1, Y1), E(X2, Y1), B(X2, Y3), and G(X1, Y2). The vertex coordinates of a first rectangle AFCG are A(X1, Y1), F(X3, Y1), C(X3, Y2), and G(X1, Y2), and the vertex coordinates of another first rectangle BEFC are B(X2, Y3), E(X2, Y1), F(X3, Y1), and C(X3, Y2).
[0121] When the intersection of the first tangent and the second tangent does not coincide with any vertex of the circumscribed rectangle, and the side of the circumscribed rectangle does not coincide with the first tangent or the second tangent, it means that the X coordinates and Y coordinates of the three vertices of the triangle primitive are different, as shown in Figures 2 and 3.
[0122] In some embodiments, the above method further includes determining the first rectangle where each pixel point within the circumscribed rectangle is located based on the vertex coordinates of each first rectangle.
[0123] Specifically, the first rectangle is determined by judging whether the coordinates of each pixel point fall within the coordinate range of the first rectangle.
[0124] The coordinates of a pixel point falling within the coordinate range of a first rectangle means that the X coordinate of the pixel point falls within the X coordinate range of the first rectangle and the Y coordinate of the pixel point falls within the Y coordinate range of the first rectangle.
[0125] For example, in the triangle primitive shown in FIG2 , the vertex coordinates of the first rectangle AFCK are A(X1, Y1), F(X3, Y1), C(X3, Y3), K(X1, Y3), whose X coordinate range is X1 to X3, and whose Y coordinate range is Y3 to Y1. The vertex coordinates of the first rectangle DEAK are D(X2, Y3), E(X2, Y1), A(X1, Y1), K(X1, Y3), whose X coordinate range is X2 to X1, and whose Y coordinate range is Y3 to Y1. The vertex coordinates of the first rectangle CGHK are C(X3, Y3), G(X3, Y2), H( The first rectangle BDKH has vertex coordinates B(X2,Y2), D(X2,Y3), K(X1,Y3), and H(X1,Y2), whose X coordinate range is X2 to X1 and Y coordinate range is Y2 to Y3. The first rectangle BDKH has vertex coordinates B(X2,Y2), D(X2,Y3), K(X1,Y3), and H(X1,Y2), whose X coordinate range is X2 to X1 and Y coordinate range is Y2 to Y3. Therefore, if the X coordinate Xp and Y coordinate Xp of the pixel point P(Xp,Yp) fall within the X coordinate range and Y coordinate range of the same first rectangle respectively, then the first rectangle can be determined to be the first rectangle where the pixel point (Xp,Yp) is located.
[0126] One implementation method of the above-mentioned step S120 is to determine the first rectangle in which the pixel points within the circumscribed rectangle are located one by one, and then use the method in step S120 to determine whether they are inside the triangle primitive. Another implementation method is to traverse the pixel points within a first rectangle to determine whether they are inside the triangle primitive. After the pixel points within the first rectangle are determined, traverse the pixel points within the next first rectangle to determine whether it is inside the triangle primitive.
[0127] It should be noted that in step S120, the hypotenuse of the target right triangle is the target side of the triangle primitive, the target side of the triangle primitive is the side covered by the first rectangle corresponding to the target right triangle (i.e., the current first rectangle), the vertices of the target side are the vertices of the triangle primitive, and the coordinates are known, that is, the coordinates of the two vertices corresponding to the hypotenuse of the target right triangle are known, and the right-angled side of the target right triangle coincides with the side of the corresponding first rectangle, then the coordinates of the right-angled vertices of the target triangle can also be confirmed, then, each vertex of the target triangle can be confirmed. Then, according to the distance from the pixel point to the two right-angled sides of the target right triangle, based on the principle of geometric relationship of similar triangles, it is determined whether the pixel point is inside the triangle primitive. The specific calculation principle is as shown in Figure 4. Since there is only one first rectangle, there are two target right triangles that meet the conditions that the right angle side of the target right triangle coincides with the side of the corresponding first rectangle, the hypotenuse of the target right triangle is the target side of the triangle primitive, and the target side of the triangle primitive is the side covered by the first rectangle corresponding to the target right triangle, namely triangle ABC or triangle AEC. Taking triangle ABC as the target right triangle as an example, the distances from pixel point P to the two right angles of triangle ABC are D1 and D2 respectively. Based on the principle of geometric proportion of similar triangles, when (D1 / (AB-D2)) is less than or equal to (BC / AB), it means that pixel point P is inside the triangle primitive. When (D1 / (AB-D2)) is greater than (BC / AB), it means that pixel point P is outside the triangle primitive. Since the vertex coordinates of the target right triangle (ABC) and the coordinates of pixel point P are known, the values of D1, D2, BC, and AB can be calculated based on these coordinates through simple subtraction. Taking triangle AEC as an example, the distances from pixel point P to the two right-angled sides of triangle AEC are D1' and D2', respectively. Based on the principle of geometric proportions for similar triangles, when (D1' / (EC - D2')) is greater than or equal to (AE / EC), pixel point P is inside the triangle primitive. When (D1' / (EC - D2')) is less than (AE / EC), pixel point P is outside the triangle primitive. Since the vertex coordinates of the target right triangle (AEC) and the coordinates of pixel point P are known, the values of D1', D2', AE, and EC can be calculated using these coordinates through simple subtraction.
[0128] In step S120, the right-angled side of the target right triangle overlaps with the side of the corresponding first rectangle, which may be partially overlapped or completely overlapped. The target side of the triangle primitive is the side partially or completely covered by the first rectangle corresponding to the target right triangle.
[0129] In some embodiments, in step S120, for a pixel point located within the first rectangle that is not of the first type, determining whether the pixel point is inside the triangle primitive based on the distance between the pixel point and two right-angled sides of the target right triangle and the principle of geometric proportions of similar triangles includes:
[0130] a) For a pixel point located within the first rectangle of the second type, determine whether (D1 / (L1-D2)) is greater than (L2 / L1) based on the distance D1 and the distance D2 from the pixel point to the first right-angled side and the second right-angled side of the target right triangle, as well as the length L1 and the length L2 of the first right-angled side. If so, determine that the pixel point is outside the triangle primitive; otherwise, determine that the pixel point is inside the triangle primitive. The first rectangle of the second type refers to the first rectangle whose overlapping portion with the triangle primitive is a right triangle, and the target right triangle is the overlapping portion or the first similar triangle of the overlapping portion; the first similar triangle covers the overlapping portion; or,
[0131] b) For a pixel point located within the first rectangle of the second type, determine whether (D1' / (L1-D2')) is less than (L2 / L1) based on the distance D1' and the distance D2' from the pixel point to the first right-angled side and the second right-angled side of the target right triangle, as well as the length L1 of the first right-angled side and the length L2 of the second right-angled side. If so, determine that the pixel point is outside the triangle primitive; otherwise, determine that the pixel point is inside the triangle primitive. The first rectangle of the second type refers to the first rectangle whose overlapping portion with the triangle primitive is a right triangle, and the target right triangle is the second similar triangle of the overlapping portion; the second similar triangle does not cover the overlapping portion.
[0132] Corresponding to the first rectangle of the second type, the overlapping part with the triangle primitive is a right triangle, and the non-overlapping part is not necessarily a right triangle. Therefore, based on the overlapping part of the first rectangle and the triangle primitive, combined with the target right triangle being the overlapping part or a similar triangle of the overlapping part, and the right-angled side of the target right triangle coinciding with the side of the corresponding first rectangle, and the hypotenuse of the target right triangle being the target side of the triangle primitive, and the target side of the triangle primitive being the side covered by the first rectangle corresponding to the target right triangle, the target right triangle (a right triangle with known vertex coordinates) can be determined. In the determined target right triangle, according to the distance from the pixel point to the two right-angled sides of the target right triangle, based on the principle of geometric proportion of similar triangles, it is judged whether the pixel point is inside the triangle primitive.
[0133] Exemplarily, as shown in FIG2 , the first rectangle AFCK is a first rectangle of the second type. The target right triangle corresponding to the first rectangle AFCK that satisfies the above condition a) is triangle DCB, and the target right triangle that satisfies the above condition b) is triangle CBG.
[0134] In some embodiments, the above rasterization method further includes:
[0135] Determine, based on the vertex coordinates of the triangle primitive, the vertex coordinates of the circumscribed rectangle, and the vertex coordinates of each first rectangle, the number of overlapping vertices between each first rectangle and the triangle primitive, and the positional relationship between the overlapping vertices and the first tangent and the second tangent;
[0136] Based on the number of overlapping vertices between each first rectangle and the triangle primitive, and the positional relationship between the overlapping vertices and the first tangent and the second tangent, the type of each first rectangle is determined, and for the pixel points located in the first rectangle that is not of the first type, the two right-angled sides of the corresponding target right triangle are determined.
[0137] It can be understood that while determining the type of each first rectangle based on the number of overlapping vertices between each first rectangle and the triangle primitive, and the positional relationship between the overlapping vertices and the first tangent and the second tangent, the two right-angled sides of the target right triangle corresponding to each first rectangle can be determined at the same time.
[0138] In some embodiments, corresponding to the above situation a):
[0139] a.1) When the number of overlapping vertices between a first rectangle and a triangle primitive is one, the overlapping vertex is located on both the first tangent and the second tangent, and the corresponding ((Wx-Lx) / Ly) is less than (Wx / Wy) and (Lx / (Wy-Ly)) is greater than (Wx / Wy), the first rectangle is a first rectangle of the second type. For a pixel point within the first rectangle, the two right-angled sides of the corresponding target right triangle are, respectively, the first Y-direction side and the first X-direction side of the circumscribed rectangle; the first Y-direction side and the first X-direction side of the circumscribed rectangle that do not overlap with the first rectangle; the Y-direction side and the X-direction side of the circumscribed rectangle that overlap with the first rectangle are, respectively, the second Y-direction side and the second X-direction side; Lx and Ly are the lengths of the X-direction side and the Y-direction side of the first rectangle, respectively; and Wx and Wy are the lengths of the X-direction side and the Y-direction side of the circumscribed rectangle, respectively.
[0140] a.2) When the number of overlapping vertices between a first rectangle and a triangle primitive is one and the overlapping vertex is located on the first tangent line but not on the second tangent line, the first rectangle is a first rectangle of the second type, and the two right-angled sides of the corresponding target right triangle are the line segment on the corresponding first Y-direction edge aligned with the Y-direction edge of the first rectangle and the first tangent line, respectively;
[0141] a.3) When the number of overlapping vertices between a first rectangle and a triangle primitive is one and the overlapping vertex is located on the second tangent line but not on the first tangent line, the first rectangle is a first rectangle of the second type, and the two right-angled sides of the corresponding target right triangle are respectively the second tangent line and a line segment on the corresponding first X-direction edge that is aligned with the X-direction edge of the first rectangle;
[0142] a.4) When the number of overlapping vertices between a first rectangle and a triangle primitive is two, and both of these overlapping vertices lie on a first tangent line, the first rectangle is a second-type first rectangle, and the two right-angled sides of the corresponding target right triangle are the corresponding first Y-direction side and the first tangent line, respectively. When the number of overlapping vertices between a first rectangle and a triangle primitive is two, and both of these overlapping vertices lie on a second tangent line, the first rectangle is a second-type first rectangle, and the two right-angled sides of the corresponding target right triangle are the second tangent line and the corresponding first X-direction side, respectively.
[0143] a.5) When the number of overlapping vertices between a first rectangle and a triangle primitive is two, and the two overlapping vertices are located on the first tangent and the second tangent, respectively, or when the number of overlapping vertices between a first rectangle and a triangle primitive is three, the first rectangle is a first rectangle of the second type, and the two right-angled sides of the corresponding target right triangle are the Y-direction side of the first rectangle that overlaps with the second tangent and the X-direction side that overlaps with the first tangent, respectively.
[0144] It should be noted that the above-mentioned first tangent refers to the line segment with coordinates Y=Ymid within the circumscribed rectangle, and its length is equal to Wx. The above-mentioned second tangent refers to the line segment with coordinates X=Xmid within the circumscribed rectangle, and its length is equal to Wy. For example, corresponding to the triangle primitive ABC shown in Figure 2, the first tangent is DC (coordinates Y=Y3, length Wx), and the second tangent is AH (coordinates X=X1, length Wy); corresponding to the triangle primitive ABC shown in Figure 3, the first tangent is DJ (coordinates Y=Y3, length Wx), and the second tangent is FH (coordinates X=X3, length Wy).
[0145] Among them, based on the vertex coordinates of the first rectangle, the vertex coordinates of the circumscribed rectangle, and the coordinates of the first tangent and the second tangent obtained above, through simple coordinate comparison, the number of overlapping vertices of each first rectangle and the triangle primitive, as well as the positional relationship between the overlapping vertices and the first tangent and the second tangent can be determined. Corresponding to the triangle primitive ABC shown in Figure 3, the vertex coordinates of the triangle primitive ABC are A(X1, Y1), B(X2, Y2), and C(X3, Y3), and the vertex coordinates of the circumscribed rectangle AEBG are A(X1, Y1), E(X2, Y1), B(X2, Y2), and G(X1, Y2). The vertex coordinates of the first rectangle DEFC are D(X2, Y3), E(X2, Y1), F(X3, Y1), and C(X3, Y3). The coordinates of the first tangent are Y=Y3, and the coordinates of the second tangent are X=X3. Then for the first rectangle DEFC, the vertex that coincides with the triangle primitive ABC is vertex C(X3, Y3), and the coincident vertex C(X3, Y3) is located on both the first tangent (Y=Y3) and the second tangent (X=X3). And if ((Wx-Lx) / Ly) corresponding to the first rectangle DEFC is less than (Wx / Wy) and (Lx / (Wy-Ly)) is greater than (Wx / Wy), then the above situation a.1) is satisfied, and the two right-angled sides of the target right triangle are determined according to the method in the above situation a.1).
[0146] Among them, the side length Lx of the X direction side and the side length Ly of the Y direction side of the above-mentioned first rectangle, and the side length Wx of the X direction side and the side length Wy of the Y direction side of the circumscribed rectangle can all be obtained by simple subtraction based on the vertex coordinates of the first rectangle and the vertex coordinates of the circumscribed rectangle obtained above. 3, the vertex coordinates of the circumscribed rectangle AEBG corresponding to the triangle primitive ABC shown in Figure 3 are A(X1, Y1), E(X2, Y1), B(X2, Y2), and G(X1, Y2). Then, the length Wx of the X-direction side of the circumscribed rectangle AEBG is equal to |X1-X2|, the length Wy of the Y-direction side is equal to |Y1-Y2|, the vertex coordinates of the first rectangle AFCJ are A(X1, Y1), F(X3, Y1), C(X3, Y3), and J(X1, Y3). The length Lx of the X-direction side of the first rectangle AFCJ is equal to |X1-X3| and the length Ly of the Y-direction side is equal to |Y1-Y3|. The vertex coordinates of the first rectangle DEFC are D(X2, Y3), E(X2, Y1), F(X3, Y1), and C(X3, Y3). The length Lx of the X-direction side of the first rectangle CHGJ is equal to |X2-X3|, and the length Ly of the Y-direction side is equal to |Y1-Y3|, the vertex coordinates of the first rectangle CHGJ are C(X3,Y3), H(X3,Y2), G(X1,Y2), and J(X1,Y3), the length Lx of the X-direction side of the first rectangle CHGJ is equal to |X1-X3|, and the length Ly of the Y-direction side is equal to |Y2-Y3|, the vertex coordinates of the first rectangle BDCH are B(X2,Y2), D(X2,Y3), C(X3,Y3), and H(X3,Y2), the length Lx of the X-direction side of the first rectangle BDCH is equal to |X2-X3|, and the length Ly of the Y-direction side is equal to |Y2-Y3|.
[0147] And according to the vertex coordinates of the first rectangle and the vertex coordinates of the circumscribed rectangle obtained above, the first Y-direction side, the first X-direction side, the second Y-direction side and the second X-direction side of the circumscribed rectangle can all be determined. For example, corresponding to the triangle primitive ABC shown in FIG3 , the vertex coordinates of the circumscribed rectangle AEBG are A(X1, Y1), E(X2, Y1), B(X2, Y2), G(X1, Y2), and its four sides are AE (coordinate is Y=Y1), AG (coordinate is X=X1), BE (coordinate is X=X2), BG (coordinate is Y=Y2). For the first rectangle DEFC, its vertex is The point coordinates are D(X2,Y3), E(X2,Y1), F(X3,Y1), and C(X3,Y3). Then the first Y-direction side of the circumscribed rectangle AEBG corresponding to the first rectangle DEFC is AG (coordinate is X=X1, and it does not coincide with any of the vertices of the first rectangle DEFC), the first X-direction side is BG (coordinate is Y=Y2, and it does not coincide with any of the vertices of the first rectangle DEFC), the second Y-direction side is BE (coordinate is X=X2, and it coincides with vertices D and E of the first rectangle DEFC), and the second X-direction side is AE (coordinate is Y=Y1, and it coincides with vertices E and F of the first rectangle DEFC).
[0148] And according to the coordinates of the vertices of the first rectangle and the coordinates of the first tangent and the second tangent obtained above, the X-direction side of the first rectangle that coincides or does not coincide with the first tangent, and the Y-direction side that coincides or does not coincide with the second tangent can also be determined. For example, in the triangle primitive ABC shown in Figure 3, the coordinate of the first tangent is Y=Y3, the coordinate of the second tangent is X=X3, the coordinates of the vertices of the first rectangle DEFC are D(X2,Y3), E(X2,Y1), F(X3,Y1), C(X3,Y3), and the four sides are EF (with coordinate Y=Y1), FC (coordinate is X=X3), DE (coordinate is X=X2), DC (coordinate is Y=Y3), then the X-direction sides of the first rectangle DEFC that coincide with and do not coincide with the first tangent (Y=Y3) are DC (coordinate is Y=Y3, the same as the coordinate of the first tangent) and EF (coordinate is Y=Y1, different from the coordinate of the first tangent), and the Y-direction sides of the first rectangle DEFC that coincide with and do not coincide with the second tangent (X=X3) are FC (coordinate is X=X3, the same as the coordinate of the second tangent) and DE (coordinate is X=X2, different from the coordinate of the second tangent). Similarly, the X-direction side of the circumscribed rectangle that coincides or does not coincide with the first tangent, and the Y-direction side that coincides or does not coincide with the second tangent can also be determined. In the triangle primitive ABC shown in Figure 2 or the triangle primitive ABC shown in Figure 3, the two X-direction sides of the circumscribed rectangle do not coincide with the first tangent, and the two Y-direction sides of the circumscribed rectangle do not coincide with the second tangent. In the triangle primitive ABC shown in Figure 4, the coordinate of the first tangent is Y=Y3, the coordinate of the second tangent is X=X1, and the vertex coordinates of the circumscribed rectangle ABCE are A(X1,Y1), B(X1,Y3), C(X3,Y3), and E(X3,Y1 ), the four sides are AE (coordinate is Y=Y1), EC (coordinate is X=X3), AB (coordinate is X=X1), and BC (coordinate is Y=Y3), then the X-direction sides of the circumscribed rectangle ABCE that coincide with and do not coincide with the first tangent (Y=Y3) are BC (coordinate is Y=Y3, the same as the coordinates of the first tangent) and AE (coordinate is Y=Y1, different from the coordinates of the first tangent), and the Y-direction sides of the circumscribed rectangle ABCE that coincide with and do not coincide with the second tangent (X=X1) are AB (coordinate is X=X1, the same as the coordinates of the second tangent) and EC (coordinate is X=X3, different from the coordinates of the second tangent).
[0149] The above-mentioned information of corresponding edges and tangents (including coordinates and lengths) can be calculated in advance and then placed in corresponding registers. When needed, they can be read from the corresponding registers.
[0150] For example, case a.1) corresponds to the first rectangle DEFC in Figure 3, and the corresponding target right triangle is triangle ABG. The two right-angled sides of the corresponding target right triangle are the first Y-direction side AG (coordinate is X=X1, length is Wy) and the first X-direction side BG (coordinate is Y=Y2, length is Wx) of the circumscribed rectangle. The coordinates and lengths of these two right-angled sides are known. Combined with the coordinates (Xp, Yp) of the pixel point P, through simple subtraction and division operations, the distance D1 from the pixel point to the first right-angled side and the distance D2 from the second right-angled side of the target right triangle, as well as the length L1 of the first right-angled side and the length L2 of the second right-angled side, can be determined to determine whether (D1 / (L1-D2)) is greater than (L2 / L1).
[0151] Case a.2) corresponds to the first rectangle CGHK in Figure 2, and the corresponding target right triangle is triangle CBD. The two right-angled sides of the corresponding target right triangle are the line segment (BD, coordinate X=X2, length Ly) on the corresponding first Y-direction side (coordinate X=X2) aligned with the Y-direction side of the first rectangle and the first tangent DC (coordinate Y=Y3, length Wx).
[0152] Case a.3) corresponds to the first rectangle DEAK in Figure 7 , and the corresponding target right triangle is triangle ABH. The two right-angled sides of the corresponding target right triangle are the second tangent line AH (coordinate X=X1, length Wy) and the line segment BH (coordinate Y=Y2, length Lx) on the corresponding first X-direction side (coordinate Y=Y2) aligned with the X-direction side of the first rectangle.
[0153] Case a.4) corresponds to the first rectangle BEFC in Figure 6, the corresponding target right triangle is triangle ABG, and the two right-angled sides of the corresponding target right triangle are the corresponding first Y-direction side (coordinate is X=X1, length is Wy) and the first tangent BG (coordinate is Y=Y2, length is Wx).
[0154] Case a.5) corresponds to the first rectangle AFCK in Figure 8, the first rectangle ABCE in Figure 4, and the first rectangles AEBK and AFCK in Figure 5. For the first rectangle AFCK in Figure 8, the corresponding target right triangle is triangle AKC, and the two right-angled sides of the corresponding target right triangle are the Y-direction side AK (coordinate X=X1, length Ly) and the X-direction side KC (coordinate Y=Y3, length Lx) where the first rectangle coincides with the second tangent and the first tangent. For the first rectangle ABCE in Figure 4, the corresponding target right triangle is triangle ABC, and the two right-angled sides of the corresponding target right triangle are the Y-direction side AB (coordinate X=X1, length Ly) and the X-direction side BC (coordinate Y=Y3, length Lx) where the first rectangle coincides with the second tangent and the first tangent. ; For the first rectangle AEBK in Figure 5, the corresponding target right triangle is triangle ABK, and the two right-angled sides of the corresponding target right triangle are the Y-direction side AK (coordinate is X=X1, length is Ly) and the X-direction side BK (coordinate is Y=Y3, length is Lx) of the first rectangle coinciding with the second tangent and the first tangent. For the first rectangle AFCK in Figure 5, the corresponding target right triangle is triangle ACK, and the two right-angled sides of the corresponding target right triangle are the Y-direction side AK (coordinate is X=X1, length is Ly) and the X-direction side CK (coordinate is Y=Y3, length is Lx) of the first rectangle coinciding with the second tangent and the first tangent.
[0155] In some embodiments, corresponding to the above situation b):
[0156] When the number of overlapping vertices between a first rectangle and a triangle primitive is 1, the overlapping vertex is located on both the first tangent and the second tangent, and the corresponding ((Wx-Lx) / Ly) is less than (Wx / Wy) and (Lx / (Wy-Ly)) is greater than (Wx / Wy), the first rectangle is a first rectangle of the second type, and for a pixel point within the first rectangle, the two right-angled sides of the corresponding target right triangle are respectively the second Y-direction side and the second X-direction side of the circumscribed rectangle; the second Y-direction side and the second X-direction side are respectively the Y-direction side and the X-direction side of the circumscribed rectangle that overlap with the first rectangle; the Y-direction side and the X-direction side of the circumscribed rectangle that do not overlap with the first rectangle are respectively the first Y-direction side and the first X-direction side; Lx and Ly are respectively the side lengths of the X-direction side and the Y-direction side of the first rectangle, and Wx and Wy are respectively the side lengths of the X-direction side and the Y-direction side of the circumscribed rectangle;
[0157] b.2) When the number of overlapping vertices between a first rectangle and a triangle primitive is one and the overlapping vertex is located on the first tangent line but not on the second tangent line, the first rectangle is a first rectangle of the second type, and the two right-angled sides of the corresponding target right triangle are the Y-direction side of the first rectangle that does not overlap with the second tangent line and the second X-direction side;
[0158] b.3) When the number of overlapping vertices between a first rectangle and a triangle primitive is one and the overlapping vertex is located on the second tangent line but not on the first tangent line, the first rectangle is a first rectangle of the second type, and the corresponding two right-angled sides of the target right triangle are the second Y-direction side and the X-direction side of the first rectangle that does not overlap with the first tangent line.
[0159] Case b.4) When the number of overlapping vertices between a first rectangle and a triangle primitive is two, and both of these overlapping vertices lie on the first tangent line, the first rectangle is a first rectangle of the second type, and the corresponding two right-angled sides of the target right triangle are the corresponding second Y-direction side and the X-direction side of the circumscribed rectangle that does not overlap with the first tangent line. When the number of overlapping vertices between a first rectangle and a triangle primitive is two, and both of these overlapping vertices lie on the second tangent line, the first rectangle is a first rectangle of the second type, and the corresponding two right-angled sides of the target right triangle are the Y-direction side of the circumscribed rectangle that does not overlap with the second tangent line and the corresponding second X-direction side.
[0160] b.5) When the number of overlapping vertices between a first rectangle and a triangle primitive is two, and the two overlapping vertices are located on the first tangent and the second tangent, respectively, or the number of overlapping vertices between a first rectangle and a triangle primitive is three, the first rectangle is a first rectangle of the second type, and the two right-angled sides of the corresponding target right triangle are the Y-direction side of the first rectangle that does not overlap with the second tangent and the X-direction side that does not overlap with the first tangent, respectively.
[0161] For example, case b.1) corresponds to the first rectangle DEFC in Figure 3, and the corresponding target right triangle is triangle ABE. The two right-angled sides of the corresponding target right triangle are the second Y-direction side BE (coordinate is X=X2, length is Wy) and the second X-direction side EA (coordinate is Y=Y1, length is Wx) of the circumscribed rectangle. The coordinates and lengths of these two right-angled sides are known. Combined with the coordinates (Xp, Yp) of the pixel point P, through simple subtraction and division operations, the distance D1' and the distance D2' from the pixel point to the first right-angled side of the target right triangle, as well as the length L1 of the first right-angled side and the length L2 of the second right-angled side, can be determined to determine whether (D1' / (L1-D2')) is less than (L2 / L1).
[0162] Case b.2) corresponds to the first rectangle CGHK in Figure 2, and the corresponding target right triangle is triangle CBG. The two right-angled sides of the corresponding target right triangle are the Y-direction side CG (coordinate X=X3, length Ly) of the first rectangle that does not coincide with the second tangent, and the second X-direction side BG (coordinate Y=Y2, length Wx).
[0163] Case b.3) corresponds to the first rectangle DEAK in Figure 7, and the corresponding target right triangle is triangle ABE. The two right-angled sides of the corresponding target right triangle are the second Y-direction side (coordinate is X=X2, length is Wy) and the X-direction side AE (coordinate is Y=Y1, length is Lx) of the first rectangle that does not coincide with the first tangent.
[0164] Case b.4) corresponds to the first rectangle BEFC in Figure 6, and the corresponding target right triangle is triangle ABE. The two right-angled sides of the corresponding target right triangle are the corresponding second Y-direction side BE (coordinate is X=X2, length is Wy) and the X-direction side AE (coordinate is Y=Y1, length is Wx) of the circumscribed rectangle that does not coincide with the first tangent.
[0165] Case b.5) corresponds to the first rectangle AFCK in Figure 8, the first rectangle ABCE in Figure 4, and the first rectangles AEBK and AFCK in Figure 5. For the first rectangle AFCK in Figure 8, the corresponding target right triangle is triangle AFC, and the two right-angled sides of the corresponding target right triangle are the Y-direction side FC (coordinate X=X3, length Ly) and the X-direction side AF (coordinate Y=Y1, length Lx), where the first rectangle does not overlap with the second tangent and the first tangent. For the first rectangle ABCE in Figure 4, the corresponding target right triangle is triangle AEC, and the two right-angled sides of the corresponding target right triangle are the Y-direction side EC (coordinate X=X3, length Ly) and the X-direction side AE (coordinate Y=Y1, length Lx), where the first rectangle does not overlap with the second tangent and the first tangent. ; For the first rectangle AEBK in Figure 5, the corresponding target right triangle is triangle AEB, and the two right-angled sides of the corresponding target right triangle are the Y-direction side EB (coordinate is X=X2, length is Ly) and the X-direction side EA (coordinate is Y=Y1, length is Lx) of the first rectangle that do not coincide with the second tangent and the first tangent. For the first rectangle AFCK in Figure 5, the corresponding target right triangle is triangle ACF, and the two right-angled sides of the corresponding target right triangle are the Y-direction side FC (coordinate is X=X3, length is Ly) and the X-direction side AF (coordinate is Y=Y1, length is Lx) of the first rectangle that do not coincide with the second tangent and the first tangent.
[0166] In some embodiments, in step S120, for a pixel point located within the first rectangle that is not of the first type, determining whether the pixel point is inside the triangle primitive based on the distance between the pixel point and two right-angled sides of the target right triangle and the principle of geometric proportions of similar triangles includes:
[0167] c) For a pixel point located within the first rectangle of the third type, determine whether (D1 / (L1-D2)) is less than (L2 / L1) based on the distance D1 and the distance D2 from the pixel point to the first right-angled side and the second right-angled side of the target right triangle, as well as the length L1 and the length L2 of the first right-angled side. If so, determine that the pixel point is outside the triangle primitive. The first rectangle of the third type refers to a first rectangle whose overlapping portion with the triangle primitive is a non-right triangle, and the target right triangle is the non-overlapping portion of the corresponding first rectangle and the triangle primitive or the first similar triangle of the non-overlapping portion; the first similar triangle covers the non-overlapping portion and does not cover the overlapping portion of the corresponding first rectangle and the triangle primitive; or
[0168] d) For a pixel point located within the first rectangle of the third type, determine whether (D1' / (L1-D2')) is greater than (L2 / L1) based on the distance D1' and the distance D2' from the pixel point to the first right-angled side and the second right-angled side of the target right triangle, as well as the length L1 of the first right-angled side and the length L2 of the second right-angled side. If so, determine that the pixel point is outside the triangle primitive. The first rectangle of the third type refers to the first rectangle whose overlapping portion with the triangle primitive is a non-right triangle, and the target right triangle is the second similar triangle of the non-overlapping portion of the corresponding first rectangle and the triangle primitive; the second similar triangle covers the overlapping portion of the corresponding first rectangle and the triangle primitive.
[0169] Corresponding to the first rectangle of the third type, the non-overlapping part of the first rectangle and the triangle primitive is a right triangle, and the overlapping part is not necessarily a right triangle. Therefore, based on the non-overlapping part of the first rectangle and the triangle primitive, combined with the target right triangle being a non-overlapping part or a similar triangle of the non-overlapping part and the right-angled side of the target right triangle coinciding with the side of the corresponding first rectangle, and the hypotenuse of the target right triangle being the target side of the triangle primitive, and the target side of the triangle primitive being the side covered by the first rectangle corresponding to the target right triangle, the target right triangle (a right triangle with known vertex coordinates) can be determined. In the determined target right triangle, according to the distance from the pixel point to the two right-angled sides of the target right triangle, based on the similar triangle Based on the principle of geometric proportion, whether the pixel point is inside the target right triangle is determined. In the above case c), since the target right triangle is the non-overlapping part of the corresponding first rectangle and triangle primitive or the first similar triangle of the non-overlapping part, the first similar triangle covers the non-overlapping part and does not cover the overlapping part of the corresponding first rectangle and triangle primitive. Therefore, when the pixel point is inside each target right triangle, it means that the pixel point is outside the triangle. In the above case b), since the target right triangle is the second similar triangle of the non-overlapping part of the corresponding first rectangle and triangle primitive, the second similar triangle covers the overlapping part of the corresponding first rectangle and triangle primitive. Therefore, when the pixel point is outside each target right triangle, it means that the pixel point is outside the triangle.
[0170] Exemplarily, as shown in Figure 9, the first rectangle BDKH is a first rectangle of the third type, and the target right triangle corresponding to the first rectangle BDKH that satisfies the above situation c) is triangle AEB, the target right triangle that satisfies the above situation d) is triangle ABH, or the target right triangle that satisfies the above situation c) is triangle CBG, and the target right triangle that satisfies the above situation d) is triangle CBD.
[0171] In some embodiments, the above rasterization method further includes:
[0172] Determine, based on the vertex coordinates of the triangle primitive, the vertex coordinates of the circumscribed rectangle, and the vertex coordinates of each first rectangle, the number of overlapping vertices between each first rectangle and the triangle primitive, and the positional relationship between the overlapping vertices and the first tangent and the second tangent;
[0173] Based on the number of overlapping vertices between each first rectangle and the triangle primitive, and the positional relationship between the overlapping vertices and the first tangent and the second tangent, the type of each first rectangle is determined, and for the pixel points located in the first rectangle that is not of the first type, the two right-angled sides of the corresponding target right triangle are determined.
[0174] Similarly, while determining the type of each first rectangle based on the number of overlapping vertices between each first rectangle and the triangle primitive, and the positional relationship between the overlapping vertices and the first tangent and the second tangent, the two right-angled sides of the target right triangle corresponding to each first rectangle can be determined at the same time.
[0175] In some embodiments, corresponding to the above situation c):
[0176] c.1) When the number of overlapping vertices between a first rectangle and a triangle primitive is one and the overlapping vertices are not located on the first tangent or the second tangent, the first rectangle is a first rectangle of the third type, and the two right-angled sides of the corresponding target right triangle are respectively the second Y-side of the circumscribed rectangle and a line segment on the first X-side of the circumscribed rectangle that is aligned with the X-side of the first rectangle; or, the two right-angled sides of the corresponding target right triangle are respectively the line segment on the first Y-side of the circumscribed rectangle that is aligned with the Y-side of the first rectangle and the second X-side of the circumscribed rectangle; the first Y-side and the first X-side are respectively the Y-side and X-side of the circumscribed rectangle that do not overlap with the first rectangle; and the second Y-side and the second X-side are respectively the Y-side and X-side of the circumscribed rectangle that overlap with the first rectangle;
[0177] c.2) When the number of overlapping vertices between a first rectangle and a triangle primitive is two, and one overlapping vertex lies on both the first and second tangents, the other overlapping vertex does not lie on either of the first and second tangents, and the corresponding (Lx / Ly) is less than (Wx / Wy), the first rectangle is a third type first rectangle, and the two right-angled sides of the corresponding target right triangle are the corresponding first Y-direction side and second X-direction side, respectively; or, the two right-angled sides of the corresponding target right triangle are the Y-direction side of the first rectangle that does not overlap with the second tangent, and the X-direction side that overlaps with the first tangent; Lx and Ly are the lengths of the X and Y sides of the first rectangle, respectively, and Wx and Wy are the lengths of the X and Y sides of the circumscribed rectangle, respectively.
[0178] c.3) When the number of overlapping vertices between a first rectangle and a triangle primitive is two, one overlapping vertex lies on both the first and second tangents, the other overlapping vertex does not lie on either the first or second tangents, and the corresponding ratio (Lx / Ly) is greater than (Wx / Wy), the first rectangle is a first rectangle of the third type, and the two right-angled sides of the corresponding target right triangle are the corresponding second Y-direction side and the first X-direction side, respectively; or, the two right-angled sides of the corresponding target right triangle are the Y-direction side of the first rectangle that overlaps with the second tangent and the X-direction side that does not overlap with the first tangent.
[0179] Similarly, based on the vertex coordinates of the first rectangle, the vertex coordinates of the circumscribed rectangle, and the coordinates of the first tangent and the second tangent obtained above, through a simple coordinate comparison, the number of overlapping vertices between each first rectangle and the triangle primitive, as well as the positional relationship between the overlapping vertices and the first tangent and the second tangent can be determined. For the triangle primitive ABC shown in Figure 9, the vertex coordinates of the triangle primitive ABC are A(X1, Y1), B(X2, Y2), and C(X3, Y3), and the vertex coordinates of the circumscribed rectangle AEBG are A(X1, Y1), E(X2, Y1), B(X2, Y2), and G(X1, Y2). The vertex coordinates of the first rectangle BDKH are B(X2, Y2), D(X2, Y3), K(X1, Y3), and H(X1, Y2). The coordinates of the first tangent are Y=Y3, and the coordinates of the second tangent are X=X3. Then, for the first rectangle BDKH, the vertex that coincides with the triangle primitive ABC is vertex B(X2, Y2), and the coincident vertex B(X2, Y2) does not lie on the first tangent (Y=Y3) or the second tangent (X=X3). This satisfies the above situation c.1), and the two right-angled sides of the target right triangle are determined according to the method in the above situation c.1).
[0180] The X-axis length Lx and Y-axis length Ly of the first rectangle, and the X-axis length Wx and Y-axis length Wy of the circumscribed rectangle can all be calculated by simple subtraction based on the vertex coordinates of the first rectangle and the vertex coordinates of the circumscribed rectangle obtained above. Based on the vertex coordinates of the first rectangle and the vertex coordinates of the circumscribed rectangle obtained above, the first Y-axis side, first X-axis side, second Y-axis side, and second X-axis side of the circumscribed rectangle can also be determined. Furthermore, based on the vertex coordinates of the first rectangle and the coordinates of the first and second tangents obtained above, the X-axis side of the first rectangle that coincides or does not coincide with the first tangent, and the Y-axis side that coincides or does not coincide with the second tangent, can also be determined. Similarly, the X-axis side of the circumscribed rectangle that coincides or does not coincide with the first tangent, and the Y-axis side that coincides or does not coincide with the second tangent, can also be determined. The above-mentioned information of corresponding edges and tangents (including coordinates and lengths) can be calculated in advance and then placed in corresponding registers. When needed, they can be read from the corresponding registers.
[0181] For example, case c.1) corresponds to the first rectangle BDKH in Figures 9 and 10, and there are two corresponding target right triangles, namely triangle AEB and triangle BCG. For the target right triangle AEB, as shown in Figure 9, the two right-angled sides of the corresponding target right triangle are the second Y-direction side BE of the circumscribed rectangle (coordinate X=X2, length Wy) and the line segment AE (coordinate Y=Y1, length Lx) on the first X-direction side (coordinate Y=Y1) of the circumscribed rectangle aligned with the X-direction side of the first rectangle. For the target right triangle BCG, as shown in Figure 10, the two right-angled sides of the corresponding target right triangle are the line segment CG (coordinate X=X3, length Ly) on the first Y-direction side (coordinate X=X3) of the circumscribed rectangle aligned with the Y-direction side of the first rectangle and the second X-direction side (coordinate Y=Y2, length Wx) of the circumscribed rectangle. The coordinates and lengths of these two right-angled sides are known. Combined with the coordinates (Xp, Yp) of the pixel point P, through simple subtraction and division operations, we can determine whether (D1 / (L1-D2)) is less than (L2 / L1) based on the distance D1 from the pixel point to the first right-angled side and the distance D2 from the second right-angled side, as well as the length L1 of the first right-angled side and the length L2 of the second right-angled side. It should be noted that for the target right triangle AEB and the target right triangle BCG, as long as the pixel point to be determined satisfies (D1 / (L1-D2)) less than (L2 / L1) for any of the two target right triangles, it means that the pixel point is outside the triangle primitive. If the pixel points to be determined for both target right triangles satisfy (D1 / (L1-D2)) greater than or equal to (L2 / L1), it can be said that the pixel point is inside the triangle primitive.
[0182] Case c.2) corresponds to the first rectangle AFCJ in Figures 11 and 12 . There are two corresponding target right triangles, namely triangle AEB and triangle ACJ. For target right triangle AEB, as shown in Figure 11 , the two right-angled sides of the corresponding target right triangle are the corresponding first Y-direction side BE (coordinate X=X2, length Wy) and the second X-direction side AE (coordinate Y=Y1, length Wx). For target right triangle ACJ, as shown in Figure 12 , the two right-angled sides of the corresponding target right triangle are the Y-direction side AJ (coordinate X=X1, length Ly) of the first rectangle that does not coincide with the second tangent, and the X-direction side (coordinate Y=Y3, length Lx) that coincides with the first tangent.
[0183] Case c.3) corresponds to the first rectangle BDCH in Figures 13 and 14 , and has two corresponding target right triangles, namely triangle AEB and triangle BCH. For target right triangle AEB, as shown in Figure 13 , the two right-angled sides of the corresponding target right triangle are the corresponding second Y-direction side BE (coordinate X=X2, length Wy) and the first X-direction side AE (coordinate Y=Y1, length Wx). For target right triangle BCH, as shown in Figure 14 , the two right-angled sides of the corresponding target right triangle are the Y-direction side CH (coordinate X=X3, length Ly) of the first rectangle coinciding with the second tangent, and the X-direction side BH (coordinate Y=Y2, length Lx) that does not coincide with the first tangent.
[0184] In some embodiments, corresponding to the above situation d):
[0185] d.1) When the number of overlapping vertices between a first rectangle and a triangle primitive is one and the overlapping vertex does not lie on the first or second tangent lines, the first rectangle is a third type first rectangle, and the corresponding two right-angled sides of the target right triangle are the second tangent line and the X-direction side of the first rectangle that does not overlap with the first tangent line; or, the corresponding two right-angled sides of the target right triangle are the Y-direction side of the first rectangle that does not overlap with the second tangent line and the first tangent line;
[0186] d.2) When the number of overlapping vertices between a first rectangle and a triangle primitive is two, one overlapping vertex lies on both the first and second tangent lines, the other overlapping vertex does not lie on either of the first and second tangent lines, and the corresponding (Lx / Ly) is less than (Wx / Wy), the first rectangle is a first rectangle of the third type, and the corresponding right-angled sides of the target right triangle are the second Y-direction side and the first X-direction side of the circumscribed rectangle, respectively; or, the corresponding right-angled sides of the target right triangle are the Y-direction side of the first rectangle that overlaps with the second tangent line and the X-direction side that does not overlap with the first tangent line, respectively.
[0187] d.3) When the number of overlapping vertices between a first rectangle and a triangle primitive is two, one overlapping vertex lies on both the first and second tangent lines, the other overlapping vertex does not lie on either of the first and second tangent lines, and the corresponding (Lx / Ly) is greater than (Wx / Wy), the first rectangle is a first rectangle of the third type, and the two right-angled sides of the corresponding target right triangle are the first Y-direction side and the second X-direction side of the circumscribed rectangle, respectively; or, the two right-angled sides of the corresponding target right triangle are the Y-direction side of the first rectangle that does not overlap with the second tangent line and the X-direction side that overlaps with the first tangent line.
[0188] The first Y-direction side and the first X-direction side are respectively the Y-direction side and the X-direction side of the circumscribed rectangle that do not overlap with the first rectangle; the second Y-direction side and the second X-direction side are respectively the Y-direction side and the X-direction side of the circumscribed rectangle that overlap with the first rectangle.
[0189] Exemplarily, case d.1) corresponds to the first rectangle BDKH in Figures 9 and 10, and there are two corresponding target right triangles, namely triangle ABH and triangle BCD. For the target right triangle ABH, as shown in Figure 9, the two right-angled sides of the corresponding target right triangle are the second tangent AH (coordinate X=X1, length Wy) and the X-direction side BH (coordinate Y=Y2, length Lx) of the first rectangle that does not coincide with the first tangent; for the target right triangle BCD, as shown in Figure 10, the two right-angled sides of the corresponding target right triangle are the Y-direction side BD (coordinate X=X2, length Ly) of the first rectangle that does not coincide with the second tangent and the first tangent CD (coordinate Y=Y3, length Wx). The coordinates and lengths of these two right-angled sides are known. Combined with the coordinates (Xp, Yp) of the pixel point P, through simple subtraction and division operations, we can determine whether (D1' / (L1-D2')) is greater than (L2 / L1) based on the distance D1' and the distance D2' from the pixel point to the first and second right-angled sides of the target right triangle, as well as the lengths L1 and L2 of the first and second right-angled sides. It should be noted that for the target right triangles ABH and BCD, as long as the pixel point to be determined satisfies (D1' / (L1-D2')) greater than (L2 / L1) for either of the two target right triangles, it indicates that the pixel point is outside the triangle primitive. If the pixel point to be determined satisfies (D1' / (L1-D2')) less than or equal to (L2 / L1) for both target right triangles, it indicates that the pixel point is inside the triangle primitive.
[0190] Case d.2) corresponds to the first rectangle AFCJ in Figures 11 and 12 . There are two corresponding target right triangles, namely triangle ABG and triangle ACF. For target right triangle ABG, as shown in Figure 11 , the two right-angled sides of the corresponding target right triangle are the second Y-direction side AG (coordinate X=X1, length Wy) and the first X-direction side (coordinate Y=Y2, length Wx) of the circumscribed rectangle. For target right triangle ACF, as shown in Figure 12 , the two right-angled sides of the corresponding target right triangle are the Y-direction side CF (coordinate X=X3, length Ly) of the first rectangle that coincides with the second tangent, and the X-direction side AF (coordinate Y=Y1, length Lx) that does not coincide with the first tangent.
[0191] Case c.3) corresponds to the first rectangle BDCH in Figures 13 and 14 . There are two corresponding target right triangles, namely triangle ABG and triangle BCD. For target right triangle ABG, as shown in Figure 13 , the two right-angled sides of the corresponding target right triangle are the first Y-direction side AG (coordinate X=X1, length Wy) and the second X-direction side (coordinate Y=Y2, length Wx) of the circumscribed rectangle. For target right triangle BCD, as shown in Figure 14 , the two right-angled sides of the corresponding target right triangle are the Y-direction side of the first rectangle that does not overlap with the second tangent (coordinate X=X2, length Ly) and the X-direction side that overlaps with the first tangent (coordinate Y=Y3, length Lx).
[0192] In some embodiments, when the number of overlapping vertices between a first rectangle and a triangle primitive is one, the overlapping vertex is located on both the first tangent and the second tangent, and the corresponding (Lx / (Wy-Ly)) is less than (Wx / Wy) and ((Wx-Lx) / Ly) is greater than (Wx / Wy), the first rectangle is a first rectangle of the first type; Lx and Ly are the lengths of the X-direction side and the Y-direction side of the first rectangle, respectively, and Wx and Wy are the lengths of the X-direction side and the Y-direction side of the circumscribed rectangle, respectively.
[0193] The above situation corresponds to the first rectangle CHGJ in Figure 3, and the determination principle is: the adjacent first rectangle AFCJ with the same Lx as the first rectangle CHGJ meets the condition in situation c.2): the corresponding (Lx / Ly) is less than (Wx / Wy), and the adjacent first rectangle BDCH with the same Ly as the first rectangle CHGJ meets the condition in situation c.3): the corresponding (Lx / Ly) is greater than (Wx / Wy). Therefore, the size condition corresponding to the first rectangle CHGJ is that (Lx / (Wy-Ly)) is less than (Wx / Wy) and ((Wx-Lx) / Ly) is greater than (Wx / Wy).
[0194] Similarly, the principle for determining the size condition in the above case a.1) (corresponding to the first rectangle DEFC in Figure 3) is that the adjacent first rectangle AFCJ with the same Ly as the first rectangle DEFC satisfies the condition in case c.2): the corresponding (Lx / Ly) is less than (Wx / Wy), and the adjacent first rectangle BDCH with the same Lx as the first rectangle DEFC satisfies the condition in case c.3): the corresponding (Lx / Ly) is greater than (Wx / Wy). Therefore, the size condition corresponding to the first rectangle DEFC is ((Wx-Lx) / Ly) is less than (Wx / Wy) and (Lx / (Wy-Ly)) is greater than (Wx / Wy).
[0195] In some embodiments, in step S120, for each pixel point within the first rectangle, determining whether some or all of the pixels are within the triangle primitive includes the following steps:
[0196] The pixels within the circumscribed rectangle are scanned row by row or column by column. For each scanned pixel, the first rectangle in which it is located is determined, and it is judged whether it is inside the triangle primitive.
[0197] In some embodiments, scanning the pixels within the circumscribed rectangle row by row, determining the first rectangle in which each scanned pixel lies, and determining whether the pixel is within the triangle primitive includes the following steps:
[0198] Scan the pixels within the circumscribed rectangle line by line;
[0199] Scan the current row from one edge of the circumscribed rectangle to the other. For each scanned pixel, determine the first rectangle it is in and whether it is inside the triangle primitive. If so, stop scanning in that direction and the current pixel becomes the first pixel.
[0200] Scan the current row in reverse from the other edge. For each pixel found, determine the first rectangle it is in and whether it is inside the triangle primitive. If so, end scanning the current row and the current pixel becomes the second pixel.
[0201] The first pixel point, the second pixel point, and all pixel points between the first pixel point and the second pixel point in the current row are all inside the triangle primitive.
[0202] As shown in Figure 15, the current row is scanned from the left to the right of the circumscribed rectangle. When a pixel point P1 is found inside the triangle primitive, the scanning in this direction is stopped. Then, the current row is scanned in reverse (from the right to the left of the circumscribed rectangle) starting from the right edge of the circumscribed rectangle. When a pixel point P2 is found inside the triangle primitive, the scanning of the current row is ended. Based on P1 and P2, it can be determined that P1, P2 and all pixels between P1 and P2 are inside the triangle primitive. This saves the hardware resources and power consumption required to judge all pixels between P1 and P2. This is the scenario in step S120 where some pixels in the first rectangle are judged to be inside the triangle primitive.
[0203] Similarly, the pixels within the circumscribed rectangle are scanned column by column. For each scanned pixel, the first rectangle in which it is located is determined, and whether it is inside the triangle primitive is determined, including the following steps:
[0204] Scan the pixels within the circumscribed rectangle column by column;
[0205] Scan the current column from one edge of the circumscribed rectangle to the other. For each target pixel found, determine the first rectangle it is in and whether it is inside the triangle primitive. If so, stop scanning in that direction and the current pixel becomes the first pixel.
[0206] Scan the current column in reverse from the other edge. For each pixel found, determine the first rectangle it is in and whether it is inside the triangle primitive. If so, end scanning the current column and the current pixel becomes the second pixel.
[0207] The first pixel point, the second pixel point, and all pixel points between the first pixel point and the second pixel point in the current column are all inside the triangle primitive.
[0208] Based on the same inventive concept, an embodiment of the present disclosure further provides a graphics processor 200, as shown in FIG16 , including:
[0209] An information acquisition module 210 is configured to determine vertex coordinates of a first rectangle based on vertex coordinates of a triangle primitive to be rasterized and vertex coordinates of a circumscribed rectangle of the triangle primitive, where the circumscribed rectangle is divided into at least one first rectangle by a first tangent and a second tangent, where the first tangent is an X-direction tangent at a first vertex of the triangle primitive, the second tangent is a Y-direction tangent at a second vertex of the triangle primitive, the first vertex is a vertex in the triangle primitive with a center Y coordinate value or a same Y coordinate value, and the second vertex is a vertex in the triangle primitive with a center X coordinate value or a same X coordinate value;
[0210] The determination module 220 is configured to determine whether some or all of the pixels in each first rectangle are inside the triangle primitive using the following methods:
[0211] For a pixel point located within a first rectangle of a first type, determining that the pixel point is outside the triangle primitive, where the first rectangle of the first type refers to a first rectangle that does not overlap with the triangle primitive;
[0212] For pixel points located in the first rectangle that is not of the first type, determine whether the pixel point is inside the triangle primitive based on the distance from the pixel point to the two right-angled sides of the target right triangle and the principle of geometric proportion of similar triangles. The right-angled side of the target right triangle coincides with the side of the corresponding first rectangle, and the hypotenuse of the target right triangle is the target side of the triangle primitive. The target side of the triangle primitive is the side covered by the first rectangle corresponding to the target right triangle.
[0213] The specific implementation process of each module of the above-mentioned graphics processor can be referred to the rasterization method of any of the above-mentioned embodiments, and will not be repeated here.
[0214] Based on the same inventive concept, an embodiment of the present disclosure further provides a graphics processing system, comprising the graphics processor of any of the above embodiments.
[0215] The graphics processing system can be a die (tube core), or a SOC (System on Chip) with multiple dies interconnected, or other organizational forms.
[0216] Based on the same inventive concept, an embodiment of the present disclosure further provides an electronic component, which includes the graphics processing system in any of the above embodiments.
[0217] In some usage scenarios, the electronic component is in the form of a graphics card or a CPU motherboard.
[0218] Based on the same inventive concept, embodiments of the present disclosure further provide an electronic device comprising the aforementioned electronic components. In some usage scenarios, the electronic device is a portable electronic device, such as a smartphone, tablet computer, or VR device; in other usage scenarios, the electronic device is a personal computer, game console, or the like.
[0219] Although the preferred embodiments of the present disclosure have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concepts. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present disclosure.
[0220] Obviously, those skilled in the art may make various changes and modifications to the present disclosure without departing from the spirit and scope of the present disclosure. Thus, if these modifications and variations of the present disclosure fall within the scope of the claims of the present disclosure and their equivalents, the present disclosure is intended to include these modifications and variations.
Claims
1. A rasterization method, comprising: Determining vertex coordinates of a first rectangle according to vertex coordinates of a triangle primitive to be rasterized and vertex coordinates of a circumscribed rectangle of the triangle primitive, where the circumscribed rectangle is divided into at least one of the first rectangles by a first tangent line and a second tangent line, the first tangent line is an X-direction tangent line where a first vertex of the triangle primitive is located, the second tangent line is a Y-direction tangent line where a second vertex of the triangle primitive is located, the first vertex is a vertex in the triangle primitive with a middle or same Y coordinate value, and the second vertex is a vertex in the triangle primitive with a middle or same X coordinate value; For some or all pixel points in each first rectangle, respectively, determining whether they are inside the triangle primitive by the following method: For pixel points located in a first rectangle of a first type, determining that the pixel points are outside the triangle primitive, where the first rectangle of the first type refers to a first rectangle that does not overlap with the triangle primitive; For the pixel points located in a first rectangle that is not of the first type, judging whether the pixel points are inside the triangle primitive according to distances from the pixel points to two right-angled sides of a target right triangle, based on the principle of equal ratio relationship of similar triangles, where the right-angled sides of the target right triangle coincide with sides of the corresponding first rectangle, and the hypotenuse of the target right triangle is a target side of the triangle primitive, and the target side of the triangle primitive is the side covered by the first rectangle corresponding to the target right triangle.
2. The rasterization method according to claim 1, for the pixel points located in a first rectangle that is not of the first type, judging whether the pixel points are inside the triangle primitive according to distances from the pixel points to two right-angled sides of a target right triangle, based on the principle of equal ratio relationship of similar triangles, including: For the pixel points located in a first rectangle of a second type, judging whether (D1 / (L1 - D2)) is greater than (L2 / L1) according to the distance D1 from the pixel points to a first right-angled side of the target right triangle, the distance D2 to a second right-angled side, the side length L1 of the first right-angled side, and the side length L2 of the second right-angled side. If so, determining that the pixel points are outside the triangle primitive; otherwise, determining that the pixel points are inside the triangle primitive. The first rectangle of the second type refers to a first rectangle whose overlapping part with the triangle primitive is a right triangle, and the target right triangle is the overlapping part or a first similar triangle of the overlapping part; the first similar triangle covers the overlapping part.
3. The rasterization method according to claim 1, for the pixel points located in a first rectangle that is not of the first type, judging whether the pixel points are inside the triangle primitive according to distances from the pixel points to two right-angled sides of a target right triangle, based on the principle of equal ratio relationship of similar triangles, including: For the pixel points located within the first rectangle of the second type, based on the distance D1' from the pixel point to the first right-angled side of the target right-angled triangle, the distance D2' to the second right-angled side, the length L1 of the first right-angled side, and the length L2 of the second right-angled side, determine whether (D1' / (L1 - D2')) is less than (L2 / L1). If so, determine that the pixel point is outside the triangular primitive; otherwise, determine that the pixel point is inside the triangular primitive. The first rectangle of the second type refers to the first rectangle whose overlapping part with the triangular primitive is a right-angled triangle, and the target right-angled triangle is the second similar triangle of the overlapping part; the second similar triangle does not cover the overlapping part.
4. For the rasterization method according to claim 1, for the pixel points located within the first rectangle of a non-first type, based on the distances from the pixel points to the two right-angled sides of the target right-angled triangle and the principle of the proportional relationship of similar triangles, determine whether the pixel points are inside the triangular primitive, including: For the pixel points located within the first rectangle of the third type, based on the distance D1 from the pixel point to the first right-angled side of the target right-angled triangle, the distance D2 to the second right-angled side, the length L1 of the first right-angled side, and the length L2 of the second right-angled side, determine whether (D1 / (L1 - D2)) is less than (L2 / L1). If so, determine that the pixel point is outside the triangular primitive. The first rectangle of the third type refers to the first rectangle whose overlapping part with the triangular primitive is a non-right-angled triangle, and the target right-angled triangle is the non-overlapping part of the corresponding first rectangle and the triangular primitive or the first similar triangle of the non-overlapping part; the first similar triangle covers the non-overlapping part and does not cover the overlapping part of the corresponding first rectangle and the triangular primitive.
5. For the rasterization method according to claim 1, for the pixel points located within the first rectangle of a non-first type, based on the distances from the pixel points to the two right-angled sides of the target right-angled triangle and the principle of the proportional relationship of similar triangles, determine whether the pixel points are inside the triangular primitive, including: For the pixel points located within the first rectangle of the third type, based on the distance D1' from the pixel point to the first right-angled side of the target right-angled triangle, the distance D2' to the second right-angled side, the length L1 of the first right-angled side, and the length L2 of the second right-angled side, determine whether (D1' / (L1 - D2')) is greater than (L2 / L1). If so, determine that the pixel point is outside the triangular primitive. The first rectangle of the third type refers to the first rectangle whose overlapping part with the triangular primitive is a non-right-angled triangle, and the target right-angled triangle is the second similar triangle of the non-overlapping part of the corresponding first rectangle and the triangular primitive; the second similar triangle covers the overlapping part of the corresponding first rectangle and the triangular primitive.
6. The rasterization method according to claim 2 further includes: Determine the number of overlapping vertices of each first rectangle and the triangular primitive, and the positional relationship between the overlapping vertices and the first tangent and the second tangent according to the vertex coordinates of the triangular primitive, the vertex coordinates of the circumscribed rectangle, and the vertex coordinates of each first rectangle; Determine the type of each first rectangle according to the number of overlapping vertices of each first rectangle and the triangular primitive, and the positional relationship between the overlapping vertices and the first tangent and the second tangent, and determine the two right-angled sides of the corresponding target right-angled triangle for the pixel points located within the first rectangles that are not of the first type; When the number of overlapping vertices of a first rectangle and the triangular primitive is 1, the overlapping vertex is located on both the first tangent and the second tangent, and the corresponding ((Wx - Lx) / Ly) is less than (Wx / Wy) and (Lx / (Wy - Ly)) is greater than (Wx / Wy), this first rectangle is the first rectangle of the second type. For the pixel points within this first rectangle, the two right-angled sides of the corresponding target right-angled triangle are respectively the first Y-direction side and the first X-direction side of the circumscribed rectangle; the first Y-direction side and the first X-direction side are respectively the Y-direction side and the X-direction side of the circumscribed rectangle that do not overlap with this first rectangle; the Y-direction side and the X-direction side of the circumscribed rectangle that overlap with this first rectangle are respectively the second Y-direction side and the second X-direction side; Lx and Ly are respectively the side lengths of the X-direction side and the Y-direction side of this first rectangle, and Wx and Wy are respectively the side lengths of the X-direction side and the Y-direction side of the circumscribed rectangle; When the number of overlapping vertices of a first rectangle and the triangular primitive is 1 and the overlapping vertex is located on the first tangent but not on the second tangent, this first rectangle is the first rectangle of the second type, and the two right-angled sides of the corresponding target right-angled triangle are respectively the line segment on the corresponding first Y-direction side that is aligned with the Y-direction side of this first rectangle and the first tangent; When the number of overlapping vertices of a first rectangle and the triangular primitive is 1 and the overlapping vertex is located on the second tangent but not on the first tangent, this first rectangle is the first rectangle of the second type, and the two right-angled sides of the corresponding target right-angled triangle are respectively the second tangent and the line segment on the corresponding first X-direction side that is aligned with the X-direction side of this first rectangle; When the number of overlapping vertices of a first rectangle and the triangular primitive is 2 and the two overlapping vertices are both located on the first tangent, this first rectangle is the first rectangle of the second type, and the two right-angled sides of the corresponding target right-angled triangle are respectively the corresponding first Y-direction side and the first tangent; when the number of overlapping vertices of a first rectangle and the triangular primitive is 2 and the two overlapping vertices are both located on the second tangent, this first rectangle is the first rectangle of the second type, and the two right-angled sides of the corresponding target right-angled triangle are respectively the second tangent and the corresponding first X-direction side; When the number of overlapping vertices of a first rectangle and the triangular primitive is 2 and the two overlapping vertices are respectively located on the first tangent line and the second tangent line, or when the number of overlapping vertices of a first rectangle and the triangular primitive is 3, the first rectangle is the first rectangle of the second type, and the two right-angled sides of the corresponding target right-angled triangle are respectively the Y-direction side of the first rectangle that coincides with the second tangent line and the X-direction side that coincides with the first tangent line.
7. The rasterization method according to claim 3, further comprising: Determining the number of overlapping vertices of each first rectangle and the triangular primitive, and the positional relationship between the overlapping vertices and the first tangent line and the second tangent line according to the vertex coordinates of the triangular primitive, the vertex coordinates of the circumscribed rectangle, and the vertex coordinates of each first rectangle; Determining the type of each first rectangle according to the number of overlapping vertices of each first rectangle and the triangular primitive, and the positional relationship between the overlapping vertices and the first tangent line and the second tangent line, and determining the two right-angled sides of the corresponding target right-angled triangle for the pixel points located within the first rectangles that are not of the first type; When the number of overlapping vertices of a first rectangle and the triangular primitive is 1, the overlapping vertex is simultaneously located on the first tangent line and the second tangent line, and the corresponding ((Wx - Lx) / Ly) is less than (Wx / Wy) and (Lx / (Wy - Ly)) is greater than (Wx / Wy), the first rectangle is the first rectangle of the second type, and for the pixel points within this first rectangle, the two right-angled sides of the corresponding target right-angled triangle are respectively the second Y-direction side and the second X-direction side of the circumscribed rectangle; the second Y-direction side and the second X-direction side are respectively the Y-direction side and the X-direction side where the circumscribed rectangle coincides with this first rectangle; the Y-direction side and the X-direction side where the circumscribed rectangle does not coincide with this first rectangle are respectively the first Y-direction side and the first X-direction side; Lx and Ly are respectively the side lengths of the X-direction side and the Y-direction side of this first rectangle, and Wx and Wy are respectively the side lengths of the X-direction side and the Y-direction side of the circumscribed rectangle; When the number of overlapping vertices of a first rectangle and the triangular primitive is 1 and the overlapping vertex is located on the first tangent line but not on the second tangent line, the first rectangle is the first rectangle of the second type, and the two right-angled sides of the corresponding target right-angled triangle are respectively the Y-direction side of the first rectangle that does not coincide with the second tangent line and the second X-direction side; When the number of overlapping vertices of a first rectangle and the triangular primitive is 1 and the overlapping vertex is located on the second tangent line but not on the first tangent line, the first rectangle is the first rectangle of the second type, and the two right-angled sides of the corresponding target right-angled triangle are respectively the second Y-direction side and the X-direction side of the first rectangle that does not coincide with the first tangent line; When the number of overlapping vertices of a first rectangle and the triangular primitive is 2 and the two overlapping vertices are both located on the first tangent line, the first rectangle is the first rectangle of the second type, and the two right-angled sides of the corresponding target right-angled triangle are the corresponding second Y-direction side and the X-direction side of the circumscribed rectangle that does not overlap with the first tangent line; when the number of overlapping vertices of a first rectangle and the triangular primitive is 2 and the two overlapping vertices are both located on the second tangent line, the first rectangle is the first rectangle of the second type, and the two right-angled sides of the corresponding target right-angled triangle are the Y-direction side of the circumscribed rectangle that does not overlap with the second tangent line and the corresponding second X-direction side; When the number of overlapping vertices of a first rectangle and the triangular primitive is 2 and the two overlapping vertices are respectively located on the first tangent line and the second tangent line, or when the number of overlapping vertices of a first rectangle and the triangular primitive is 3, the first rectangle is the first rectangle of the second type, and the two right-angled sides of the corresponding target right-angled triangle are the Y-direction side of the first rectangle that does not overlap with the second tangent line and the X-direction side that does not overlap with the first tangent line.
8. The rasterization method according to claim 4, further comprising: Determining the number of overlapping vertices of each first rectangle and the triangular primitive, and the positional relationship between the overlapping vertices and the first tangent line and the second tangent line according to the vertex coordinates of the triangular primitive, the vertex coordinates of the circumscribed rectangle, and the vertex coordinates of each first rectangle; Determining the type of each first rectangle according to the number of overlapping vertices of each first rectangle and the triangular primitive, and the positional relationship between the overlapping vertices and the first tangent line and the second tangent line, and for the pixel points located within the first rectangles that are not of the first type, determining the two right-angled sides of the corresponding target right-angled triangle; When the number of overlapping vertices of a first rectangle and the triangular primitive is 1 and the overlapping vertex is not located on the first tangent line and the second tangent line, the first rectangle is the first rectangle of the third type, and the two right-angled sides of the corresponding target right-angled triangle are respectively the second Y-direction side of the circumscribed rectangle and the line segment on the first X-direction side of the circumscribed rectangle that is aligned with the X-direction side of the first rectangle; or, the two right-angled sides of the corresponding target right-angled triangle are respectively the line segment on the first Y-direction side of the circumscribed rectangle that is aligned with the Y-direction side of the first rectangle and the second X-direction side of the circumscribed rectangle; the first Y-direction side and the first X-direction side are respectively the Y-direction side and the X-direction side of the circumscribed rectangle that do not overlap with the first rectangle; the second Y-direction side and the second X-direction side are respectively the Y-direction side and the X-direction side of the circumscribed rectangle that overlap with the first rectangle; When the number of coincident vertices of a first rectangle and the triangular primitive is 2, and one coincident vertex is located on both the first tangent and the second tangent, the other coincident vertex is not located on the first tangent and the second tangent, and the corresponding (Lx / Ly) is less than (Wx / Wy), the first rectangle is the first rectangle of the third type, and the two right-angled sides of the corresponding target right-angled triangle are the corresponding first Y-direction side and the second X-direction side respectively; or, the two right-angled sides of the corresponding target right-angled triangle are the Y-direction side of the first rectangle that does not coincide with the second tangent and the X-direction side that coincides with the first tangent respectively; Lx and Ly are the side lengths of the X-direction side and the Y-direction side of the first rectangle respectively, and Wx and Wy are the side lengths of the X-direction side and the Y-direction side of the circumscribed rectangle respectively; When the number of coincident vertices of a first rectangle and the triangular primitive is 2, and one coincident vertex is located on both the first tangent and the second tangent, the other coincident vertex is not located on the first tangent and the second tangent, and the corresponding (Lx / Ly) is greater than (Wx / Wy), the first rectangle is the first rectangle of the third type, and the two right-angled sides of the corresponding target right-angled triangle are the corresponding second Y-direction side and the first X-direction side respectively; or, the two right-angled sides of the corresponding target right-angled triangle are the Y-direction side of the first rectangle that coincides with the second tangent and the X-direction side that does not coincide with the first tangent respectively.
9. The rasterization method according to claim 5, further comprising: Determining the number of coincident vertices of each first rectangle and the triangular primitive, and the positional relationship between the coincident vertices and the first tangent and the second tangent according to the vertex coordinates of the triangular primitive, the vertex coordinates of the circumscribed rectangle, and the vertex coordinates of each first rectangle; Determining the type of each first rectangle according to the number of coincident vertices of each first rectangle and the triangular primitive, and the positional relationship between the coincident vertices and the first tangent and the second tangent, and determining the two right-angled sides of the corresponding target right-angled triangle for the pixel points located within the first rectangles that are not of the first type; When the number of coincident vertices of a first rectangle and the triangular primitive is 1 and the coincident vertex is not located on the first tangent and the second tangent, the first rectangle is the first rectangle of the third type, and the two right-angled sides of the corresponding target right-angled triangle are the second tangent and the X-direction side of the first rectangle that does not coincide with the first tangent respectively; or, the two right-angled sides of the corresponding target right-angled triangle are the Y-direction side of the first rectangle that does not coincide with the second tangent and the first tangent respectively; When the number of overlapping vertices of a first rectangle and the triangle primitive is 2, and one overlapping vertex is located on both the first tangent line and the second tangent line, the other overlapping vertex is not located on the first tangent line and the second tangent line, and the corresponding (Lx / Ly) is less than (Wx / Wy), this first rectangle is the first rectangle of the third type, and the two right-angled sides of the corresponding target right-angled triangle are respectively the second Y-direction side and the first X-direction side of the circumscribed rectangle; or, the two right-angled sides of the corresponding target right-angled triangle are respectively the Y-direction side where this first rectangle coincides with the second tangent line and the X-direction side that does not coincide with the first tangent line; When the number of overlapping vertices of a first rectangle and the triangle primitive is 2, and one overlapping vertex is located on both the first tangent line and the second tangent line, the other overlapping vertex is not located on the first tangent line and the second tangent line, and the corresponding (Lx / Ly) is greater than (Wx / Wy), this first rectangle is the first rectangle of the third type, and the two right-angled sides of the corresponding target right-angled triangle are respectively the first Y-direction side and the second X-direction side of the circumscribed rectangle; or, the two right-angled sides of the corresponding target right-angled triangle are respectively the Y-direction side where this first rectangle does not coincide with the second tangent line and the X-direction side that coincides with the first tangent line; The first Y-direction side and the first X-direction side are respectively the Y-direction side and the X-direction side of the circumscribed rectangle that do not coincide with this first rectangle; the second Y-direction side and the second X-direction side are respectively the Y-direction side and the X-direction side of the circumscribed rectangle that coincide with this first rectangle.
10. The rasterization method according to claim 1, when the number of overlapping vertices of a first rectangle and the triangle primitive is 1, and this overlapping vertex is located on both the first tangent line and the second tangent line, and the corresponding (Lx / (Wy - Ly)) is less than (Wx / Wy) and ((Wx - Lx) / Ly) is greater than (Wx / Wy), this first rectangle is the first rectangle of the first type; Lx and Ly are respectively the side lengths of the X-direction side and the Y-direction side of this first rectangle, and Wx and Wy are respectively the side lengths of the X-direction side and the Y-direction side of the circumscribed rectangle.
11. The rasterization method according to claim 1 further includes: Determine the first rectangle where each pixel point in the circumscribed rectangle is located according to the vertex coordinates of each first rectangle.
12. The rasterization method according to claim 1, for some or all of the pixel points in each first rectangle, determine whether they are inside the triangle primitive, including the following steps: Scan the pixel points in the circumscribed rectangle row by row or column by column. For each scanned pixel point, determine the first rectangle it is in and determine whether it is inside the triangle primitive.
13. The rasterization method according to claim 12, scan the pixel points in the circumscribed rectangle row by row. For each scanned pixel point, determine the first rectangle it is in and determine whether it is inside the triangle primitive, including the following steps: Scan the pixel points in the circumscribed rectangle row by row; Scan in the current row in the direction from one side edge of the circumscribed rectangle to the other side edge. For each pixel point scanned, determine the first rectangle it belongs to and determine whether it is inside the triangle primitive; if so, stop the scan in this direction, and the current pixel point is the first pixel point; Start a reverse scan of the current row from the other side edge. For each pixel point scanned, determine the first rectangle it belongs to and determine whether it is inside the triangle primitive; if so, end the scan of the current row, and the current pixel point is the second pixel point; wherein, the first pixel point, the second pixel point, and all pixel points between the first pixel point and the second pixel point in the current row are all inside the triangle primitive.
14. The rasterization method according to claim 12, for the pixel points in the circumscribed rectangle, perform a column-by-column scan. For each pixel point scanned, determine the first rectangle it belongs to and determine whether it is inside the triangle primitive, including the following steps: Perform a column-by-column scan of the pixel points in the circumscribed rectangle; Scan the current column in the direction from one side edge of the circumscribed rectangle to the other side edge. For each target pixel point scanned, determine the first rectangle it belongs to and determine whether it is inside the triangle primitive; if so, stop the scan in this direction, and the current pixel point is the first pixel point; Start a reverse scan of the current column from the other side edge. For each pixel point scanned, determine the first rectangle it belongs to and determine whether it is inside the triangle primitive; if so, end the scan of the current column, and the current pixel point is the second pixel point; wherein, the first pixel point, the second pixel point, and all pixel points between the first pixel point and the second pixel point in the current column are all inside the triangle primitive.
15. A graphics processor, comprising: An information acquisition module configured to determine the vertex coordinates of the first rectangle according to the vertex coordinates of the triangle primitive to be rasterized and the vertex coordinates of the circumscribed rectangle of the triangle primitive. The circumscribed rectangle is divided into at least one first rectangle by a first tangent line and a second tangent line. The first tangent line is the X-direction tangent line where the first vertex of the triangle primitive is located, the second tangent line is the Y-direction tangent line where the second vertex of the triangle primitive is located. The first vertex is the vertex in the triangle primitive with the middle Y coordinate value or the same Y coordinate value, and the second vertex is the vertex in the triangle primitive with the middle X coordinate value or the same X coordinate value; A judgment module configured to respectively use the following methods to judge whether it is inside the triangle primitive for some or all pixel points in each first rectangle: For the pixel points located in the first rectangle of the first type, determine that the pixel point is outside the triangle primitive. The first rectangle of the first type refers to the first rectangle that does not overlap with the triangle primitive; For the pixel point located within the first rectangle that is not of the first type, based on the distances from the pixel point to the two right-angled sides of the target right-angled triangle and the principle of the proportional relationship of similar triangles, determine whether the pixel point is inside the triangle primitive. The right-angled sides of the target right-angled triangle coincide with the sides of the corresponding first rectangle, and the hypotenuse of the target right-angled triangle is the target side of the triangle primitive. The target side of the triangle primitive is the side covered by the first rectangle corresponding to the target right-angled triangle.
16. A graphics processing system, wherein, Comprising the graphics processor according to claim 15.
17. An electronic component, wherein, Comprising the graphics processing system according to claim 16.
18. An electronic device, wherein, Comprising the electronic component according to claim 17.
Citation Information
Patent Citations
Multi-GPU-oriented high-performance primitive split-screen grating method
CN112581352A
Block-based rasterization method and device, and image rendering method and device
CN115841433A
Method of performing image grating by random using multi primitire object
CN1651253A
Apparatus of and method for drawing graphics, and computer program product
US20050134583A1
Cited By
Method and device for determining processing starting point of target primitive and chip
CN121639775A