Intersection testing in a ray tracing system using convex polygon edge parameters
11593986 · 2023-02-28
Assignee
Inventors
- Peter Smith-Lacey (Hertfordshire, GB)
- Rostam King (Hertfordshire, GB)
- Gregory Clark (Hertfordshire, GB)
- Simon Fenney (Hertfordshire, GB)
Cpc classification
G06T17/20
PHYSICS
International classification
Abstract
A method and an intersection testing module in a ray tracing system for performing intersection testing for a ray with respect to a plurality of convex polygons, each of which is defined by an ordered set of vertices, wherein at least one of the vertices is a shared vertex which is used to define at least two of the convex polygons. The vertices of the convex polygons are projected onto a pair of axes orthogonal to the ray direction. A vertex ordering scheme defines an ordering of the projected vertices which is independent of the ordering of the vertices in the ordered sets. For each of the convex polygons, for each edge of the convex polygon defined by two of the projected vertices, a parameter indicative of which side of the edge the ray passes on is determined, wherein if the ray is determined to intersect a point on the edge then the parameter is determined based upon whether the ordering of the projected vertices defining the edge matches the ordering of the vertices in the ordered set of vertices defining the convex polygon. Whether the ray intersects the convex polygon is determined based on the parameters determined for the edges of the convex polygon.
Claims
1. A method of performing intersection testing, in a ray tracing system, for a ray with respect to a plurality of convex polygons, wherein each of the convex polygons is defined by an ordered set of vertices, and wherein at least one of the vertices is a shared vertex which is used to define two or more of the convex polygons, the method comprising: projecting the vertices of the convex polygons onto a pair of axes orthogonal to the ray direction, wherein the origin of the pair of axes corresponds with the ray origin, and wherein a vertex ordering scheme defines an ordering of the projected vertices which is independent of the ordering of the vertices in the ordered sets of vertices defining the convex polygons; and for each of the convex polygons: for each edge of the convex polygon defined by two of the projected vertices, determining a parameter indicative of which side of the edge the ray passes on, wherein if the ray is determined to intersect a point on the edge then the parameter is determined based upon whether the ordering, defined by the vertex ordering scheme, of the projected vertices defining the edge matches the ordering of the vertices in the ordered set of vertices defining the convex polygon; and determining whether the ray intersects the convex polygon based on the parameters determined for the edges of the convex polygon; wherein for each of two or more of the convex polygons the ray is determined to intersect a point on an edge of that convex polygon.
2. The method of claim 1, wherein said determining a parameter indicative of which side of the edge the ray passes on comprises determining a signed parameter using a function of the positions of the two projected vertices defining the edge; and wherein said determining whether the ray intersects the convex polygon is based on the signs of the signed parameters determined for the edges of the convex polygon.
3. The method of claim 2, wherein said determining whether the ray intersects the convex polygon comprises: determining that the ray intersects the convex polygon if the signed parameters determined for the edges of the convex polygon all have the same sign; and determining that the ray does not intersect the convex polygon if it is not the case that the signed parameters determined for the edges of the convex polygon all have the same sign.
4. The method of claim 2, wherein said determining whether the ray intersects the convex polygon comprises: determining that the signed parameter for any edge of the convex polygon which has zero magnitude has a particular sign; and determining that the signed parameters for edges of the convex polygon which have non-zero magnitude have signs that are consistent with each other.
5. The method of claim 2, wherein the function is a 2D cross product, ƒ(v.sub.i, v.sub.j), of the positions of the two projected vertices, v.sub.i and v.sub.j, defining an edge, which is defined as ƒ(v.sub.i, v.sub.j)=p.sub.iq.sub.j−q.sub.ip.sub.j, where p.sub.i and q.sub.i are components of the projected vertex v.sub.i along the respective axes of the pair of axes, and where p.sub.j and q.sub.j are components of the projected vertex v.sub.j along the respective axes of the pair of axes.
6. The method of claim 5, wherein the ray is determined to intersect a point on an edge if the 2D cross product of the positions of two projected vertices defining the edge has a magnitude of zero.
7. The method of claim 5, wherein the two projected vertices, v.sub.i and v.sub.j, defining an edge are provided to the 2D cross product, ƒ(v.sub.i, v.sub.j), in an order defined by the ordering of the vertices in the ordered set of vertices defining the convex polygon, and wherein the sign of the signed parameter for an edge is determined to be: the same as the sign of ƒ(v.sub.i, v.sub.j) if the ray is not determined to intersect a point on the edge, and the sign of (−1).sup.v.sup.
8. The method of claim 5, wherein the two projected vertices, v.sub.i and v.sub.j, defining an edge are provided to the 2D cross product in an order defined by the vertex ordering scheme, such that the 2D cross product is determined as ƒ(max(v.sub.i, v.sub.j), min(v.sub.i, v.sub.j)), wherein the sign of the signed parameter for an edge is determined to be the same as the sign of (−1).sup.v.sup.
9. The method of claim 1, wherein if the ray is determined to intersect a point on an edge of a convex polygon then the method further comprises performing an XOR operation using: (i) the sign of the signed parameter for the edge and (ii) an indication of the perceived orientation of the convex polygon, wherein the determination of whether the ray intersects the convex polygon is based on the result of the XOR operation.
10. The method of claim 1, wherein the ordering of the vertices according to the vertex ordering scheme is dependent upon the projection used to project the vertices of the convex polygons onto the pair of axes.
11. The method of claim 1, wherein the vertex ordering scheme orders the projected vertices such that: a first projected vertex v.sub.i with components, p.sub.i and q.sub.j, along the respective axes of the pair of axes, is before a second projected vertex v.sub.j with components, p.sub.i and q.sub.i, along the respective axes of the pair of axes, if p.sub.i<p.sub.j or if (p.sub.i=p.sub.j AND q.sub.i<q.sub.j); and a first projected vertex v.sub.i with components, p.sub.i and q.sub.j, along the respective axes of the pair of axes, is after a second projected vertex v.sub.j with components, p.sub.j and q.sub.j, along the respective axes of the pair of axes, if p.sub.ip.sub.j or if (p.sub.i=p.sub.j AND q.sub.i>q.sub.j).
12. The method of claim 1, wherein said determining whether the ray intersects the convex polygon comprises using the parameters determined for the edges of the convex polygon to determine whether the ray passes on the inside of the edges of the convex polygon, wherein it is determined that the ray intersects the convex polygon if it is determined that the ray passes on the inside of all of the edges of the convex polygon, and wherein it is determined that the ray does not intersect the convex polygon if it is determined that the ray passes on the outside of one or more of the edges of the convex polygon.
13. The method of claim 1, wherein the ray and the convex polygon are defined in a 3D space using a space-coordinate system, and wherein said projecting the vertices of the convex polygons onto a pair of axes orthogonal to the ray direction comprises transforming the vertices of the convex polygons into a ray coordinate system, wherein the ray-coordinate system has an origin at the ray origin, and wherein the ray-coordinate system has three basis vectors, wherein a first of the basis vectors is aligned with the ray direction; and wherein a second and a third of the basis vectors are respectively aligned with said pair of axes orthogonal to the ray direction, wherein the second and third basis vectors: (i) are not parallel with each other, and (ii) have a zero as one component when expressed in the space-coordinate system.
14. The method of claim 13, wherein the second and the third of the basis vectors of the ray-coordinate system have a value of ±1 as one component when expressed in the space-coordinate system.
15. The method of claim 13, wherein the ray direction vector is defined with components D.sub.x, D.sub.y and D.sub.z in the space-coordinate system, and wherein the method further comprises selectively permuting and/or reversing the x, y and z components of the ray and the vertices defining the convex polygons, such that D.sub.z≥D.sub.x≥0 and D.sub.z>D.sub.y≥0, before transforming the vertices of the convex polygons into a ray coordinate system.
16. The method of claim 1, wherein the convex polygons are triangles.
17. The method of claim 1, further comprising outputting an indication of a result of the determination of whether the ray intersects the convex polygon wherein the outputted indication is used in the ray tracing system for rendering an image of a 3D scene.
18. The method of claim 1, further comprising, if the ray is determined to intersect the convex polygon, determining an intersection distance and barycentric coordinates for the intersection, wherein the intersection distance and barycentric coordinates are used in the ray tracing system for rendering an image of a 3D scene.
19. An intersection testing module, for use in a ray tracing system, configured to perform intersection testing for a ray with respect to a plurality of convex polygons, wherein each of the convex polygons is defined by an ordered set of vertices, and wherein at least one of the vertices is a shared vertex which is used to define two or more of the convex polygons, the intersection testing module including hardware circuitry being configured to: project the vertices of the convex polygons onto a pair of axes orthogonal to the ray direction, wherein the origin of the pair of axes corresponds with the ray origin, and wherein a vertex ordering scheme defines an ordering of the projected vertices which is independent of the ordering of the vertices in the ordered sets of vertices defining the convex polygons; and for each of the convex polygons: for each edge of the convex polygon defined by two of the projected vertices, determine a parameter indicative of which side of the edge the ray passes on, wherein the intersection testing module is configured to determine the parameter, if the ray is determined to intersect a point on the edge, based upon whether the ordering, defined by the vertex ordering scheme, of the projected vertices defining the edge matches the ordering of the vertices in the ordered set of vertices defining the convex polygon; and determine whether the ray intersects the convex polygon based on the parameters determined for the edges of the convex polygon.
20. A non-transitory computer readable storage medium having stored thereon an integrated circuit definition dataset that, when processed in an integrated circuit manufacturing system, configures the integrated circuit manufacturing system to manufacture an intersection testing module for use in a ray tracing system, the intersection testing module being configured to perform intersection testing for a ray with respect to a plurality of convex polygons, wherein each of the convex polygons is defined by an ordered set of vertices, and wherein at least one of the vertices is a shared vertex which is used to define two or more of the convex polygons, the intersection testing module being configured to: project the vertices of the convex polygons onto a pair of axes orthogonal to the ray direction, wherein the origin of the pair of axes corresponds with the ray origin, and wherein a vertex ordering scheme defines an ordering of the projected vertices which is independent of the ordering of the vertices in the ordered sets of vertices defining the convex polygons; and for each of the convex polygons: for each edge of the convex polygon defined by two of the projected vertices, determine a parameter indicative of which side of the edge the ray passes on, wherein the intersection testing module is configured to determine the parameter, if the ray is determined to intersect a point on the edge, based upon whether the ordering, defined by the vertex ordering scheme, of the projected vertices defining the edge matches the ordering of the vertices in the ordered set of vertices defining the convex polygon; and determine whether the ray intersects the convex polygon based on the parameters determined for the edges of the convex polygon.
Description
BRIEF DESCRIPTION OF THE DRAWINGS
(1) Examples will now be described in detail with reference to the accompanying drawings in which:
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(9)
(10)
(11)
(12)
(13)
(14)
(15)
(16)
(17)
(18)
(19)
(20)
(21)
(22) The accompanying drawings illustrate various examples. The skilled person will appreciate that the illustrated element boundaries (e.g., boxes, groups of boxes, or other shapes) in the drawings represent one example of the boundaries. It may be that in some examples, one element may be designed as multiple elements or that multiple elements may be designed as one element. Common reference numerals are used throughout the figures, where appropriate, to indicate similar features.
DETAILED DESCRIPTION
(23) The following description is presented by way of example to enable a person skilled in the art to make and use the invention. The present invention is not limited to the embodiments described herein and various modifications to the disclosed embodiments will be apparent to those skilled in the art.
(24) Embodiments will now be described by way of example only.
(25) Even when an acceleration structure is used, the amount of work involved in performing intersection testing in a ray tracing system is still very large. For example, ray tracing may be used for rendering an image of a 3D scene, where the image may have of the order of a million pixels. The pixel colour values are derived from some distribution of samples, associated with points in the image plane (typically, there is a one-to-one correspondence between pixel and sample location, but regions of an image may have a higher or lower sample density or may otherwise be independent of the arrangement of pixels). In the context of ray tracing, the samples are themselves associated with a distribution (in the statistical sense) of primary rays parameterised by the neighbourhood of each sample location. In the simplest example, a single primary ray is traced for each sample and used to determine its result. In other examples, multiple rays may be generated in accordance with the distribution (e.g. stochastic sampling) and the result derived from some accumulation or combination of the individual primary rays. When it is determined that a ray intersects with an object in the scene, a shader can be executed which may result in the emission of another ray (i.e. a “secondary ray”) into the scene. Each primary ray may result in the emission of many secondary rays, which are all traced through the scene to determine their intersections. Therefore, it would not be unusual for there to be tens or hundreds of millions of rays traced through a scene for rendering an image. The complexity of scenes to be rendered tends to increase as graphics rendering technology develops, so it would not be unusual for there to be thousands of objects in a scene, each of which may be represented by many primitives (e.g. polygons, such as triangles). Furthermore, the images being rendered may represent frames of a sequence of frames which are to be rendered in real-time, e.g. for a display to a user in real-time. For example, the user may be playing a game wherein the rendered images represent a users view of the 3D scene as the user plays the game. In order for the sequence of frames to appear like a continuous stream of video data, many frames may be rendered per second, e.g. 24, 30 or 60 frames per second to give some examples. It can therefore be appreciated that the work involved in performing intersection testing in a ray tracing system to render scenes to be output in real-time is vast.
(26) One way to overcome this problem, and to perform ray tracing to render scenes to be output in real-time would be to have one or more supercomputers to perform all of the processing. This could be considered to be a ‘brute force’ approach. However, as well as an aim to have high performance (to perform ray tracing to render scenes to be output in real-time), there are also competing aims of reducing the size (e.g. silicon area) and power consumption of the ray tracing system. For example, there may be an aim to implement the ray tracing system on a mobile device, such as a tablet or smartphone, for which the acceptable size and power consumption may be much lower than for a supercomputer. As such, when designing a ray tracing system, there may be a trade-off between performance, power consumption and area. Depending on how this trade-off is implemented, examples described herein may allow the performance to be increased without a significant increase to the power consumption and area (compared to the prior art described above in the background section). Alternatively, in a different implementation of the trade-off, examples described herein may allow the power consumption and/or size of the ray tracing system to be decreased without significantly decreasing the performance of the ray tracing system (compared to the prior art described above in the background section). Different implementations can be designed to target different points in the trade-off between performance, power consumption and silicon area.
(27) As described above, since objects are often represented as sets of convex polygons (non-convex polygons can be described in terms of unions of convex polygons), testing rays for intersection with convex polygons (e.g. triangles) is an extremely frequent operation in a ray tracing system. Therefore, any optimizations that can be made to the way in which the intersection tests are performed can be very useful for optimizing the ray tracing system in terms of reducing the latency, power consumption and size of the ray tracing system.
(28) Furthermore, since such objects typically describe connected surfaces whereby neighbouring polygons have one or more shared vertices or edges, it is important that gaps do not spuriously appear as ray intersections sweep over the object interior, producing noticeable structural defects (which may be referred to as “rendering artefacts” in the rendered image). These may manifest due to rounding error or otherwise approximation in the intersection testing of each polygon whereby implicit perturbation of common vertices and/or edges may render neighbouring polygons disconnected when expressed in terms of their individual intersection results. An implementation that prevents any such disconnection from occurring may be referred to as “watertight”.
(29) While it is possible to mitigate the appearance of gaps by fattening the boundary of each convex polygon to some extent in order to provide some error tolerance, it is also desirable for an implementation to exhibit some form of non-redundant watertight behaviour i.e. for it to minimise the number of reported intersections that occur between a single ray and a single object. It is therefore preferable for an implementation to provide consistent results across individual polygon intersection tests, especially those with common vertices and/or edges, without modification of the polygon boundaries. However, it is usually not feasible to implement fully accurate tests in the general case so we are left with having to ensure that whatever errors are introduced are compatible with the aim of ensuring non-redundant watertightness. If we limit ourselves to cases in which an edge is only considered common if it is bounded by a pair of common vertices (so that “T-junctions” are not present) then it is possible to achieve this by decomposing each intersection test into a projection of the polygon vertices onto a plane (not containing the ray), followed by an accurate intersection test in the plane. This series of operations consolidates all of the error into per-vertex contributions, ensuring that results are consistent across connected triangles since common vertices remain common after transformation (thereby preserving the local topology) and the subsequent intersection tests are exact.
(30) In the context of the above operations, an implementation may then be referred to as “non-redundantly watertight” if and only if a single positive intersection result is reported for any set of (exact) common vertex or edge intersections in the plane. To put this another way, intersection testing of rays with convex polygons is “watertight” if it is ensured that a ray that intersects a point on a shared edge of multiple polygons or a shared vertex of a closed fan is determined to intersect at least one of the polygons which share the edge or vertex. Furthermore, intersection testing of rays with convex polygons is “non-redundantly watertight” if it is ensured that a ray that intersects a point on a shared edge of multiple convex polygons or a shared vertex of a closed fan is determined to intersect a single one of the polygons which share the edge or vertex (i.e. the ray is determined to intersect one and only one of the polygons which share the edge or vertex).
(31) Examples described herein further qualify this watertightness property by stipulating that common edges and vertices belong to polygons with consistent orientation, either with respect to each other (distinguishing outward and inward facing polygons i.e. in accordance with their winding order) or with respect to the perspective of the ray (distinguishing front facing and back facing polygons). In fact, there are several (non-mutually exclusive) scenarios (or any combination thereof) where the properties of “watertight” and/or “non-redundantly watertight” may or may not apply: (i) shared vertices not of a closed fan (e.g., boundary vertices of a mesh); (ii) non-manifold geometry, i.e., edges shared by three or more polygons; (iii) shared edges or shared vertices of a closed fan with polygons specified with inconsistent winding orders (i.e., the endpoints of any shared edge are given in the same order); (iv) shared edges or shared vertices of a closed fan with polygons, specified with consistent winding orders (i.e. the endpoints of any shared edge are given in the opposite order), with more than one orientation (i.e., clockwise and anticlockwise) from the viewpoint of the ray (e.g., silhouette edges or vertices); (v) non-simple geometry, i.e., intersections between polygons not at shared edges or shared vertices (e.g. interior intersections, T-junctions); and (vi) redundant geometry, i.e., intersections of shared edges or shared vertices of a closed fan shared by degenerate polygons. In case (vi), it is desirable for the properties of “watertight” or “non-redundantly watertight” to hold, but only when the degenerate polygons are omitted.
(32) In the examples described herein the vertices of the convex polygons are projected onto a pair of axes orthogonal to the ray direction, wherein the origin of the pair of axes corresponds with the ray origin. In this way, the intersection testing process for testing whether a ray intersects a convex polygon in a 3D scene is reduced to a 2D problem which, as described above, enables us to ensure watertight intersection. The pair of axes are not parallel with each other. The ray is located at the origin of the pair of axes. The direction vector of the ray has a magnitude of zero along both of the axes in the pair of axes. Therefore, the ray is determined to intersect a polygon only if the polygon covers the origin of the pair of axes, where the ray may or may not intersect a polygon at its boundary. Different examples for ensuring watertightness of the intersection testing when the ray intersects a point on an edge of a polygon are described herein.
(33) In examples described herein the pair of axes represent two basis vectors of a ray coordinate system. The particular ray coordinate systems described herein are particularly beneficial for use in performing intersection testing in a ray tracing system, although in other examples the pair of axes might not be part of the particular ray coordinate systems described herein.
(34) For example, in the ray coordinate systems described herein, some of the components of the basis vectors, when expressed in the space-coordinate system, are zero. Furthermore, the ray may be rescaled such that the largest component(s) of the ray direction vector have unit magnitude. The choice of the ray coordinate system and the rescaling of the ray in examples described herein may make two thirds of the tests mathematically cheaper due to scale values being either 1.0 or 0.0. This can be achieved by performing a small amount of pre-calculation that is constant for the ray, so the cost of performing this pre-calculation can be ameliorated because it is performed once for a ray and then can be used in many intersection tests involving that ray. For example, where the ray direction vector D has components D.sub.x, D.sub.y and D.sub.z, values of
(35)
(or values of
(36)
for a ray may be pre-computed and may be stored. As described in more detail below, the axes can be swapped (e.g. permuted) to ensure that D.sub.z is the major component of the ray direction vector, i.e. |D.sub.z|≥|D.sub.x| and |D.sub.z|≥|D.sub.y|. Since any valid ray direction vector has a non-zero magnitude this means that |D.sub.z|>0. As another example, values of
(37)
for values or
(38)
for a ray may be pre-computed and may be stored, with D.sub.x and D.sub.y nonzero, or by using the concept of signed infinity, e.g. as defined in the IEEE floating point format, if D.sub.x or D.sub.y is zero. In some examples, values of zero can be replaced with non-zero values that are small enough to behave like zero in the operations described herein, and/or values of infinity can be replaced with finite values that are large enough to behave like infinity in the operations described herein, and these examples avoid having to treat some zeros and infinities as special cases, and also avoid at least some undefined results which can result from multiplying or dividing by zero or infinity. It is noted that the values of
(39)
(or values of
(40)
have a modulus greater than or equal to 1. As another example, a value of
(41)
for a ray may be precomputed and may be stored. After these values have been pre-computed they can be used for performing intersection testing on the ray. The pre-computed values can be used for multiple intersection tests, which may be performed in parallel. In some examples, the pre-computed values are stored so that they can be read, rather than calculated for use in performing intersection testing on the ray. Furthermore, rescaling the ray so that the largest component(s) of the ray direction vector have unit magnitude and/or the choice of the ray coordinate system so that one or more of the components of the basis vectors are zero makes the processing of the rays simpler to implement. Reducing the number of tests that need to be performed in order to determine whether a ray intersects a convex polygon, and/or simplifying the processing of the rays for determining whether a ray intersects a convex polygon, can reduce the latency, size and/or power consumption of an intersection testing module in a ray tracing system.
(42)
(43) In the examples described herein the ray tracing system uses an acceleration structure in order to reduce the number of intersection tests that need to be performed for a ray against convex polygons. However, it is noted that some other examples might not use an acceleration structure, and may simply tests rays against the convex polygons without first attempting to reduce the number of intersection tests that need to be performed using an acceleration structure.
(44) Generally, when performing intersection testing of a ray with a convex polygon, the ray is defined in terms of components in a space-coordinate system in which the convex polygon is defined. However, in examples described herein, a ray-coordinate system is derived relative to the ray itself, and the convex polygon can be mapped onto the ray coordinate system. The term “space-coordinate system” is used herein to refer to the coordinate system in which the convex polygon is defined. The “space-coordinate system” may be a world space-coordinate system or an instance space-coordinate system. In most of the examples described herein the space-coordinate system is a three-dimensional coordinate system, and a convex polygon is a region of three-dimensional space contained entirely within a plane, bounded by n≥3 line segments, such that all interior angles are less than or equal to 180°. A strictly convex polygon is a convex polygon such that all interior angles are strictly less than 180°.
(45) The term “ray-coordinate system” is used herein to refer to a coordinate system that is specific to a ray, and which has its origin at the origin of the ray. It is noted that in the examples described in detail herein the origin of the ray-coordinate system is the origin of the ray, but in other examples, any point along the ray's line could be used as the origin of the ray-coordinate system, with a suitable adjustment to the minimum and maximum clipping distances for the ray (t.sub.min and t.sub.max). The ray-coordinate system has three basis vectors. A first of the basis vectors is aligned with the ray direction. A second and third of the basis vectors are both orthogonal to the first basis vector, and are not parallel with each other. In examples described herein the second and third basis vectors of the ray-coordinate system are not, in general, orthogonal to each other, although in some examples it is possible that they are orthogonal to each other. Furthermore, in examples described herein, the second and third basis vectors of the ray-coordinate system have a 0 as one component when expressed in the space-coordinate system. In some examples, the second and third of the basis vectors of the ray-coordinate system have a value of ±1 (i.e. a magnitude of 1) for one component when expressed in the space-coordinate system.
(46) In examples described herein, the ray-coordinate system is used by the intersection testing module 108 to perform intersection testing to determine whether a ray intersects a convex polygon, wherein the ray and the convex polygon are defined in a 3D space using a space-coordinate system. A result of performing the intersection testing for the ray is output from the intersection testing module 108 for use by the ray tracing system, e.g. for use in determining which shader program(s) is(are) executed for the ray by the processing logic 110.
(47) The vertices defining the convex polygon are translated for use in performing the intersection testing using the ray-coordinate system by subtracting the ray origin from the positions of the vertices defining the convex polygon. Subtracting the ray origin from the positions of the vertices defining the convex polygon means that the position of the polygon is then defined relative to the origin of the ray. By shifting the vertices by the ray origin first, all relative error in downstream calculations is centred around the ray origin. Assuming that the same is true for the box tester, this makes guaranteeing conservatism (i.e., no false negatives) easier.
(48)
(49) Furthermore, in some examples described herein, the x, y and z components of the ray and the vertices defining the polygons are selectively permuted, such that |D.sub.z|≥|D.sub.x| and |D.sub.z|≥|D.sub.y|, before performing intersection testing (noting that in these examples we must also have |D.sub.z|>0 for valid ray directions). The selective permutation of the axes is performed such that D.sub.z will be the major component of the ray direction.
(50)
(51) The basis vectors of the ray-coordinate system are represented as P, Q and S in
(52)
such that
(53)
(54) As an example (which may be referred to as a “first example” below), the second and third basis vectors, P and Q, may be defined to be
(55)
More generally, and as shown in the example in
(56)
or ±sgn(D.sub.x) or any product of these non-zero scalar values e.g.
(57)
and C could be
(58)
or ±sgn(D.sub.y) or any product of these non-zero scalar values e.g.
(59)
It is noted that, for a non-zero value α, sgn(α)=+1 if α is positive, and sgn(α)=−1 if α is negative. If α=0 then sgn(α) may be +1 or −1 depending on the sign bit of the floating point representation of α. It is noted that standard floating point representations allow both +0 and −0 to be represented separately, and that unsigned 0 is usually identified with +0. In other words, if the adopted number system distinguishes between −0 and +0 (as is the case for the IEEE floating point system) then, as an example, sgn(+0)=+1 and sgn(−0)=−1, otherwise sgn(0)=1. A set of common values for A might be the union of the sets of common values for B and C. It is noted that S is orthogonal to P and to Q, which can be seen in that P.Math.S=Q.Math.S=0. However, depending on the values of D.sub.x and D.sub.y, P and Q are not necessarily orthogonal to each other. For example, unless D.sub.x or D.sub.y is zero then P and Q will not be orthogonal to each other. As described above, P and Q are not parallel to each other, e.g. P and Q are at least far enough from being parallel to each other to not cause issues due to loss in rounding, otherwise the system might degenerate into a 1D scenario. It is noted that D.sub.z cannot be zero because of the selective permutation of the axes such that D.sub.z is the major component of the ray direction and because a valid ray direction vector must have a non-zero magnitude in order to define a line. Therefore, of the possible components of ray basis vector P and Q, the values of
(60)
are always well-defined and have a magnitude in the range from zero to one inclusive, and the values of
(61)
have a magnitude in the range from one to positive infinity (inclusive).
(62) The choice of the scalar values A, B and C can affect the handedness of the system. In
(63) A sign of the mapping from the space-coordinate system to the ray-coordinate system may affect the perceived primitive orientation (given a fixed primitive winding). For example, a negative sign of the mapping may reverse primitive orientation and a positive sign of the mapping may preserve primitive orientation. As an example, the sign of the mapping may be given as:
sgn(D.sub.z)XOR sgn(A)XOR sgn(B)XOR sgn(C)XOR sgn(σ) (1)
wherein sgn(σ) indicates whether the permutation reverses the mapping sign.
(64) The individual terms are XORed together as reversing the system handedness twice results in the original handedness. For example, if A=1/|D.sub.z|, B=sgn(D.sub.z)/D.sub.x, C=sgn(D.sub.z)/D.sub.y, then expression (1) becomes sgn(D.sub.x) XOR sgn(D.sub.y) XOR sgn(D.sub.z) XOR sgn(σ).
(65) The value of sgn(D.sub.z) comes from the sign of the determinant of a change-of-basis matrix (i.e. the three ray-coordinate axes as rows or columns with A=B=C=1 and the major component already permuted to the final row or column), which gives the signed volume of a transformed unit cube, equal to D.sub.z(D.sub.x.sup.2+D.sub.y.sup.2+D.sub.z.sup.2)=D.sub.z∥D∥.sup.2. Being the major component, the magnitude of D.sub.z is at least
(66)
hence the magnitude of the determinant is at least
(67)
After normalising this result by the product of the basis vector magnitudes, this gives a measure of how far the matrix is from singular, i.e. how far the ray-coordinate system is from degenerate, and hence also how far from parallel the orthogonal axes are. It is beneficial for D to be of such magnitude that these expressions do not underflow or overflow, to avoid potential precision issues when transforming vertices into the ray-coordinate system.
(68) In a higher n-dimensional construction, this determinant generalises to D.sub.z.sup.(n-2)∥D∥.sup.2, both demonstrating that the construction works for all n>1 and that Dz only affects sign when n is odd.
(69) The values of sgn(A), sgn(B) and sgn(C) come from rescaling the above ray-coordinate system bases. The value of the sign of the permutation sigma, σ, comes from the way the ray components are reordered (i.e. “permuted” by sigma, σ) to put the major component into a specific position (e.g. the final/z coordinate). By doing so, we leave two choices for which positions the minor coordinates go in. One of these choices corresponds to rotating all the coordinates, the other corresponds to transposing two of the coordinates. For example, to simplify muxing, the permutation involves a transposition when Y is the major component and the permutation involves a rotation otherwise. For example, if X is the major component of the ray direction vector then the permutation of the axes is the rotation (x, y, z)->(y, z, x); if Y is the major component of the ray direction vector then the permutation of the axes is the transposition (x, y, z)->(x, z, y); and if Z is the major component of the ray direction vector then the permutation of the axes is the identity (x, y, z)->(x, y, z). This example provides for simple multiplexing because there are only two inputs for the first two components. Transposing two of the coordinates results in a sign change to the determinant as it is equivalent to swapping two rows in the change-of-basis matrix.
(70) In another example (not shown in the Figures, and which is referred to as a “second example” below), the second and third basis vectors, P and Q, are defined to be
(71)
In this example (not shown in
(72)
Generally, these two examples can be described as the second basis vector, P, being defined to be
(73)
i.e. either
(74)
and the third basis vector, Q, being defined to be
(75)
i.e. eith
(76)
(77) In another example (not shown in the Figures, and which is referred to as a “third example” below),
(78)
For example, the second basis vector, P, may be define to be
(79)
i.e. either
(80)
and the third basis vector, Q, may be defined to be
(81)
i.e. either
(82)
It is noted that
(83)
(84) In another example (not shown in the Figures, and which is referred to as a “fourth example” below), B=±1 and C=±1. For example, the second basis vector, P, may be defined to be P=(±D.sub.z, 0, ∓D.sub.x), i.e. either P=(+D.sub.z, 0, −D.sub.x) or P=(—D.sub.z, 0, +D.sub.x), and the third basis vector, Q, may be defined to be Q=(0, ±D.sub.z, ∓D.sub.y), i.e. either Q=(0, +D.sub.z, −D.sub.y) or Q=(0, −D.sub.z, +D.sub.y).
(85) In another example (not shown in the Figures, and which is referred to as a “fifth example” below),
(86)
For example, the second basis vector, P, may be defined to be
(87)
i.e. either
(88)
and the third basis vector, Q, may be defined to be
(89)
i.e. either
(90)
(91) In other examples (not shown in the Figures, and which are referred to as “sixth examples” below),
(92)
Therefore, the second basis vector, P, may be defined to be
(93)
i.e. either
(94)
and the third basis vector, Q, may be defined to be
(95)
i.e. either
(96)
Since D.sub.z is the major component of the ray direction vector, it is possible that D.sub.x or D.sub.y may be zero. Therefore, in these examples, care needs to be taken when handling the values of
(97)
In one approach, the values of D.sub.x or D.sub.y may be perturbed by some small amount so that they are never exactly zero. For example, values of zero can be replaced with non-zero values that are small enough to behave like zero in the operations described herein.
(98) In other examples (not shown in the Figures, and which are referred to as “seventh examples” below),
(99)
Therefore, the second basis vector, P, may be defined to be
(100)
i.e. either
(101)
and the third basis vector, Q, may be defined to be
(102)
i.e. either
(103)
Since D.sub.z is the major component of the ray direction vector, it is possible that D.sub.x or D.sub.y may be zero. Therefore, in these examples, care needs to be taken when handling the values of
(104)
As described above, in one approach, the values of D.sub.x or D.sub.y may be perturbed by some small amount so that they are never exactly zero. For example, values of zero can be replaced with non-zero values that are small enough to behave like zero in the operations described herein.
(105) The example basis vectors given in the second, third, fourth and fifth examples described above all have consistent handedness, whereas the handedness of the basis vectors given in the sixth and seventh examples described above may either have consistent or opposite handedness, depending on the signs of D.sub.x and D.sub.y.
(106) In another example (not shown in the Figures), B=±sgn(D.sub.z) and C=±sgn(D.sub.z). For example, the second basis vector, P, may be defined to be P=(±|D.sub.z|, 0, ∓sgn(D.sub.z)D.sub.x), i.e. either P=(±|D.sub.z|, 0, −sgn(D.sub.z)D.sub.x) or P=(−|D.sub.z|, 0, +sgn(D.sub.z)D.sub.x), and the third basis vector, Q, may be defined to be Q=(0, ±|D.sub.z|, ∓sgn(D.sub.z)D.sub.y), i.e. either Q=(0, ±|D.sub.z|, −sgn(D.sub.z)D.sub.y) or Q=(0, −|D.sub.z|, +sgn(D.sub.z)D.sub.y).
(107) In another example (not shown in the Figures), B=±sgn(D.sub.x) and C=±sgn(D.sub.y). For example, the second basis vector, P, may be defined to be P=(±sgn(D.sub.x)D.sub.z, 0, ∓|D.sub.x|), i.e. either P=(±sgn(D.sub.x)D.sub.z, 0, −|D.sub.x|) or P=(−sgn(D.sub.x)D.sub.z, 0, +|D.sub.x|), and the third basis vector, Q, may be defined to be Q=(0, ±sgn(D.sub.y)D.sub.z, ∓|D.sub.y|), i.e. either Q=(0, ±sgn(D.sub.y)D.sub.z, −|D.sub.y|) or Q=(0, −sgn(D.sub.y)D.sub.z, +|D.sub.y|).
(108) In all of these examples: (i) S is orthogonal to P and to Q, (ii) P and Q are not parallel with each other, and (iii) P and Q have a zero as one component when expressed in the space-coordinate system. Furthermore, in some of these examples, P and Q have a value of ±1 as one component when expressed in the space-coordinate system. Conditions (i) and (ii) together imply that P, Q and S are always linearly independent. This implies that they are also spanning, and so do form a basis. That they form a nondegenerate basis is also demonstrated by the determinant never being zero for a valid (i.e. nonzero) ray direction.
(109) Some sort of error will be introduced into the projected quantities (e.g. through floating point evaluation) and the choice of basis vectors is relevant to how this will affect the overall error of the intersection calculation. Given a general basis as defined above, the components (p, q, s) of a projected vertex are given by the following matrix multiplications
(110)
where (v.sub.z, v.sub.y, v.sub.z) are the vertex components in world or instance space after the ray origin has been subtracted and perhaps after the axes have been permuted and mirrored such that D.sub.z≥D.sub.x, D.sub.z≥D.sub.y and D.sub.z≥0. The inverse mapping, which expresses these vertex components in terms of their projected counterparts is given by
(111)
where D.sup.2=D.sub.x.sup.2+D.sub.y.sup.2+D.sub.z.sup.2 is the square length of the ray. The above expression is useful because it illustrates how errors in the calculated projected components map to errors in the original vertex locations, thereby giving an impression of the error behaviour in a ray-independent fashion (recall that a multitude of distinct rays may be tested against a given primitive), in the sense that a direct comparison may be made between perturbed vertex locations as implied by one ray projection versus another (assuming a shared ray origin).
(112) Suppose, for example, that we compute p and q as p′ and q′ with relative error ε.sub.p and ε.sub.q (realistic for an accurate floating point implementation) such that
(113)
(114) Note that, since s is not explicitly computed in this example, it may be described, as above, with zero effective error. Now, using the earlier expression for the inverse mapping, we may express this error in terms oƒ(v′.sub.x, v′.sub.y, v′.sub.z), the implied offset vertex, with
(115)
(116) If we substitute our original projection expression for (p, q, s), this simplifies to
(117)
(118) The first important thing to observe (in this example in which the projected coordinates are computed with relative error) is that the implied vertex error does not depend on the choice of values for A, B or C (assuming values of zero are correctly handled, as described elsewhere). This allows us to decide these quantities on their relative merits, without having to consider their impact on the error analysis.
(119) Next, we can understand bounds on the error by writing the total square relative error ε.sup.2 as
(120)
where v.sup.2=v.sub.x.sup.2+v.sub.y.sup.2+v.sub.z.sup.2 is the square length of the vertex relative to the ray origin, for a vertex not at the ray origin. Now we can see why it is important that D.sub.z is the major axis; the above equation involves D.sub.x/D.sub.z and D.sub.y/D.sub.z terms that may become unbounded for finite ε.sub.x and ε.sub.y, the errors on the computed projected components, as D.sub.z tends to zero.
(121) Take for example the case where v.sub.z≠0, ε.sub.p≠0, ε.sub.q=0, D.sub.x=D.sub.y and D.sub.z/D.sub.x.fwdarw.0. We have
(122)
where in the first line we have used the substitution ε.sub.y=0, in the second line we have used D.sub.x=D.sub.y and in the third line we have used D.sub.z/D.sub.x.fwdarw.0 and the fact that v.sub.z≠0. So we see that information about the vertex component v.sub.x (and v.sub.y) gets washed out in the projection as D.sub.z/D.sub.x.fwdarw.0 as should be intuitively clear with reference to the matrix expression for (p, q, s). Of course, if D.sub.z is the major axis, the magnitude of D.sub.z/D.sub.x (and D.sub.z/D.sub.y) is bounded below by one so that the above pathology doesn't arise (and it is easy to construct an upper bound on the total error in terms of the error bounds on the projected components).
(123) A “reciprocal basis” is one where in the basis vectors, P=B(D.sub.z, 0, −D.sub.x) and Q=C(0, D.sub.z, −D.sub.y), B is a function of
(124)
and C is a function of
(125)
In other words, B is a simplified fraction with D.sub.x in its denominator, and C is a simplified fraction with D.sub.y in its denominator. For example, a reciprocal basis may have
(126)
such that
(127)
another example, a reciprocal basis may have
(128)
such that
(129)
One advantage of using a reciprocal basis is that each reciprocal may be evaluated to some accuracy (usually less accurate than comparable floating point operations) and then those evaluated values may be treated as if they were exact, in essence perturbing the direction of the ray direction for the sake of improving the accuracy of all intersection testers (improving consistency across the board). Another advantage of using a reciprocal basis is that it provides more flexibility in how the intersection distance, if required, is calculated. In particular, if a point of intersection (relative to the ray basis coordinate system) (p.sub.x, p.sub.y, p.sub.z) is determined, for example via barycentric interpolation, then the intersection parameter t may be alternatively computed as
(130)
This may provide superior error characteristics if, for example, the component is selected corresponding to the axis for which a given convex polygon's components have the smallest range. This is in contrast with a non-reciprocal basis for which it is less cost effective to perform a calculation involving the reciprocals
(131)
without additional per ray storage. Pre-computing these additional terms would also potentially sacrifice some of the consistency in the definition of the ray since the computed reciprocals could not in general be treated as exact. Since the reciprocal basis projection operation also involves products of vertex components of the form
(132)
these intermediate products may be retained so that the intersection parameter t is obtained directly from barycentric interpolation without the need for any further scaling (described in more detail later in the document).
(133) Table 1 below shows eight examples (denoted A to H) of different ray formats and basis vectors (up to sign) which may be used in different examples. The phrase “up to sign” here means that P and Q can be scaled by any unit value, i.e. restricted to the set {−1. +1}. Table 1 also shows the number of multiply and reciprocal operations that would be performed per ray for the different ray formats, the number of multiply operations that would be performed per vertex for the projection into 2D ray space with its corresponding basis, and the reciprocal and multiply operations that would be performed per primitive for the intersection distance calculation.
(134) TABLE-US-00001 TABLE 1 Example ray formats and basis vectors Implicit Ray Ray Muls Distance Distance Ray Basis Muls Recips (per Recips Muls (per # Format vectors (per Ray) (per Ray) Vertex) (per Prim.) Prim.) A (D.sub.x, D.sub.y, D.sub.z) P = (D.sub.z, 0, −D.sub.x) 0 0 4 1 1 B
(135) The different options for the ray formats and basis vectors can be compared with each other based on the total cost of all the floating point operations (FLOPs) from both the ray format encoding, the basis projection and the distance calculation. When the pre-processing of a ray into a given format (e.g. one of the options shown as A to H in Table 1) is decoupled from the polygon intersection testing and performed once per ray, and given that a single ray is tested against multiple vertices, then offloading FLOP costs from the basis projection onto the ray format encoding to minimise the former tends to be beneficial. When a single ray is tested against multiple primitives, then offloading FLOP costs from the distance calculation onto the ray format encoding to minimise the former is also beneficial.
(136) Options B, D, F and H are generally all improvements over A, C, E and G respectively, as they shift the reciprocal from the (per primitive) distance calculation to the (per ray) ray format encoding.
(137) Option B (and option A) is the default ray format/basis which is the most intuitive way to perform the intersection testing but is not the most efficient in terms of the number of floating point operations that need to be performed. Option F (and option E) reduces the number of multiply operations that are performed per vertex in the basis projection by two relative to option B (and option A).
(138) Options C, D, G and H use reciprocal bases. Option D (and option C) reduces the number of multiply operations that are performed per vertex in the basis projection by one, and reduces the number of multiply operations that are performed per primitive in the distance calculation by one, relative to option B (and option A).
(139) Option H (and option G) reduces the number of multiply operations that are performed per vertex in the basis projection by two relative to option B (and option A).
(140) Using the ray-coordinate system with basis vectors as described in the examples above can simplify some of the processing involved in intersection testing. In particular, if a basis vector has a 0 as a component value then a multiply and/or add operation (e.g. as used for performing a dot product or a cross product) involving that basis vector will not include a multiply and/or an add operation for the component which is 0, thereby reducing the number and/or complexity of operations that need to be performed. Similarly, if a basis vector has ±1 as a component value then a multiply and/or add operation (e.g. as used for performing a dot product or a cross product) involving that basis vector will not include a multiply operation for the component which is ±1, thereby reducing the number and/or complexity of operations that need to be performed. Reducing the number of operations that are performed will tend to reduce the latency and power consumption of the intersection testing module 108 and, additionally, reducing the complexity of operations that are performed will tend to increase the accuracy. Furthermore, when the intersection testing module 108 is implemented in fixed function circuitry then reducing the number and/or complexity of operations that are performed will tend to reduce the size (i.e. the silicon area) of the intersection testing module 108. For example, the fixed function circuitry may comprise one or more multiply-and-add components (e.g. a fused singly rounded multiply-add unit) for performing multiplications and additions using the second and third basis vectors of the ray-coordinate system. In a singly rounded floating point implementation (i.e. rounding is applied to the exact final result to ensure a representable value is output), this is more accurate and typically smaller in area than a sum of products, multiply rounded (both products and sum). Its area may even be comparable to a less accurate multiply rounded implementation, which is less likely to be the case for more complex operations. Floating point add and multiply operations (unlike the real numbers they approximate) are not associative. Reducing the operations, which reduces the possible orderings, thus may have other benefits in terms of consistency of results.
(141) In the main examples described herein the ray data for the rays has n=3 coefficients. However, in other examples, the ray data could have more than three coefficients. The construction of the ray coordinate system described can be applied to any dimension n≥2. For example, n basis vectors of the ray coordinate system can be defined where a first of the basis vectors of the ray coordinate system is aligned with the ray direction, and there are (n−1) other basis vectors which are orthogonal to the first basis vector. If n>2 then no pairing of the (n−1) other basis vectors are parallel. Furthermore, the (n−1) other basis vectors have zeros for (n−2) components when expressed in the space-coordinate system. The n basis vectors of the ray coordinate system form a basis of n-dimensional space (they are linearly independent and hence spanning). For example, in a four dimensional space, the ray direction vector may be D=(D.sub.w, D.sub.x, D.sub.y, D.sub.z), and the four basis vectors of the ray coordinate system may be: S=A(D.sub.w, D.sub.x, D.sub.y, D.sub.z), P=B(D.sub.z, 0, 0, −D.sub.W) and Q=C(0, D.sub.z, 0, −D.sub.x), R=D(0, 0, D.sub.z, −D.sub.y), where in this example, the selective permutation of the axes ensures that D.sub.z is the major component of the ray direction vector, i.e. |D.sub.z|≥|D.sub.w|, |D.sub.z≥|D.sub.x| and |D.sub.z|≥|D.sub.y|. In this example, A, B, C and D are nonzero scalars, and they may be chosen to make one of the coefficients unital, e.g. as described above in relation to the three dimensional examples. In this example, the four dimensions may correspond to three spatial dimensions and one temporal dimension. In the 4D case, an expression for the sign of the determinant (similar to expression (1) given above for the 3D case) may be given as:
sgn(A)XOR sgn(B)XOR sgn(C)XOR sgn(D)XOR sgn(σ) (2)
(142) As an example, the permutation sigma may reverse the mapping sign if the major component of the ray direction vector is the W or the Y axis, but not if the major component of the ray direction vector is the X or the Z axis. In particular, in this example, permuting the components so that the major component is in the final position may involve a four cycle for a major axis of W and a transposition for a major axis of Y, in both cases flipping the sign. The sign of D.sub.z does not factor in expression (2) because n is even (i.e. n=4).
(143) Returning to the 3D case, in some examples, the ray and the convex polygon are transformed from the space-coordinate system into the ray-coordinate system, wherein the intersection testing is performed in the ray-coordinate system. Testing in the ray-coordinate system could be performed by determining if the ray intersects with the convex polygon defined by its vertices as defined in the ray-coordinate system. However, in some other examples, a full transformation of the ray and the convex polygon into the ray-coordinate system does not need to be performed. In these other examples, the polygons can be projected onto a pair of axes corresponding to the second and third basis vectors of the ray coordinate system, but components of the polygons along the ray direction (i.e. in the direction of the first basis vector of the ray coordinate system) might not be determined. It is noted that defining the ray in the ray-coordinate system is trivial because its origin is at the origin of the ray-coordinate system and its direction is parallel to the S axis, such that its component values along the P and Q axes of the ray-coordinate system are zero.
(144) In the examples described above, the axes are selectively permuted to ensure that D.sub.z is the major component of the ray direction vector. Furthermore, the axes may be selectively reversed (or “reflected”) to ensure that all of the components of the ray direction vector are non-negative, i.e. D.sub.z>0, D.sub.x≥0 and D.sub.y≥0. The selective reversing of the axes causes the ray direction vector to point into the octant of the space-coordinate system which has positive values for x, y and z. Since D.sub.z is the major component of the ray direction vector this means that
(145)
are in a range from 0 to 1 and it means that
(146)
are in an interval from 1 to positive infinity. After the selective permutation and selective reversing of the axes, D.sub.z≥D.sub.x≥0 and D.sub.z≥D.sub.y≥0.
(147) Returning to the sign of the change of basis, forcing the signs of D.sub.x, D.sub.y and D.sub.z to be nonnegative means that any appearance of them in the determinant, sgn(A), sgn(B) or sgn(C) is forced to 1, simplifying the post sign modification. However, as the vector coordinates must be reversed/reflected to match the reversal/reflection of the ray coordinates, the sign must be post-modified by sgn(Dx), sgn(Dy) and sgn(Dz). So for the particular choices of A, B and C given in the example above, this results in the same sign modification expression.
(148) A mapping indication of the sign of the change-of-basis mapping can be stored, wherein the mapping indication indicates whether the mapping from the space-coordinate system to the ray-coordinate system affects the perceived polygon orientation. The mapping indication can be used during intersection testing of the ray with a polygon to ensure the correct orientation (perceived by the ray in the original space-coordinate system) is output.
(149)
(150) In step S302 data defining the ray 202 and data for the vertices defining the convex polygons 204 and 206 are obtained at the intersection testing module 108. In particular, data defining the components of the ray origin and the ray direction in the space-coordinate system are obtained. The data defining the ray origin may be the three components of the ray origin position in the space-coordinate system, O.sub.x, O.sub.y and O.sub.z. In the example shown in
(151)
In other examples, different pre-computed values may be read to define the ray direction, e.g. values of
(152)
and D.sub.z may be read. As another example, values of
(153)
may be read. As another example, values of
(154)
may be read. In other examples, other values may be pre-computed and read which can be used to define the ray direction. The roles of these three values are distinct, and they are not always all needed. A first and key purpose of a triangle tester is an intersection determination. This uses the first two values, e.g. either
(155)
or similar, possibly with some signs depending on the choice of B and C. These are used to generate P and Q against which the primitive vertices are projected. The barycentric coordinates of an intersection point can be derived from the intersection determination without additional input. A second purpose of a triangle tester is an orientation determination (e.g. for back-face culling). This additionally uses the sign of the third value
(156)
to ensure correct results, as per the determinant form. A third and final purpose of a triangle tester is an intersection distance calculation. This additionally uses the magnitude of the third value, i.e. either
(157)
or |D.sub.z|, to rescaie me aistance value correctly. If the third purpose is not needed (e.g. when the ray has infinite range or t.sub.min and t.sub.max have been pre-scaled accordingly), then
(158)
or |D.sub.z| may not be required as input. If the second purpose is not needed (e.g. when no distinction is made between hitting either side of the primitive), then sgn(D.sub.z) may not be required. Alternatively, an intersection distance calculation may use any of
(159)
in conjunction with the corresponding component of the intersection point to determine the intersection distance.
(160) In the example described with reference to
(161) In step S304 the x, y and z components of the data defining the ray and the vertices defining the convex polygons are selectively permuted and/or reversed by the intersection testing module 108 (e.g. by the ray rescaling unit 116), such that D.sub.z≥D.sub.x≥0 and D.sub.z≥D.sub.y≥0. The permutation of the axes may be thought of as rearranging the axes. In particular, a permutation of the axes comprises either a rotation of three axes, a transposition of two axes or the identity (i.e. not changing the axes). It is noted that a permutation involving a transposition of two axes will alter the handedness of the coordinate system, whereas a permutation that does not involve a transposition of two axes will not alter the handedness of the coordinate system. The permutation of the axes is performed so that the major component of the ray direction is D.sub.z (i.e. ensuring that |D.sub.z|≥|D.sub.x| and |D.sub.z|≥|D.sub.y|). For example, if the original z component of the ray direction vector has a larger magnitude than the original x and y components of the ray direction vector then no permutation is used (which may be thought of as the permutation using the identity operation); if the original x component of the ray direction vector has a larger magnitude than the original y and z components of the ray direction vector then the permutation may comprise a rotation of the three axes such that the x components become the z components, the z components become the y components, and the y components become the x components; and if the original y component of the ray direction vector has a larger magnitude than the original x and z components of the ray direction vector then the permutation comprises a transposition of the y and z axes such that the y components become the z components, and the z components become the y components (and the x components stay as the x components). It would be possible to just perform the selective permutation in step S304 (i.e. not perform the selective reversing), but in the method described with reference to
(162) In step S306, the intersection testing module 108 projects the vertices of the convex polygons onto a pair of axes orthogonal to the ray direction, wherein the origin of the pair of axes corresponds with the ray origin. This projection of the vertices of the convex polygons onto a pair of axes orthogonal to the ray direction may comprise transforming the vertices of the convex polygons into the ray coordinate system described above. As described above, the ray-coordinate system has an origin at the ray origin, so step S306 may involve subtracting the respective components of the ray origin (O.sub.x, O.sub.y and O.sub.z) from respective components of the data defining the positions of the vertices defining the polygons, to thereby determine components of the positions of the vertices defining the polygons relative to the ray origin. As described above, the ray-coordinate system has three basis vectors, wherein a first of the basis vectors is aligned with the ray direction; and wherein a second and a third of the basis vectors are respectively aligned with said pair of axes orthogonal to the ray direction, wherein the second and third basis vectors: (i) are not parallel with each other, and (ii) have a 0 as one component when expressed in the space-coordinate system. As mentioned above, in some examples, the second and third basis vectors may have ±1 as one component when expressed in the space-coordinate system.
(163) The projection can take the form of a dot product. The projection of a 3D vertex v=(v.sub.x, v.sub.y, v.sub.x) to a 2D ray-space coordinate (p, q), with 3D basis vectors P=(P.sub.x, P.sub.y, P.sub.z) and Q=(Q.sub.x, Q.sub.y, Q.sub.z) is as follows:
v.fwdarw.p=P.Math.v=P.sub.xv.sub.x+P.sub.yv.sub.y+P.sub.zv.sub.z
v.fwdarw.q=Q.Math.v=Q.sub.xv.sub.x+Q.sub.yv.sub.yQ.sub.zv.sub.z
(164) With the examples of the basis described herein, P.sub.y=0 and Q.sub.x=0, such that:
p=P.sub.xv.sub.x+P.sub.zv.sub.z
q=Q.sub.yv.sub.y+Q.sub.zv.sub.z
(165) This may be implemented by separate multiplications and an addition, or alternatively as a (singly rounded) fused DP2 (2D dot product), which in this latter case would ensure that the computed components have finite relative error with the properties discussed earlier.
(166) Furthermore, with some of the examples of the basis described herein P.sub.x or P.sub.z may be equal to ±1 and Q.sub.y or Q.sub.z may be equal to ±1, respectively, such that either:
p=±v.sub.x+P.sub.zv.sub.z
q=±v.sub.y+Q.sub.zv.sub.z
Or:
p=P.sub.xv.sub.x±v.sub.z
q=Q.sub.yv.sub.y±v.sub.z
(167) Either of these may be implemented by a separate multiplication and addition, or alternatively as a (singly rounded) FMA (fused multiply add), which in this latter case would ensure that the computed components have finite relative error with the properties discussed earlier.
(168) As mentioned above, a mapping indication is stored to indicate whether mapping from the space-coordinate system to the ray-coordinate system (i.e. steps S304 and S306) has altered the perceived orientation of the polygons. If the perceived orientation of the polygons has changed then this is taken into account in the intersection process, e.g. in step S318, in order to ensure that the mapping from the space-coordinate system to the ray-coordinate system in steps S304 and S306 does not prevent the intersection testing module from correctly determining whether a ray intersects a polygon.
(169)
(170) In step S308 a parameter, k, is set to zero. The parameter, k, is used to indicate a particular convex polygon.
(171) In step S310 a parameter, e, is set to zero. The parameter, e, is used to indicate a particular edge of a convex polygon. It is noted that the polygon's winding order (i.e., the order of its vertices) specifies a direction for each of its edges, such that every edge given below is implicitly a directed edge. In the example in which the polygons are triangles then the maximum value (e.sub.max) for the parameter, e, is 2. In other words the parameter, e, can take values of 0, 1 or 2 to indicate the three edges of a triangle. In the example in which the polygons have n edges then the maximum value (e.sub.max) for the parameter, e, is n−1. Each edge of a convex polygon is defined by two of the projected vertices as an ordered pair, indicating the direction of the edge. For example polygon 204 shown in
(172) In step S312 the polygon testing unit(s) 114 of the intersection testing module 108 determines a parameter, w, indicative of which side of the e.sup.th edge of the k.sup.th polygon the ray passes on. For example, w may be a signed parameter which is determined using a function (which is referred to herein as a “2D cross product”), ƒ(v.sub.i, v.sub.j), of the positions of the two projected vertices defining the e.sup.th edge of the k.sup.th polygon. The 2D cross product, ƒ(v.sub.i, v.sub.j), of the positions of two projected vertices, v.sub.i and v.sub.j, defining an edge, is defined as ƒ(v.sub.i, v.sub.j)=p.sub.iq.sub.j−q.sub.ip.sub.j, where p.sub.i and q.sub.i are components of the projected vertex v.sub.i along the respective axes of the pair of axes, and where p.sub.j and q.sub.j are components of the projected vertex v.sub.j along the respective axes of the pair of axes. In other examples, other functions of the positions of the two projected vertices defining the edge may be used to determine the parameter w. For example, the function may return the result of a comparison of p.sub.iq.sub.j and q.sub.ip.sub.j, which would avoid performing a subtraction operation, but would not provide a magnitude for use in determining barycentric coordinates. The sign of w for the e.sup.th edge of the k.sup.th polygon indicates whether the ray passes on the left or the right of that edge, from the edge's perspective (directed from v.sub.i to v.sub.j). Passing on the “left” side of the edge corresponds to an anticlockwise rotation from the first endpoint to the second endpoint relative to the origin. Passing on the “right” side of the edge corresponds to a clockwise rotation from the first endpoint to the second endpoint relative to the origin. With the form of the “2D cross product” given above as ƒ=(v.sub.i, v.sub.j)=p.sub.iq.sub.j−q.sub.ip.sub.j, and with a first axis pointing rightwards and a second axis pointing upwards, left/anticlockwise corresponds to a positive result of ƒ and right/clockwise corresponds to a negative result of ƒ. In the IEEE floating point specification, a negative value has a sign bit of 1, whereas a positive value has a sign bit of 0. Assuming a left-handed system (as per
(173) The parameter w is determined using the 2D cross product in different ways in different implementations. Two examples are described in detail below with reference to
(174) The function ƒ(v.sub.i, v.sub.j)=p.sub.iq.sub.j−q.sub.ip.sub.j, referred to herein as a “2D cross product”, is a 2D analogy to the 3D triple product: it calculates the signed area of a parallelogram defined by a first edge between the origin and (p.sub.0, q.sub.0) and a second edge between the origin and (p.sub.1, q.sub.1). This is equivalent to generating the determinant of the matrix with rows (p.sub.i, q.sub.j) for i=0, 1. It is also equivalent to considering the endpoints as complex numbers, taking the complex conjugate of the first endpoint, multiplying this with the second endpoint and looking at the imaginary component. Considering all cases geometrically, the sine of the angle between the two endpoints and the origin (i.e. intersection point) is found, scaled by the distances of the two endpoints from the origin. Sine is an odd function, so we have a signed function, i.e. we get a positive result if we rotate anticlockwise from the first endpoint to the second endpoint, and a negative result if we rotate clockwise from the first endpoint to the second endpoint (with standard axes).
(175) After parameter w is determined using the 2D cross product for the e.sup.th edge of the k.sup.th polygon in step S312, then in step S314 the polygon testing unit(s) 114 of the intersection testing module 108 determines whether e=e.sub.max. In other words, it determines whether the w parameter has been determined for all of the edges of the k.sup.th polygon. If not, then the method passes to step S316 in which the parameter, e, is incremented, and then the method passes back to step S312 so that the parameter w can be determined for the next edge of the k.sup.th polygon. If it is determined in step S314 that the w parameter has been determined for all of the edges of the k.sup.th polygon (i.e. if e=e.sub.max) then the method passes to step S318.
(176) In step S318 the polygon intersection testing unit(s) 114 of the intersection testing module 108 determines whether the ray intersects the k.sup.th polygon based on the w parameters determined for the edges of that polygon. For example, the determination as to whether the ray intersects the k.sup.th polygon may be based on the signs of the w parameters determined for the edges of the k.sup.th polygon. In an example, if the w parameters determined for the edges of the k.sup.th polygon all have the same sign then it is determined that the ray intersects the k.sup.th polygon; whereas if it is not the case that the w parameters determined for the edges of the k.sup.th polygon all have the same sign then it is determined that the ray does not intersect the convex polygon. In this way, step S318 comprises using the parameters determined for the edges of the convex polygon to determine whether the ray passes on the inside of the edges of the convex polygon, wherein it is determined that the ray intersects the convex polygon if it is determined that the ray passes on the inside of all of the edges of the convex polygon, and wherein it is determined that the ray does not intersect the convex polygon if it is determined that the ray passes on the outside of one or more of the edges of the convex polygon.
(177) In some examples, as soon as an edge test indicates that the ray passes on the outside of an edge of a polygon, then a determination can be made that the ray does not intersect the polygon, without necessarily performing the edge tests for all of the edges of the polygon. For example, step S314 could be modified to also identify, after we have processed at least 2 edges, if we have one or more determined w parameters that are strictly positive and one or more w parameters that are strictly negative for edges of a polygon, and in that case the polygon may be marked as a “miss” without determining w parameters for any remaining edges of the polygon.
(178) Furthermore, for an intersection to be determined, as well as all n signs of w matching, the signs of w might need to match some predetermined value (e.g., when back-face culling), and if they do not match the predetermined value then the polygon can be discarded. For example, if culling is enabled for clockwise/anticlockwise primitives or front/back-facing primitives (e.g., back-face culling), then as soon as a single edge test result is determined then it might be possible to discard the primitive. For example, if anticlockwise primitives are being culled then any primitive with an intersection point on the left of an edge can be discarded, likewise if clockwise primitives are being culled then any primitive with an intersection point on the right of an edge can be discarded. Furthermore, many edges may be shared (perhaps with reversed directions) within a single batch of convex polygons, and in this situation each unique edge may be tested once and the results for a shared edge can be duplicated (perhaps with reversed sign) across both polygons sharing the edge.
(179) In some examples, the presence of one or more w parameters with zero magnitude may be treated as a special case. For example, if the w parameters for all of the edges of the polygon have non-zero magnitude, it may be determined that the ray intersects the k.sup.th polygon only if all edges have matching signs for their w parameters (similar to as described above), but if, one or more w parameters have zero magnitude then an intersection is determined only if all of the zero magnitude w parameters (for edges of nonzero projected length) have a particular sign (e.g. a positive sign, or in other examples, a negative sign) and if all remaining edges with nonzero w parameters have mutually consistent sign. In these examples, the signs of the one or more w parameters which have zero magnitude do not necessarily have to match the signs of the one or more w parameters which have non-zero magnitude to determine that the ray intersects the polygon. In this way, the determination of whether the ray intersects the convex polygon (in step S318) comprises: (i) determining that the signed parameter, w, for any edge of the convex polygon which has zero magnitude has a particular sign (e.g. positive in some examples, and negative in other examples), and (ii) determining that the signed parameters, w, for edges of the convex polygon which have non-zero magnitude have signs that are consistent with each other (albeit not necessarily consistent with the signs of the w parameters which have zero magnitude). Furthermore, in some examples, it may be determined that the ray does not intersect the k.sup.th polygon if all edges generate w parameters with zero magnitude, indicating degeneracy. In other words, in order to omit degenerate polygons, if the 2D cross products for all of the edges of the convex polygon have a magnitude of zero then it can be determined that the ray does not intersect the convex polygon. If culling is enabled, primitives may be discarded based on the sign of the edges with nonzero w parameters, as described in the previous paragraph. Furthermore, as described and in addition to the previous paragraph, it is not necessary to determine all n w parameters once any pair of edges with nonzero w parameters is determined to have conflicting signs or, in some examples, once a w parameter is determined to have zero magnitude. In this latter case, it may be determined that intersection does not occur if the w parameter (for an edge of nonzero projected length) does not have the necessary sign. Alternatively, for a nondegenerate strictly convex polygon, it may be determined that intersection does occur if precisely two w parameters (for edges of nonzero projected length) both have the necessary sign (guaranteeing sign consistency of the remaining edges with nonzero w parameters), since the magnitudes of at most two w parameters (for edges of nonzero projected length) may be zero (one zero w parameter indicates edge intersection and two zero w parameters indicate vertex intersection). In the “sign-equality test”, a pair of equal signs of zero parameters (for edges of nonzero projected length) likewise determines an intersection, but this property often may not be exploited as edges with zero w parameters are generally not distinguished in this intersection test. This latter case assumes culling has not been enabled, as this may require checking the sign of one of the edges with nonzero w parameters.
(180) In some examples, the signed parameter, w, for an edge equals the 2D cross product for the edge. In other examples, the signed parameter, w, equals the 2D cross product multiplied by a positive constant (e.g., ½). In other examples, the signed parameter, w, equals the 2D cross product multiplied by a negative constant (e.g., −1), but in this case all orientation determinations are reversed. In the example shown in
(181) The 2D cross product for the first edge of polygon 206 defined by vertices v.sub.1 and v.sub.3 is given by ƒ(v.sub.1, v.sub.3)=p.sub.1q.sub.3−q.sub.1p.sub.3, and it will be appreciated by considering
(182) Following step S318 the method passes to step S320 in which the polygon testing unit(s) 114 of the intersection testing module 108 outputs an indication of the result of the determination of whether the ray intersects the k.sup.th polygon. This indication could be a binary indication (e.g. a one-bit flag) to indicate either a ‘hit’ or a ‘miss’ of the ray in respect of the polygon. In other examples, the indications could have different forms. Alongside an indication of whether intersection occurs, there may be additional output attributes, e.g., barycentric coordinates, orientation (clockwise/anticlockwise or front/back facing), and/or an intersection distance.
(183) In step S322 the polygon testing unit(s) 114 of the intersection testing module 108 determines whether there are more polygons to test. If so, then the method passes to step S324 in which the parameter, k, is incremented, and then the method passes back to step S310 so that steps S310 to S320 can be performed for the next polygon in order to determine whether the ray intersects the next polygon. When there are no more polygons to test, the method passes to step S326. Step S326 can be performed before, after or during step S322, i.e. step S326 can be performed following step S320 irrespective of whether there are more polygons to test.
(184) In step S326, the outputted indication is used in the ray tracing system 100 (e.g. by the processing logic 110) for rendering an image of a 3D scene. For example, as well as the indication that the ray intersects a polygon, in step S320 the polygon intersection testing unit(s) 114 of the intersection testing module 108 can output an intersection distance (i.e. a distance between the ray origin and the point at which the ray intersects the polygon), and an indication of the position on the polygon at which the ray intersects it (e.g. defined in barycentric coordinates), and this information can be output to the processing logic 110. In step S326 all the intersection tester output attributes, alongside other external attributes, e.g., scene data (e.g., light source(s), cube map), instance data, primitive/polygon ID, vertex data (e.g., positions, normal, texture coordinates), texture address(es), secondary ray data, etc., are processed to determine a colour value and/or generate additional secondary rays for future traversal.
(185) If barycentric coordinates are output in step S320, the magnitudes of the w parameters for the different edges of a polygon that the ray is determined to intersect may be used for determining the barycentric coordinates. For example, where the polygon is a triangular polygon having vertices v.sub.0, v.sub.1 and v.sub.2, for an intersection of a ray at an intersection point v with, the w values give twice the signed area of the sub-triangles formed by vertices (v, v.sub.0, v.sub.1), (v, v.sub.1, v.sub.2) and (v, v.sub.2, v.sub.0), up to uniform nonzero rescaling from the ray-space projection. The barycentric coordinates (which may be referred to as “areal coordinates”) are found by normalising these three w weights (i.e., summing them and dividing through by the total), so that they sum to 1. In particular, normalising the three w weights factors out all uniform scaling. As described above, all non-zero weights have the same sign for an intersection, so their magnitudes (rather than their signed values) can be normalised which reduces the complexity in the floating point operations, because it is simpler to add together three values which are known to be nonnegative than to add three values whose signs are unknown. The resulting barycentric coordinates α, β and γ, corresponding to the edges (v.sub.1, v.sub.2), (v.sub.2, v.sub.0) and (v.sub.0, v.sub.1) respectively, define a point of intersection of the ray with the convex polygon t=0+αv.sub.0+βv.sub.1+γv.sub.2. Finally, note that since the barycentrics, by definition, sum to one, only two of the three values need to be output (although, as described above, all three weights must be computed to perform the normalisation).
(186) If intersection distances are output in step S320, these may be calculated in terms of ray lengths rather than actual Euclidean distances. For example, the length of the ray may be divided through by √{square root over (D.sub.x.sup.2+D.sub.y.sup.2+D.sub.z.sup.2)}, and the intersection distance can be determined in terms of ray-lengths from the ray origin. In other words, a value T is computed, where t=0+Dτ is the point of intersection of the ray with the convex polygon. This value may be determined using the barycentric coordinates according to the intersection equation Dτ=αv.sub.0+βv.sub.1+γv.sub.2. In some examples, the projected coordinates s.sub.0, s.sub.1 and s.sub.2 (where generically s=A(D.sub.xv.sub.x+D.sub.yv.sub.y+D.sub.zy.sub.z)) may be used to determine τ, according to the equation A(D.sub.x.sup.2+D.sub.y.sup.2+D.sub.z.sup.2)τ=αs.sub.0+βs.sub.1+γs.sub.2 (obtained by multiplying both sides of the intersection equation by the projection matrix). The barycentric interpolated coordinates are then divided by A(D.sub.x.sup.2+D.sub.y.sup.2+D.sub.z.sup.2) to obtain τ. For example, fora rescaled ray with
(187)
and for which values of
(188)
have been pre-computed and stored, the square rescaled ray length
(189)
may be calculated and then τ may be determined as
(190)
Here we see that the
(191)
is requited to prevent the intersection distance being overcounted by a factor of D.sub.z and motivates the storage of this quantity in the ray format. Note that this extra scaling factor is not required if we do not rescale the ray along the direction of the ray (with A=1) but may use additional storage if we wish to retain the benefits of ray rescaling in the remaining projection operations (e.g. so that we may encode both
(192)
as well as D.sub.x, D.sub.y and D.sub.z). Also note that in one example
(193)
which if precomputed avoids the need to rescale the barycentric interpolated convex polygon coordinates but this too would require additional storage. In other examples, one component of the intersection equation is used to determine τ, so that equivalently D.sub.xτ=αv.sub.0x+βv.sub.1x+γv.sub.2x, D.sub.yτ=αv.sub.0y+βv.sub.1y+γv.sub.2y and D.sub.zτ=αv.sub.0z+βv.sub.1z+γv.sub.2z. In examples where
(194)
has been pre-computed and stored, it is often most efficient to select the last of these three options so that the intersection distance can be calculated by multiplying the barycentric interpolated vertex z components by the pre-computed reciprocal. If a reciprocal basis is employed (for which
(195)
as well as
(196)
or some scaling thereof may be pre-computed and stored) then the projection operations involve terms of
(197)
(which may be thought of as mapping the coordinates to “t” space) or possibly, as in rescaled examples, terms involving
(198)
(rescalea t space). Since we may write
(199)
it is possible to determine the intersection distance without any further calculation beyond barycentric interpolation of the scaled values (that feature in the projection calculation) unless the ray has been rescaled, in which case a factor of
(200)
is needed as in the general non-reciprocal rescaled basis case.
(201) Alternatively, if for example it is not convenient to generate scaled vertex components (in t space) then the barycentric interpolated result may be scaled by the appropriate one of
(202)
(which may again involve a further scaling by
(203)
have been pre-computed and stored). Whichever the case, both scaled and unscaled reciprocal bases provide the flexibility to select which axis should be used for interpolation, which as mentioned earlier, allows an axis to be chosen that has the most attractive error properties for a given convex polygon (e.g. by selecting the axis with the minimum range of values across the convex polygon).
(204) In the example shown in
(205)
and D.sub.z or
(206)
values of
(207)
and D.sub.z or
(208)
or values of
(209)
to give just some examples, and in other examples, other values may be pre-computed and read in order to define the ray direction. Alongside the pre-computed ray data, an indication of the major axis (e.g., a 2-bit enumeration), indicating the permutation, as well as the original signs of the ray direction components, indicating the reversal, is stored so that the same pre-computation can be applied to the polygon vertices when the ray is to be tested against them (and to post-modify the orientation determination if appropriate). The (only) overhead here is an extra 2 bits for indicating the major axis, but this (negligible) amount of additional storage is outweighed by avoiding finding the major component of the ray direction every time a polygon is tested against the ray.
(210) As described above, an issue can arise in the intersection testing process if the ray intersects a point on an edge of a polygon. For example, if the ray intersects a point on a shared edge, or if the ray intersects a shared vertex of a closed fan, which is shared by multiple polygons, then, in order for the intersection testing process to be “watertight”, the polygon intersection testing unit(s) 114 should, in most cases, determine that the ray intersects at least one of the polygons. In order for the intersection testing process to be “non-redundantly watertight”, the polygon intersection testing unit(s) 114 should, in most cases, determine that the ray intersects one and only one of the polygons. There are some exceptions to these definitions of what is meant by “watertight” and “non redundantly watertight” intersection testing, as described in detail above. If the intersection testing process is not watertight then rendering errors may be introduced into the rendered images, such as cracks in geometry, which is not desirable. One way to achieve a “watertight” intersection test is to project onto a ray-dependent plane (e.g., given by ray-space basis vectors P and Q), followed by exact determination of whether the polygon, including its boundary, cover the origin (e.g., by establishing whether the origin is inside of, or strictly on, each edge). This is not a “non-redundantly watertight” intersection test as it results in all polygons overlapping, such that all shared edges are hit two (or more) times and all shared vertices of closed fans are hit once for each polygon in the closed fan. The examples outlined below are configured to remove this redundancy.
(211) In some examples described herein a plane vertex ordering scheme is used to ensure that the intersection tests are “non-redundantly watertight”. The “plane vertex ordering scheme” may be referred to herein simply as a “vertex ordering scheme”. The plane vertex ordering scheme defines a universal ordering of the 2D projected vertices which is independent of the winding order of the vertices (i.e., inherited from the ordered sets of vertices defining the convex polygons). The ordering of the projected vertices according to the plane vertex ordering scheme is a total strict ordering. This implies that, for two distinct projected vertices a and b, we either have a<b or a>b. Note that there is no “natural” total strict ordering of the plane (i.e., consistent with arithmetic operations of the complex numbers) as there is for the line (i.e., consistent with the arithmetic operations of the real numbers). The ordering of the projected vertices according to the plane vertex ordering scheme defines a direction of each edge, independent of the direction inherited from the winding order(s) of the polygon(s) which include the edge. The winding order defines a cyclic ordering of vertices, i.e., a binary relationship in and only in the following circumstances: v.sub.i<v.sub.(i+1(mod n)) for n=0, . . . , n−1. Note that this is not a proper ordering as it does not meet all the axioms of a partial ordering, e.g., transitivity, and so is also not a total ordering like the projection-dependent ordering scheme, but is defined on the edges of the polygon and is used to determine their direction. Additionally, being a cyclic ordering, its binary relations are preserved by rotations of the convex polygon, and are reversed by reflections of the convex polygon. In examples described herein, and during intersection determination, an edge of a convex polygon may be considered part of the polygon's boundary precisely when the direction of the edge given by the plane vertex ordering scheme coincides with the direction of the edge given by the winding order of the polygon.
(212) In an example plane vertex ordering scheme, the universal direction of a projected edge is from its vertex with smallest p component to its vertex with largest p component, unless the projected vertices of the edge have equal p components, in which case the direction of a projected edge is from its vertex with smallest q component to its vertex with largest q component. To state this more mathematically, a 2D edge has two vertices (v.sub.i (with components p.sub.i and q.sub.i) and v.sub.j (with components p.sub.j and q.sub.j)), and, under the plane vertex ordering scheme, the edge is directed from min(v.sub.i, v.sub.j) to max(v.sub.i, v.sub.j), wherein the vertices are ordered such that v.sub.i<v.sub.j if p.sub.i<p.sub.j or if (p.sub.i=p.sub.j and q.sub.i<q.sub.j), otherwise v.sub.i>v.sub.j. To put this another way, a first projected vertex v.sub.i with components, p.sub.i and q.sub.i, along the respective axes of the pair of axes (P and Q), is before a second projected vertex v.sub.j with components, p.sub.i and q.sub.j, along the respective axes of the pair of axes, if p.sub.i<p.sub.j or if (p.sub.i=p.sub.j and q.sub.i<q.sub.j); whereas a first projected vertex v.sub.i with components, p.sub.i and q.sub.i, along the respective axes of the pair of axes, is after a second projected vertex v.sub.j with components, p.sub.i and q.sub.j, along the respective axes of the pair of axes, if p.sub.i>p.sub.j or if (p.sub.i=p.sub.j and q.sub.i>q.sub.j). Note that any nondegenerate projected convex polygon (i.e., with a nonzero projected area) will have at least three edges with nonequal endpoints. Hence, we either have v.sub.i<v.sub.j or v.sub.j<v.sub.i for all such edges, according to the plane vertex ordering scheme, and hence a well-defined direction for all such edges. In the specific example of a nondegenerate projected triangle polygon we will have all three edges with nonequal endpoints, according the plane vertex ordering scheme, and hence all three edges with a well-defined direction.
(213) When two projected vertices do have the same p and q components then this means that either the edge is degenerate (i.e., equal components along the axis parallel with the ray direction), or that the edge is nondegenerate (i.e. with different components along the axis parallel with the ray direction vector) and the ray is looking along the edge of the convex polygon, i.e., its direction is perpendicular to the normal of the (planar) polygon (up to the accuracy of the projection). For a convex polygon to be nondegenerate (in unprojected space and therefore also in projected space), the former case must not occur for three or more edges of the convex polygon. The latter case means the polygon appears as a line with respect to the ray, with zero projected area, and therefore a convex polygon with such an edge is always degenerate (in projected space). Such degenerate (projected) polygons may freely be missed by the ray. It is acceptable for the rules of “watertight” or “non-redundantly watertight” intersection testers not to apply to such degenerate polygons, so long as they do apply when those polygons are omitted.
(214) The plane vertex ordering scheme has eight alternative characterisations giving eight alternative pairs (for clockwise and anticlockwise orientations) of edge tie-break behaviours. For convex polygons with a clockwise orientation the examples described herein exhibit a “Left-Top Rule”, whereas for convex polygons with an anticlockwise orientation the examples described herein exhibit a “Right-Bottom Rule”. Other examples exhibit different tie-break behaviour pairs. For convex polygons of a clockwise/anticlockwise orientation, the eight alternative tie-break behaviour pairs exhibited are: (i) v.sub.i<v.sub.j if p.sub.i<p.sub.j or if (p.sub.i=p.sub.j and q.sub.i<q.sub.j) (as described in the main examples herein).fwdarw.“Left-Top/Right-Bottom Rule” (ii) v.sub.i<v.sub.j if p.sub.i<p.sub.j or if (p.sub.i=p.sub.j and q.sub.i>q.sub.j).fwdarw.“Right-Top/Left-Bottom Rule” (iii) v.sub.i<v.sub.j if p.sub.i>p.sub.j or if (p.sub.i=p.sub.j and q.sub.i<q.sub.j).fwdarw.“Left-Bottom/Right-Top Rule” (iv) v.sub.i<v.sub.j if p.sub.i>p.sub.j or if (p.sub.i=p.sub.j and q.sub.i>q.sub.j).fwdarw.“Right-Bottom/Left-Top Rule” (v) v.sub.i<v.sub.j if q.sub.i<q.sub.j or if (q.sub.i=q.sub.j and p.sub.i<p.sub.j).fwdarw.“Top-Left/Bottom-Right Rule” (vi) v.sub.i<v.sub.j if q.sub.i>q.sub.j OR if (q.sub.i=q.sub.j AND p.sub.i<p.sub.j).fwdarw.“Top-Right/Bottom-Left Rule” (vii) v.sub.i<v.sub.j if q.sub.i<q.sub.j OR if (q.sub.i=q.sub.j AND p.sub.i>p.sub.j).fwdarw.“Bottom-Left/Top-Right Rule” (viii) v.sub.i<v.sub.j if q.sub.i>q.sub.j OR if (q.sub.i=q.sub.j AND p.sub.i>p.sub.j).fwdarw.“Bottom-Right/Top-Left Rule”
(215) The above terms indicate which edges are considered part of the boundary of a convex polygon in intersection determination. The first/second tie-break behaviours correspond to when the convex polygon has an apparent clockwise/anticlockwise orientation viewed in projected 2D space. As the edge tie-break behaviour depends on the winding/orientation of the convex polygon, we call it a “winding/orientation dependent” watertightness scheme. Note that the tie-break behaviour reverses for polygons having the opposite orientation, e.g., “Left-Top Rule” and “Right-Bottom Rule”. For example, the term “Left-Top Rule” indicates that all edges bounding the convex polygon from above, or bounding the convex polygon from the left but precisely vertical, are considered part of the boundary of the polygon, and therefore are intersected. As the projection is ray dependent, these edge tie-break behaviours apply to a single ray only, and may change from ray to ray, e.g., when there is a change of perceived orientation and/or major axis.
(216) The way the edge tests are performed in examples described herein means that “non-redundant watertightness” can be considered to equate to anticommutativity on the result of the 2D cross product, with the problem case being (signed) zero, corresponding to a polygon boundary intersection. In other words, the watertightness problems can occur when a ray lands on an edge or a vertex (where ƒ=±0). In this situation we want to return only one hit.
(217) In the examples shown in
(218) For example, as shown in
(219)
(220) In step S404 the polygon intersection testing unit(s) 114 determines whether ƒ(v.sub.i, v.sub.j)=±0. If it is determined that ƒ(v.sub.i, v.sub.j)≠±0, then this indicates that the ray does not intersect a point on the e.sup.th edge, and then in step S406 the parameter, w, is set to equal to the 2D cross product, i.e. w=ƒ(v.sub.i, v.sub.j). In this way, the sign of the w parameter for the e.sup.th edge is determined to be the same as the sign of ƒ(v.sub.i, v.sub.j) if the ray is not determined to intersect a point on the edge. Then the method passes to step S314.
(221) However, if, in step S404, it is determined that ƒ(v.sub.i, v.sub.j)=±0, then this indicates that the ray does intersect a point on the e.sup.th edge, and then in step S408 the parameter, w, is set based on the plane ordering of the projected vertices defining the edge according to the plane vertex ordering scheme. In particular, the parameter is determined as w=(−1).sup.v.sup.
(222) For the example method shown in
(223) It is noted that the IEEE single precision floating point format allocates an encoding for both positive and negative zero (all zeros starting with a zero or one respectively). An implementation of the 2D cross product function ƒ may generate −0 in place of +0, but this will be implementation specific. In hardware, the precision of intermediate values may be expanded (be it implicitly or explicitly) to accommodate a larger range of values. It is clear that p.sub.iq.sub.j−q.sub.ip.sub.j can generate values outside the range of 8 bits of exponent and 23 bits of mantissa, given four 32-bit floats as input. Given this, some rounding is performed if the result is to be output in 32 bits. If one of the two closest representable values to nonzero result w is 0, then w may always be rounded to +0 (generally considered to represent the traditional unsigned 0) or may sometimes (or always) be rounded to −0. In other examples, the sign of w may be used to determine the rounding: If one of the two closest representative values to nonzero w is 0 and w is positive, then w may usually be rounded to +0, and other times to −0. If one of the two closest representable value to nonzero w is 0 and w is negative, then w may usually be rounded to −0, and other times to +0. If, in all such circumstances, the sign of nonzero w matches the sign of 0 it is rounded to, then this is known as “sign accurate rounding”. Alternatively, where a nonzero w would be rounded to +0, it may instead be rounded to the minimal representable positive floating point value (e.g., when rounding away from zero), and where a nonzero w would be rounded to −0, it may instead be rounded to the maximal representable negative floating point value (e.g., when rounding away from zero). If w is exactly 0 then one would normally expect it to be encoded as +0, but may sometimes (or always) be encoded as −0. The method described with reference to
(224) In the example shown in
(225) In the second example (which may be referred to as a “full edge sorting” method), shown in
(226) In step S504 the w parameter is determined as w=(−1).sup.v.sup.
(227) A binary function ƒ is anti-commutative if swapping the order of the vertices reverses the sign of ƒ. The “full edge sorting” method shown in
(228) In the example shown in
(229) Ensuring “non-redundant watertightness” is a particular issue when at least one vertex is a shared vertex which is used to define two or more convex polygons, e.g. in a closed fan. Methods described herein ensure “non-redundant watertightness” in the intersection testing when, for two or more (e.g. exactly two) convex polygons, the ray is determined to intersect a point on an edge of one of those convex polygons: In the example shown in
(230) For example, in the example “edge direction on-edge check” method described above with reference to
(231) It is noted that none of the other polygons 802 to 808 will have w parameters determined such that a pair of intersected edges both have negative sign (and zero magnitude) or, as an immediate corollary, that all edges have the same sign. For example, for polygon 802, the w parameter for the edge defined by projected vertices v.sub.1 and v.sub.2 will be determined, in step S408, to be w=(−1).sup.1.Math.(+0), which has a negative sign; whereas the w parameter for the edge defined by projected vertices v.sub.2 and v.sub.0 will be determined, in step S408, to be w=(−1).sup.0.Math.(+0), which has a positive sign, which is neither negative nor the same sign as the w parameter for the edge defined by the projected vertices v.sub.1 and v.sub.2. For brevity, we will not describe all of the calculations for polygons 804 to 808 here because it should now be apparent that they will not determine w parameters with either both negative signs for each intersected edge or having the same signs for all of their edges. Therefore the ray will not be determined to intersect with any of polygons 802, 804, 806 or 808.
(232) It is noted that the vertex ordering scheme and the alternative check for sign consistency on all edges produce equivalent results for polygons that have a clockwise orientation as viewed. That is to say, intersected clockwise polygons generate negative w parameters so positive intersection results are both negative on intersected edges as well as all remaining edges. Anticlockwise polygons, however, generate positive w parameters, such that positive intersection results, in the case of the vertex ordering scheme, retain negative sign on intersected edges, but positive sign on remaining edges, whereas the sign-equality test requires that both intersected edges and remaining edges all have positive sign. With reference to
(233) In the second example “full edge sorting” method described above with reference to
(234) Another example method for determining the w parameter for the e.sup.th edge of the k.sup.th polygon in step S312 (which may be referred to as a “endpoint sign/zero on-edge check” method) is described with reference to the flow chart shown in
(235) Therefore, in step S902 the polygon intersection testing unit(s) 114 of the intersection testing module 108 determine an implementation of the 2D cross product ƒ(v.sub.i, v.sub.j)=p.sub.iq.sub.j−q.sub.ip.sub.j, for the e.sup.th edge which is defined by projected vertices v.sub.i and v.sub.j, ordered according to the winding order of the vertices in the ordered set of vertices defining the k.sup.th polygon. In step S904 the polygon intersection testing unit(s) 114 determine whether ƒ(v.sub.i, v.sub.j)=±0. If it is determined that ƒ(v.sub.i, v.sub.j)≠±0, then this indicates that the ray should not intersect a point on the e.sup.th edge, and then in step S906 the parameter, w, is set to equal to the 2D cross product, i.e. w=ƒ(v.sub.i, v.sub.j). In this way, the sign of the w parameter for the e.sup.th edge is determined to be the same as the sign of ƒ(v.sub.i, v.sub.j) if it is determined that the ray should not intersect a point on the edge. Then the method passes to step S314. For the scheme described with reference to
(236) However, if, in step S904, it is determined that ƒ(v.sub.i, v.sub.j)=±0, then this indicates that the ray might intersect a point on the e.sup.th edge, and then in steps S908 to S912 the sign of the parameter, w, is determined using a module which comprises a lookup table (LUT) and/or a logic array. In examples described herein the module comprising the lookup table and/or logic array is implemented on the intersection testing module 108 as a block of pre-configured logic in fixed-function hardware (e.g. as part of the polygon testing unit(s) 114). The functionality of the lookup table and/or logic array described herein can be considered to apply generally to the “module” comprising the lookup table and/or the logic array. The lookup table and/or logic array is configured to take, as its inputs, indications which classify each of the p.sub.i, q.sub.i, p.sub.j and q.sub.j coordinates as a trichotomy of negative, (plus or minus) zero or positive (e.g., as a “trit”), and to output, for valid combinations of classifications of the p.sub.i, q.sub.i, p.sub.j and q.sub.j coordinates, an indication of the sign of the signed parameter, w (e.g., as a bit). The lookup table or logic array may also be configured to take an indication of the sign of ƒ and the boolean state of an “underflow flag” as two other input bits.
(237) The lookup table and/or logic array models a function with input trits p.sub.i, q.sub.i, p.sub.j and q.sub.j (possibly as well as input bit sgn(ƒ) and the boolean state of an underflow flag) to provide an output bit indicating the sign of w. There are 2.sup.81 (or 2.sup.324) such functions. This can be achieved in a first way by a look-up table, e.g. explicitly listing 81 (or 324) bit values and using the inputs as a look-up index/reference value. This would use at least 10 (or 40) bytes of raw storage in a data store (e.g. hardcoded in software or a register in hardware). It is noted that, the lookup table is reduced to a quarter of its size without the addition of the other two inputs. Alternatively, this can be achieved in a second way by a “logic array”, e.g. a configuration of logical operations in software or logical gates in hardware, performing the desired mapping. The symmetry of the problem, along with a small number of “don't care” outputs, allows the number of logic gates to be reduced. Some hybrid of the two implementations (lookup table and logic array implementations) may also be possible, e.g. a reduced size LUT using some pre- or post-processing logic to leverage the symmetry of the problem. Either implementations may afford power or area gains over the other, depending on the specific architecture, where the first way (LUT implementation) may be more suitable to software, and the second (logic array implementation) may be more suitable to hardware in general.
(238) In step S908 the polygon testing unit(s) 114 classify each of the p.sub.i, q.sub.i, p.sub.j and q.sub.j coordinates for the vertices v.sub.i and v.sub.j defining the e.sup.th edge as: (i) negative, (ii) (plus or minus) zero, or (iii) positive. It is noted that in order to be classified as negative or positive, a coordinate is non-zero. In other words, for the purposes of this classification of the coordinates, (plus or minus) zero is considered to be non-negative and non-positive. Where the coordinates are in a floating point format, and if denormals have been excluded or flushed, the exponent of a coordinate can be checked (e.g. all zeros) to determine whether the coordinate is zero (regardless of the sign bit), and if the coordinate is not zero, the sign bit of the coordinate can be checked to determine whether it is negative or positive. These are very simple tests to perform, e.g. in fixed function hardware. If denormal numbers are supported then the significand may be checked (e.g. all zeros), as well as the exponent, to determine whether a coordinate is zero.
(239) In step S910 indications of the classifications of the coordinates are input to the lookup table or logic array. For example, the indications of the classifications can be considered to be used as indices or reference values to lookup a piece of data (i.e. the sign of w) from the lookup table or to determine the sign of w using the logic array.
(240) In step S912 the polygon testing unit(s) 114 receives the output from the lookup table or logic array which indicates the sign of the w parameter for the edge. The method then passes to step S314 and continues as described above.
(241) The use of the lookup table or logic array makes the determination of the sign of the w parameter extremely fast to implement, so steps S908 to S912 can be performed with very low latency and very low power consumption. A small amount of pre-configured logic can be used to implement the lookup table or logic array so a small amount of silicon area may be used to implement the lookup table or logic array in hardware, but this area will be very small because the operations performed by the lookup table or logic array are simple to implement in hardware.
(242) Furthermore, the lookup table or logic array is configured such that if the order of the two projected vertices defining an edge is reversed then the indication of the sign of the signed parameter that is outputted from the lookup table or logic array is reversed. This ensures that the intersection testing is “non-redundantly watertight” for non-silhouette shared edges of polygons with consistent winding orders. In examples described herein, this functionality is hardcoded into the lookup table or logic array.
(243) As described above, the ray is determined to intersect a point on an edge if the implementation of the 2D cross product ƒ(v.sub.i, v.sub.j)=p.sub.iq.sub.j−q.sub.ip.sub.j of the positions of two projected vertices defining the edge has a magnitude of zero.
(244) For “endpoint sign/zero on-edge check”, when ƒ(v.sub.i, v.sub.j)=p.sub.iq.sub.j−q.sub.ip.sub.j=±0, and in order to determine a tie-break behaviour for “non-redundant watertightness”, the method considers what the 2D cross product would be if the positions of the two projected vertices defining the edge were perturbed by ε=(ε.sub.p, ε.sub.q), as illustrated in
(245) The “endpoint sgn zero-check” method has eight alternative characterisations giving eight alternative edge tie-break behaviours. The examples described herein exhibit a “Right-Top Rule”. Other examples exhibit different tie-break behaviour pairs. The eight alternative tie-break behaviour pairs exhibited are: (i) 0<ε.sub.p<<ε.sub.q (as described in detail in the main example herein).fwdarw.“Right-Top Rule” (ii) ε.sub.p<0<|ε.sub.p|<<ε.sub.q.fwdarw.“Left-Top Rule” (iii) ε.sub.q<0<ε.sub.p<<|ε.sub.q|.fwdarw.“Right-Bottom Rule” (iv) ε.sub.q<<ε.sub.p<0.fwdarw.“Left-Bottom Rule” (v) 0<ε.sub.q<<ε.sub.p.fwdarw.“Top-Right Rule” (vi) ε.sub.q<0<ε.sub.p.fwdarw.“Top-Left Rule” (vii) ε.sub.p<0<ε.sub.q<<|ε.sub.p|.fwdarw.“Bottom-Right Rule” (viii) ε.sub.p<<ε.sub.q<0.fwdarw.“Bottom-Left Rule”
(246) The above terms indicate which edges are considered part of the boundary of a convex polygon in intersection determination, regardless of the apparent orientation of the convex polygon viewed in projected 2D space. As the edge tie-break behaviour does not depend on the winding/orientation of the convex polygon, we call it a “winding/orientation independent” watertightness scheme. For example, the term “Left-Top Rule” indicates that all edges bounding the convex polygon from above, or bounding the convex polygon from the left but precisely vertical, are considered part of the boundary of the polygon, and therefore are intersected. As the projection is ray dependent, these edge tie-break behaviours apply to a single ray only, and may change from ray to ray, e.g., when there is a change of perceived orientation and/or major axis.
(247) With this perturbation, the 2D cross product function becomes:
ƒ(v.sub.i,v.sub.j)=(p.sub.i+ε.sub.p)(q.sub.j+ε.sub.q)−(q.sub.i+ε.sub.q)(p.sub.j+ε.sub.p)=p.sub.iq.sub.j−q.sub.ip.sub.j+p.sub.iε.sub.q+ε.sub.pq.sub.j−q.sub.iε.sub.p−ε.sub.qp.sub.j (1)
(248) The lookup table is configured to output, for all valid combinations of classifications of the p.sub.i, q.sub.i, p.sub.j and q.sub.j coordinates, an indication of the sign of the signed parameter w. In some examples, e.g., fora RAZ implementation type, the lookup table or logic array is configured to output: (i) for some valid combinations of classifications of the p.sub.i, q.sub.i, p.sub.j and q.sub.j coordinates, the sign of the signed parameter w as the sign, or opposite of the sign, of p.sub.i, q.sub.i, p.sub.j or q.sub.j, and (ii) for some invalid combinations of classifications of the p.sub.i, q.sub.i, p.sub.j and q.sub.j coordinates, the sign of the signed parameter w as any value. In some other examples, e.g., for an RTZ implementation type, the lookup table or logic array is configured to further output: (iii) for some valid combinations of the classification of the p.sub.i, q.sub.i, p.sub.j and q.sub.j coordinates, the sign of the signed parameter w as the sign, or opposite of the sign, of the product of two of p.sub.i, q.sub.i, p.sub.j or q.sub.j, and (iv) for one or more other valid combinations of classifications of the p.sub.i, q.sub.i, p.sub.j and q.sub.j coordinates, the sign of the signed parameter w, as the sign of the implementation of the 2D cross product ƒ. In addition, in some other examples, e.g., for an RTZ implementation type, an “underflow flag” is used to determine which of (i), (ii), (iii) or (iv) is configured to be the output.
(249) For example, the polygon intersection testing unit(s) 114 may operate according to a “round-away-from-zero” (RAZ) implementation type when determining the 2D cross product function for use in determining the w parameters, ensuring the kernel of the implementation of the 2D cross product matches the kernel of ƒ. When a RAZ implementation type is used then the lookup table may be configured to output, for all valid combinations of classifications of the p.sub.i, q.sub.i, p.sub.j and q.sub.j coordinates for which ƒ can be determined to be zero, an indication of the sign of the signed parameter, w. In particular, when a RAZ rounding mode is used then it is determined in step S904 that ƒ(v.sub.i, v.sub.j)=p.sub.iq.sub.j−q.sub.ip.sub.j=±0 if and only if the value of the 2D cross product truly is zero, and not because a non-zero value of the 2D cross product has been approximated as zero by the implementation. Therefore, in this case, equation (1) becomes:
ƒ(v.sub.i,v.sub.j)=p.sub.iε.sub.q+ε.sub.pq.sub.j−q.sub.iε.sub.p−ε.sub.qp.sub.j (2)
(250)
(251)
(252) In
(253) In
(254) In
(255) In
(256) In
(257) In
(258) In
(259) In
(260) In
(261) The situation shown in
(262) The situation shown in
(263) The situation shown in
(264)
(265) In some other examples, the polygon intersection testing unit(s) 114 may operate according to an implementation of the 2D cross product that is not a RAZ type for use in determining the w parameters. For example, the implementation of the 2D cross product may use a rounding mode that is round to nearest, round towards zero, round towards positive infinity or round to negative infinity. When a non-RAZ implementation type is used then the value of ƒ may be determined to be (plus or minus) zero even though the exact value of ƒ is not zero. For example, a value of ƒ that is very close to zero may be rounded to (plus or minus) zero. This loss of precision in calculations involving floating point numbers is referred to as “underflow”. Therefore, when a non-RAZ, but still sign accurate, implementation type (denoted RTZ) is used to calculate the 2D cross product, then the lookup table or logic array needs to account for situations in which the edge does not exactly intersect the origin (in addition to the situations in which the edge does exactly intersect the origin). One way to accomplish this is to provide an indication that underflow has occurred and in that case proceed to step S906 as if a nonzero value had been computed or, equivalently, supply both an indication of underflow and the sign of ƒ as additional inputs to the lookup table in step S910 such that the sign is used as output. There are, however, alternative methods that make uses of steps S908 and S910 as now described.
(266) In
(267) When representing signs as + or −, indicating +1 or −1, we take the product of the signs to combine them and we negate to get the opposite result. When representing signs as 0 or 1, we take the XOR of the signs, or equivalently the sum of the signs modulo two, to combine them and we NOT, equivalently complement, to get the opposite result. The symbols in
(268) In
(269) In
(270) In
(271) In
(272) In
(273) The situation shown in
(274) The situation shown in
(275) The situation shown in
(276) The situation shown in
(277) There is a trichotomy (negative, (plus or minus) zero, positive) for each of the four input coordinates. When the convex polygons are triangles, the case of p.sub.i=q.sub.i=p.sub.j=q.sub.j=0 does not need to be included in the lookup table or logic array because, in general, any projected edge such that p.sub.i=p.sub.j and q.sub.i=q.sub.j represents a degenerate projected edge, i.e. it appears as a point, and triangle polygons including such edges can be discarded because they must be degenerate, and a ray does not need to be determined to intersect degenerate polygons. So, in total, there are 3.sup.4−1=80 examples (excluding the degenerate point line), and the
(278) For a general convex polygon having n sides, at least n−2 projected edges must be degenerate for the projected polygon to be degenerate, i.e. to have zero projected area, and hence able to be culled freely. If there are fewer than n−2 degenerate projected edges, then the signs of degenerate edge tests (i.e., the case of p.sub.i=p.sub.j and q.sub.i=q.sub.j) can be ignored when testing whether all edge signs are equal, so the case of p.sub.i=q.sub.i=p.sub.j=q.sub.j=0 does not need to be included in the lookup table of logic array for a general convex polygon either. Such edges can be detected simply by checking if the two projected endpoints are equal. Geometrically, a higher order polygon with such degenerate edges collapses to a lower order polygon (similar to a non-strictly convex polygon). Such pathological cases can be avoided by ensuring that no two vertices of a strictly convex polygon are equal. When the normal of the (planar) convex polygon is perpendicular to the ray direction it will also have zero area as it appears as a line, and hence will also be a degenerate projected polygon, even if it has no degenerate (i.e. point) projected edges.
(279) In one example, two bits can be used as the input for a coordinate to indicate negative, zero or positive. For example, a first bit could indicate that the input coordinate is either zero or non-zero, and a second bit could indicate that the input coordinate is either negative or positive. In this example, in the situation that the first bit indicates that the input coordinate is zero, then it doesn't matter what the second bit is; whereas if the first bit indicates that the input coordinate is non-zero, then the second bit is used to indicate that the input coordinate is either negative or positive. In another example, for each of the four input coordinates, the three values of a trit (i.e., 0, 1 and 2) can be assigned to encode the trichotomy of −, ±0 or + in any order. Then, the four trits (plus possibly an additional bit for the sign of the 2D cross product, plus possibly another additional bit for underflow detection, both for an RTZ implementation type) can be merged into a value between 0 and 80 (e.g. representing a case ID between 1 and 81 as shown in the table below) (or between 0 and 161, or 0 and 323), so that the value can be encoded in binary with 7 (or 8, or 9) bits.
(280) The lookup table or logic array may be hardcoded in fixed function circuitry in the polygon intersection testing unit(s) 114 of the intersection testing module 108. Table 2 below shows an example of the inputs and outputs of an implementation of the lookup table or logic array, with some explanatory comments. A value of 0 for an input coordinate p.sub.i, q.sub.i, p.sub.j or q.sub.j indicates a value of either plus or minus zero. Likewise, a result of 0 for the implementation of the 2D cross product ƒ indicates a value of either plus or minus zero. For any input of output, a “don't care” value is represented by the symbol ‘X’:
(281) TABLE-US-00002 TABLE 2 Example inputs, outputs and explanatory data for the lookup table or logic array Inputs Dual Is Case Due to Case Underflow sgn Output Case f = ±0 or ID Flag Set? (f) p.sub.i q.sub.i p.sub.j q.sub.j Figure Sign of w ID Underflow? 1.0 X + − − − − 11j/12j + (RTZ type) 1.1 f = 0/Underflow X (RAZ type) 1.1 X − − − − − 11j/12j − (RTZ type) 1.0 f = 0/Underflow X (RAZ type) 2 X ± − − − 0 12f − 10 Underflow 3 X ± − − − + 12i − 19 Underflow 4 X ± − − 0 − 12e + 28 Underflow 5 X ± − − 0 0 11a − 37 f = 0 6 X ± − − 0 + 12e − 46 Underflow 7 X ± − − + − 12h + 55 Underflow 8 X ± − − + 0 12f + 64 Underflow 9.00 N + − − + + 11e − 73.01 f = 0 9.01 N − − − + + 11e − 73.00 f = 0 9.10 Y + − − + + 12g + 73.11 Underflow 9.11 Y − − − + + 12g − 73.10 Underflow 10 X ± − 0 − − 12d + 2 Underflow 11 X ± − 0 − 0 11l X 11 f = 0 12 X ± − 0 − + 12d − 20 Underflow 13 X ± − 0 0 − 12b + 29 Underflow 14 X ± − 0 0 0 11d − 38 f = 0 15 X ± − 0 0 + 12b − 47 Underflow 16 X ± − 0 + − 12d + 56 Underflow 17 X ± − 0 + 0 11g − 65 f = 0 18 X ± − 0 + + 12d − 74 Underflow 19 X ± − + − − 12i + 3 Underflow 20 X ± − + − 0 12f + 12 Underflow 21.0 X + − + − + 11j/12j + (RTZ type) 21.1 f = 0/Underflow X (RAZ type) 21.1 X − − + − + 11j/12j − (RTZ type) 21.0 f = 0/Underflow X (RAZ type) 22 X ± − + 0 − 12e + 30 Underflow 23 X ± − + 0 0 11a − 39 f = 0 24 X ± − + 0 + 12e − 48 Underflow 25.00 N + − + + − 11e − 57.01 f = 0 25.01 N − − + + − 11e − 57.00 f = 0 25.10 Y + − + + − 12g + 57.11 Underflow 25.11 Y − − + + − 12g − 57.10 Underflow 26 X ± − + + 0 12f − 66 Underflow 27 X ± − + + + 12h − 75 Underflow 28 X ± 0 − − − 12c − 4 Underflow 29 X ± 0 − − 0 12a − 13 Underflow 30 X ± 0 − − + 12c − 22 Underflow 31 X ± 0 − 0 − 11k X 31 f = 0 32 X ± 0 − 0 0 11b + 40 f = 0 33 X ± 0 − 0 + 11c + 49 f = 0 34 X ± 0 − + − 12c + 58 Underflow 35 X ± 0 − + 0 12a + 67 Underflow 36 X ± 0 − + + 12c + 76 Underflow 37 X ± 0 0 − − 11i + 5 f = 0 38 X ± 0 0 − 0 11h + 14 f = 0 39 X ± 0 0 − + 11i + 23 f = 0 40 X ± 0 0 0 − 11f − 32 f = 0 41 X ± 0 0 0 0 N/A X 41 f = 0 42 X ± 0 0 0 + 11f + 50 f = 0 43 X ± 0 0 + − 11i − 59 f = 0 44 X ± 0 0 + 0 11h − 68 f = 0 45 X ± 0 0 + + 11i − 77 f = 0 46 X ± 0 + − − 12c + 6 Underflow 47 X ± 0 + − 0 12a + 15 Underflow 48 X ± 0 + − + 12c + 24 Underflow 49 X ± 0 + 0 − 11c − 33 f = 0 50 X ± 0 + 0 0 11b − 42 f = 0 51 X ± 0 + 0 + 11k X 51 f = 0 52 X ± 0 + + − 12c − 60 Underflow 53 X ± 0 + + 0 12a − 69 Underflow 54 X ± 0 + + + 12c − 78 Underflow 55 X ± + − − − 12h − 7 Underflow 56 X ± + − − 0 12f − 16 Underflow 57.00 N + + − − + 11e + 25.01 f = 0 57.01 N − + − − + 11e + 25.00 f = 0 57.10 Y + + − − + 12g + 25.11 Underflow 57.11 Y − + − − + 12g − 25.10 Underflow 58 X ± + − 0 − 12e − 34 Underflow 59 X ± + − 0 0 11a + 43 f = 0 60 X ± + − 0 + 12e + 52 Underflow 61.0 X + + − + − 11j/12j + (RTZ type) 61.1 f = 0/Underflow X (RAZ type) 61.1 X − + − + − 11j/12j − (RTZ type) 61.0 f = 0/Underflow X (RAZ type) 62 X ± + − + 0 12f + 70 Underflow 63 X ± + − + + 12i + 79 Underflow 64 X ± + 0 − − 12d − 8 Underflow 65 X ± + 0 − 0 11g + 17 f = 0 66 X ± + 0 − + 12d + 26 Underflow 67 X ± + 0 0 − 12b − 35 Underflow 68 X ± + 0 0 0 11d + 44 f = 0 69 X ± + 0 0 + 12b + 53 Underflow 70 X ± + 0 + − 12d − 62 Underflow 71 X ± + 0 + 0 11l X 71 f = 0 72 X ± + 0 + + 12d + 80 Underflow 73.00 N + + + − − 11e + 9.01 f = 0 73.01 N − + + − − 11e + 9.00 f = 0 73.10 Y + + + − − 12g + 9.11 Underflow 73.11 Y − + + − − 12g − 9.10 Underflow 74 X ± + + − 0 12f + 18 Underflow 75 X ± + + − + 12h + 27 Underflow 76 X ± + + 0 − 12e − 36 Underflow 77 X ± + + 0 0 11a + 45 f = 0 78 X ± + + 0 + 12e + 54 Underflow 79 X ± + + + − 12i − 63 Underflow 80 X ± + + + 0 12f − 72 Underflow 81.0 X + + + + + 11j/12j + (RTZ type) 81.1 f = 0/Underflow X (RAZ type) 81.1 X − + + + + 11j/12j − (RTZ type) 81.0 f = 0/Underflow X (RAZ type)
(282) It can be seen that Table 2 has symmetry about its median value (i.e., case 41), whereby an underflow case maintains its output sign (as rotating an edge by 180 degrees should fix the circulation of an interior intersection), whereas an ƒ=0 case reverses its sign (as rotating an edge by 180 degrees should reverse the circulation of an on-edge intersection), when going from case c to case 82-c. Table 2 also has symmetry in its duality: swapping the first two trits with the second two trits switches between a case and its dual case, reversing the output sign, as required by the anticommutative property of the signed area calculation. Both of these properties can be leveraged to reduce the size of a LUT implementing Table 2, by using a certain amount of pre- or post-processing logic, or to reduce the complexity of a logic array implementing Table 1.
(283) In the table above, the “dual case ID” column gives the case ID of the situation in which the order of the vertices defining the edge has been swapped. It can be seen that the dual case gives the opposite output for the sign of the w parameter. This ensures that when a ray intersects a shared edge, it is determined to intersect one (and only one) of the polygons which include the shared edge. In the final column, “ƒ=0” indicates that this situation occurs because the exact value of the 2D cross product is zero, i.e., no underflow has occurred (e.g. as shown in
(284) However, when an RTZ implementation type is used (and step S904 hasn't been modified such that step S906 is performed if underflow occurs) then the lookup table or logic array does include the rows which can only occur due to underflow (as well as all of the other rows), and these cases do represent “valid” combinations of classifications of the p.sub.i, q.sub.i, p.sub.j and q.sub.j coordinates for the lookup table or logic array, i.e. they can validly occur when ƒ=±0, as the kernel of the implementation off is a strict superset of its own kernel. As described in examples above, the underflow flag is set during the determination of the 2D cross product if the 2D cross product is determined to be not exactly equal to zero, but is rounded to zero. Entries in the lookup table can be avoided for the RTZ examples by only invoking the watertightness behaviours if both the magnitude of w is zero and the underflow flag has not been set. In other words, in some examples, the ray may be determined to intersect a point on an edge if: (i) the 2D cross product of the positions of two projected vertices defining the edge has a magnitude of zero, and (ii) an underflow flag has not been set during the determination of the 2D cross product. In these examples, if the 2D cross product of the positions of two projected vertices defining the edge is determined to have a magnitude of zero but the underflow flag has been set during the determination of the 2D cross product then the ray is not determined to intersect a point on an edge, and the sign of w for the edge may be set to be equal to the sign of the 2D cross product (which is either +0 or −0).
(285) For some of the rows of the lookup table or logic array the output value is denoted by ‘X’ indicating a “don't care” result. In these examples, the sign of w does not matter because a strictly convex polygon with such an edge cannot be intersected by the ray, e.g. because the ray does not pass on the inside of one of the other edges of the polygon. The case in which p.sub.i=q.sub.i=p.sub.j=q.sub.j=0 is not required: either a triangle polygon including such an edge is degenerate, so can be discarded, or such an edge of a higher order polygon can be identified, in order to exclude its sign from the intersection determination. In either case, it does not need to be included in the lookup table or logic array.
(286) In step S912 the output from the lookup table or logic array indicating the sign of the w parameter is received at the polygon intersection testing unit(s) 114 of the intersection testing module 108. Then the method passes to step S314 which is described above, and the method continues.
(287) The method describing that an intersection is determined only if the universal plane direction matches the winding direction of a shared edge ensures “non-redundant watertightness” when the polygons forming a mesh all have consistent winding orders, even on silhouette edges, and hence is denoted a “winding/orientation dependent” scheme, as mentioned earlier. The methods described with reference to
(288) For example, the differentiating functionality between a “winding/orientation dependent” scheme and a “winding/orientation independent” scheme is made clear in
(289) The first (i.e. top left) respective polygon pairs in both
(290) The second (i.e. top right) respective polygon pairs in both
(291) The third (i.e. bottom left) respective polygon pairs in both
(292) The difference in behaviour between the two types of scheme (shown in
(293)
(294) The occurrence of such rendering redundancies/artefacts described in the previous example (which may occur due to inconsistent winding orders of the polygons forming a mesh) cannot be universally removed, but they can be relocated so that they occur only at the silhouette edges of a mesh of polygons. Visual artefacts at the silhouette edges of geometry in a rendered image are less noticeable to a viewer of the rendered image than visual artefacts in the middle of an object which may, for example in the instance of zero hits, give the appearance of the object having a hole in it, such that a background colour or occluded geometry can be seen through the object. Although visual artefacts are ameliorated, rendering redundancies, in the form or double hits, still occur. Therefore, overall, it can be preferable to move the possible rendering artefacts to the silhouette edges. This can be achieved in a winding/orientation independent scheme (such as the methods described with reference to
(295)
(296) The post-processing XOR operation, being an involution, can be used both to transform a “winding/orientation dependent” scheme into a “winding/orientation independent” scheme and to transform a “winding/orientation independent” scheme into a “winding/orientation dependent” scheme. Hence, this technique can be used to convert the method, where an intersection occurs only if the universal plane direction matches the winding direction of a shared edge, into a “winding/orientation independent” scheme, and also used to convert the methods as described above with reference to
(297) In some examples of a “winding/orientation independent” scheme (e.g., the methods as described above with reference to
(298) By augmenting the on-edge signs by the sign of the polygon (denoting its perceived orientation) in the “winding/orientation dependent” scheme, the tie-breaking behaviour reverses between a polygon with a sign of 0 and a polygon with a sign of 1. The eight characterisations of the tie-breaking behaviour split into four pairs: “Top-Left Rule” and “Bottom-Right Rule”, “Top-Right Rule” and “Bottom-Left Rule”, “Left-Top Rule” and “Right-Bottom Rule”, and “Right-Top Rule” and “Left-Bottom Rule”. One member of each of these tie-break behaviour pairs corresponds to a polygon with a sign of 0, and the other to a polygon with a sign of 1. This is demonstrated in
(299) In summary, if consistent winding orders of polygons are expected (or even guaranteed) to be submitted, e.g., orientable surfaces, e.g., an annulus, then the “winding/orientation dependent” scheme may be preferable, whereas if inconsistent winding orders of polygons are expected (or even impossible to avoid) to be submitted, e.g., non-orientable surfaces, e.g., a Mobius band, then the “winding/orientation independent” scheme may be preferable.
(300)
(301) The ray tracing system of
(302) The ray tracing units, and specifically the intersection testing modules described herein may be embodied in hardware on an integrated circuit. The intersection testing modules described herein may be configured to perform any of the methods described herein. Generally, any of the functions, methods, techniques or components described above can be implemented in software, firmware, hardware (e.g., fixed logic circuitry), or any combination thereof. The terms “module,” “functionality,” “component”, “element”, “unit”, “block” and “logic” may be used herein to generally represent software, firmware, hardware, or any combination thereof. In the case of a software implementation, the module, functionality, component, element, unit, block or logic represents program code that performs the specified tasks when executed on a processor. The algorithms and methods described herein could be performed by one or more processors executing code that causes the processor(s) to perform the algorithms/methods. Examples of a computer-readable storage medium include a random-access memory (RAM), read-only memory (ROM), an optical disc, flash memory, hard disk memory, and other memory devices that may use magnetic, optical, and other techniques to store instructions or other data and that can be accessed by a machine.
(303) The terms computer program code and computer readable instructions as used herein refer to any kind of executable code for processors, including code expressed in a machine language, an interpreted language or a scripting language. Executable code includes binary code, machine code, bytecode, code defining an integrated circuit (such as a hardware description language or netlist), and code expressed in a programming language code such as C, Java or OpenCL. Executable code may be, for example, any kind of software, firmware, script, module or library which, when suitably executed, processed, interpreted, compiled, executed at a virtual machine or other software environment, cause a processor of the computer system at which the executable code is supported to perform the tasks specified by the code.
(304) A processor, computer, or computer system may be any kind of device, machine or dedicated circuit, or collection or portion thereof, with processing capability such that it can execute instructions. A processor may be or comprise any kind of general purpose or dedicated processor, such as a CPU, GPU, NNA, System-on-chip, state machine, media processor, an application-specific integrated circuit (ASIC), a programmable logic array, a field-programmable gate array (FPGA), or the like. A computer or computer system may comprise one or more processors.
(305) It is also intended to encompass software which defines a configuration of hardware as described herein, such as HDL (hardware description language) software, as is used for designing integrated circuits, or for configuring programmable chips, to carry out desired functions. That is, there may be provided a computer readable storage medium having encoded thereon computer readable program code in the form of an integrated circuit definition dataset that when processed (i.e. run) in an integrated circuit manufacturing system configures the system to manufacture an intersection testing module configured to perform any of the methods described herein, or to manufacture an intersection testing module comprising any apparatus described herein. An integrated circuit definition dataset may be, for example, an integrated circuit description.
(306) Therefore, there may be provided a method of manufacturing, at an integrated circuit manufacturing system, an intersection testing module as described herein. Furthermore, there may be provided an integrated circuit definition dataset that, when processed in an integrated circuit manufacturing system, causes the method of manufacturing an intersection testing module to be performed.
(307) An integrated circuit definition dataset may be in the form of computer code, for example as a netlist, code for configuring a programmable chip, as a hardware description language defining hardware suitable for manufacture in an integrated circuit at any level, including as register transfer level (RTL) code, as high-level circuit representations such as Verilog or VHDL, and as low-level circuit representations such as OASIS (RTM) and GDSII. Higher level representations which logically define hardware suitable for manufacture in an integrated circuit (such as RTL) may be processed at a computer system configured for generating a manufacturing definition of an integrated circuit in the context of a software environment comprising definitions of circuit elements and rules for combining those elements in order to generate the manufacturing definition of an integrated circuit so defined by the representation. As is typically the case with software executing at a computer system so as to define a machine, one or more intermediate user steps (e.g. providing commands, variables etc.) may be required in order for a computer system configured for generating a manufacturing definition of an integrated circuit to execute code defining an integrated circuit so as to generate the manufacturing definition of that integrated circuit.
(308) An example of processing an integrated circuit definition dataset at an integrated circuit manufacturing system so as to configure the system to manufacture an intersection testing module will now be described with respect to
(309)
(310) The layout processing system 1504 is configured to receive and process the IC definition dataset to determine a circuit layout. Methods of determining a circuit layout from an IC definition dataset are known in the art, and for example may involve synthesising RTL code to determine a gate level representation of a circuit to be generated, e.g. in terms of logical components (e.g. NAND, NOR, AND, OR, MUX and FLIP-FLOP components). A circuit layout can be determined from the gate level representation of the circuit by determining positional information for the logical components. This may be done automatically or with user involvement in order to optimise the circuit layout. When the layout processing system 1504 has determined the circuit layout it may output a circuit layout definition to the IC generation system 1506. A circuit layout definition may be, for example, a circuit layout description.
(311) The IC generation system 1506 generates an IC according to the circuit layout definition, as is known in the art. For example, the IC generation system 1506 may implement a semiconductor device fabrication process to generate the IC, which may involve a multiple-step sequence of photo lithographic and chemical processing steps during which electronic circuits are gradually created on a wafer made of semiconducting material. The circuit layout definition may be in the form of a mask which can be used in a lithographic process for generating an IC according to the circuit definition. Alternatively, the circuit layout definition provided to the IC generation system 1506 may be in the form of computer-readable code which the IC generation system 1506 can use to form a suitable mask for use in generating an IC.
(312) The different processes performed by the IC manufacturing system 1502 may be implemented all in one location, e.g. by one party. Alternatively, the IC manufacturing system 1502 may be a distributed system such that some of the processes may be performed at different locations, and may be performed by different parties. For example, some of the stages of: (i) synthesising RTL code representing the IC definition dataset to form a gate level representation of a circuit to be generated, (ii) generating a circuit layout based on the gate level representation, (iii) forming a mask in accordance with the circuit layout, and (iv) fabricating an integrated circuit using the mask, may be performed in different locations and/or by different parties.
(313) In other examples, processing of the integrated circuit definition dataset at an integrated circuit manufacturing system may configure the system to manufacture an intersection testing module without the IC definition dataset being processed so as to determine a circuit layout. For instance, an integrated circuit definition dataset may define the configuration of a reconfigurable processor, such as an FPGA, and the processing of that dataset may configure an IC manufacturing system to generate a reconfigurable processor having that defined configuration (e.g. by loading configuration data to the FPGA).
(314) In some embodiments, an integrated circuit manufacturing definition dataset, when processed in an integrated circuit manufacturing system, may cause an integrated circuit manufacturing system to generate a device as described herein. For example, the configuration of an integrated circuit manufacturing system in the manner described above with respect to
(315) In some examples, an integrated circuit definition dataset could include software which runs on hardware defined at the dataset or in combination with hardware defined at the dataset. In the example shown in
(316) The implementation of concepts set forth in this application in devices, apparatus, modules, and/or systems (as well as in methods implemented herein) may give rise to performance improvements when compared with known implementations. The performance improvements may include one or more of increased computational performance, reduced latency, increased throughput, and/or reduced power consumption. During manufacture of such devices, apparatus, modules, and systems (e.g. in integrated circuits) performance improvements can be traded-off against the physical implementation, thereby improving the method of manufacture. For example, a performance improvement may be traded against layout area, thereby matching the performance of a known implementation but using less silicon. This may be done, for example, by reusing functional blocks in a serialised fashion or sharing functional blocks between elements of the devices, apparatus, modules and/or systems. Conversely, concepts set forth in this application that give rise to improvements in the physical implementation of the devices, apparatus, modules, and systems (such as reduced silicon area) may be traded for improved performance. This may be done, for example, by manufacturing multiple instances of a module within a predefined area budget.
(317) The applicant hereby discloses in isolation each individual feature described herein and any combination of two or more such features, to the extent that such features or combinations are capable of being carried out based on the present specification as a whole in the light of the common general knowledge of a person skilled in the art, irrespective of whether such features or combinations of features solve any problems disclosed herein. In view of the foregoing description it will be evident to a person skilled in the art that various modifications may be made within the scope of the invention.