Real-Time GPU Rendering of Piecewise Algebraic Surfaces Charles Loop Microsoft Research Jim Blinn Microsoft Research
Introduction Graphics hardware optimized to rasterize triangles, storing colour and depth information in pixel memory Shaders: evolved to support sophisticated appearance models to compute the colour, or shaders of a pixel Problem: level of detail (LOD) management is high 2
Level Of Detail (LOD) Avoid... under sampling or tessellation artefacts when viewed up close over sampling and resource wasting, when viewed from far 3
Motivation Render curved surfaces directly Advantage: No need for LOD management Need to store the (resolution independent) polynomial Need less memory and bus bandwidth True surfaced normals can be used for lighting at each pixel(better than interpolated phong normals) 4
Curved primitives Algebraic surfaces defined by trivariate Bézier tetrahedra Algebraic surface: is an implicit surface defined as the solution of a polynomial equation Bézier tetrahedron degree 3 5
Rendering of Curved primitives render portion of surface inside a tetrahedron Restriction to tetrahedron Combined with simple continuity conditions between adjacent tetrahedra enables modelling of piecewise smooth surfaces 6
Problems Analytic techniques for finding the zeros of polynomials Limit us to degree 4 surface No robust root finding with bounded iterations were available on a GPU (2005) 7
1.1 Previous Work Bézier tetrahedron as a modelling primitive GPU algorithm for rendering implicit surface data[hardwiger et al. 2005] Concerned with surfaces over voxel grid, not surfaces described by polynomials 8
1.2 Algorithm Overview Render an algebraic surface corresponding to a Bézier tetrahedron Encoding coefficient data as vertex attributes... and rasterizing the projected triangle faces Pixel shader to perform operations for each pixel Compute coefficients of a univariate polynomial in z Find real roots to determine if the surface is visible Determine if the visible surface is inside tetrahedron Calculate the surface normal Compute shading 9
2. Mathematics of Algebraic Surfaces Bézier Tetrahedron of degree d is defined as: b d i j k l s j t k u l =0 i jkl=d Scalar valued weights Barycentric coordinates rstu=1 i j k l ri World space domain tetrahedron T =[v 0 v 1 v 2 v 3 ] T b i j k l Each row of T corresponds to a vertex 10
Positions and Weights Surface lies inside the tetrahedron if (r,s,t,u) satisfy equation (1) and all values are positive b d i j k l s j t k u l =0 (1) i jk l=d i j k l ri b i j k l Each weight is associated with position i v 0 j v 1 k v 2 l v 3 /d 11
Evaluating Bézier polynomial Several possibilities: 1. Using decastlejau's algorithm Requires arrays with tetrahedral indexing 2. Evaluating the blossom using a symmetric tensor Tensor: higher dimensional analogue of matrix Number of indices is referred to as the rank of the tensor Evaluate blossoms in terms of dot products that are native operations on a GPU 12
Example We prefer tensor notation as it maps directly to dot product implementation Example: d=2, B is a 4x4 matrix b b2000 1100 b 1010 b 1001 Equation (2) as r r B T b =0 1100 b 0200 b 0110 b 0101 b 1010 b 0110 b 0020 b 0011 b 1001 b 0101 b 0011 b 0002 Complexity: i jk l=d b i j k l d l i j k ri s j t k u l =0 Od 3 (1) r α 1 r α d Bα1 α d =0 O 4 d (2) 13
3. Per Frame Processing Transform the Bézier tetrahedron T and weights B to screen space We use 4x4 matrix M formed as product of world, view and perspective matrices This takes the world view into screen space Almost all operations can be done on Vertex Shader 14
3.1 Transformation to Screen Space T tetrahedron vertices B is a symmetric rank d tensor containing Bézier weights (for d=2 is a 4x4 Matrix) Screen space is a 4D projective space: b2000 b 1100 b 1010 b 1001 b 1100 b 0200 b 0110 b 0101 b 1010 b 0110 b 0020 b 0011 b 1001 b 0101 b 0011 b 0002 Pixel coordinates: Depth z correspond to w=1 [ x, y] [ 1,1] [ 1,1] Tetrahedron vertices in screen space: v 1..4 =[ x y z 1] 15
Transformation to screen space barycentric coordinates of a point in space r=[r s t u] x=r T (x is a point in world space) Composite transform from barycentric coordinates in screen space: x=r T M - back: r= x M 1 T 1 = x W Weights to screen space: B=W B Only the unique elements of B need to be computed: x 1... x d B 1... d =0 (3) 16
Transformation in screen space (2) Advantage of transformation into screen space: All viewing rays become parallel to the z axis Leads to more compact formulae for the coefficients of ray/surface intersection polynomials. Fewer interpolated vertex attributes are needed Alternative approach: Transform the viewing rays into barycentric coordinates of screen space (for every tetrahedron) Solve a univariate equation in this space Advantage: the weights of tensor B need not to be transformed (no precision loss) 17
3.2 Rendering Primitives 1. Approach rendering tetrahedra: Render front facing triangular faces Vertex Shader: to transform data, as outlined in the previous section Disadvantages: Computation must be done per tetrahedron Determining visibility within a tetrahedron Have to consider all 4 bounding planes(the faces) on input to a pixel shader creates a complicated interval that z values must be tested against 18
3.2 Rendering Primitives (2) Instead, perform vertex processing on the CPU submit post transformed triangles to the GPU Not tested on current Graphics Hardware (2006) Anticipate this will be the better approach on next generation GPUs that will support per triangle shader calls Can be ported to GPU 19
Rendering a tetrahedron to render the non overlapping triangles that cover the convex hull in screen space Projected tetrahedron T Count the number of negative z values in a) if 1 or 3 occurs (draw 3 triangles) b) if 2 Store vertex attributes: z min and z min Provides the z extent of the tetrahedron at each pixel (draw 4 triangles) T 1 20
4. Per Pixel Processing For a given pixel [x,y]: we must determine if a real z exists so that x=[ x y z 1] satisfies equation: x x B T =0 At each pixel Compute the Bézier form of this univariate polynomial restricted to the interval [ z p, z q ] z p and z q are interpolated values of z min and z max Representing the z extent of the interior of the tetrahedron at the current pixel. Use Bézier form to get optimal numerical conditioning: allow a pixel shader an early exist test if all coefficients have the same sign 21
Compute Coefficients Find a univariate polynomial in Bézier form d i=0 d i 1 vd i v i a i =0 (4) corresponds to (3) with x and y held constant so that v [0,1] corresponds to z [ z p, z q ] (3) Each Bézier coefficient will depend on pixel coordinates x and y. a i x 1... x d B 1... d =0 22
Compute Coefficients (2) To find the coefficients, we define a i p=[ x y z p 1] q=[ x y z q 1] point in screen space (5) x=1 v pvq Plug this into Equation (3) the coefficients can be written (for d=2): a i a 0 = p p B a 1 =q p B (6) a 2 =q q B 23
4.1 Interpolating Coefficients At each pixel evaluate Equations (6) given p and q derived from pixel. Problem: pass the tensor B to the pixel shader. This data will be different for every tetrahedron (every 3 to 4 triangles) store a variant of the tensor B as attributes on the vertices of triangles The GPU will interpolate vertex attributes when rasterizing a triangle. Vertex attributes are interpolated with any projective foreshortening induced by the viewing transformation 24
Symmetric tensor Each of the coefficients a 0,... a d 1 (all but a d } in equation (6) have a common factor of p d B 1... d p B (7) Is a symmetric tensor of rank (d-1) Suppose that p=rw 0 sw 1 tw 2 where each w j =[ x j y j z min j 1] are the vertices of a screen space triangle. It follows by linearity of dot products that p B=r w 0 Bsw 1 Bt w 2 B Need only to evaluate w j B at vertices of a triangle 25
Early exit on zeros Once we have determined the Bézier coefficients of a i, we see if any zeroes that lie in the range [0,1] a i If all of the have the same sign then, by the convex hull property, there can be no roots in [0,1] and the pixel shader can exit early. Torus model shaded: Blue: pixel culled by Bézier coefficient sign test Red: Positive quartic discrimanant Green: negative quartic discriminant 26
4.2 Computing Surface Normals If no root v [0,1] is found then the current pixel shader instance is terminated. Otherwise we take the smallest root v and shade the pixel by first computing the normal to a point on the surface x=1 v pvq By collapsing the tensor B down to the tangent plane using 1 1 = x 2 B 27
Computing Surface Normals By making the substitution x= pv z we can write the tangent plane (d = 2) as 1 1 = pv z 2 B 1 (9) with = z q z p and smallest root v as a polynomial in v. 28
Save Memory Send Data from CPU to GPU b2000 t 10 t 11 t 12 b 1100 b 0200 t 13 z min t 1010 b 0110 b 0020 z max b 1001 b 0101 b 0011 b 0002 h=[t 10 t 11 t 12 t 13 ] p=[ x y z min 1] q=[ x y z max 1] = z max z min 29
5. Results Described by one equation, but rendered piecewise Assembler Instructions for various shader tasks Degree Coefficients Roots Shading Total 2 15 65 37 117 3 37 168 37 242 4 66 193 37 296 30
GeForce 7800 GTX (640x480) Fps for single Tetrahedron: Quadratic:1200 fps Quartic: 500 fps Animated blobs(degree 4): 300 fps Depth complexity: 75 fps 31
More Objects 32
Problems on intersections Root finding is stable where only one root exists Sometimes numerical noise will cause this to be reported as a complex conjugate pair and be rejected in the real-root-finding process. This can occur: near silhouette edges near self intersections 33
Hardware Based Bézier Patch Renderer by Gerd Reis Quadric Bézier structures: Bi-cubic Bézier structures combined with standard graphics object: 34
Thank you for listening Any questions? 35
References Real-Time GPU Rendering of Piecewise Algrebraic Surfaces [Loop/Blinn 2006] Hardware Based Bezier Patch Renderer [Gerd Reis 2006] Free Form Modeling with A-Patches [Chandrajit L. Bajaj] Rational Betier solids [Martin Samuelcik] http://de.wikipedia.org/wiki/bild:voxelgitter.png http://de.wikipedia.org/wiki/bild:utah_teapot.png http://www.kidsrcrafty.com/images/pe03038_.gif http://en.wikipedia.org/wiki/tensor 36
Verarbeitung von Dreiecken Speichern der Farben und der Tiefe im Pixelspeicher shader: Verarbeitung von komplizierten Modellen für die Berechnung von Farben, Schatten oder Lichteffekten Problem: LOD
Under sampling = Unterabtastung tesselation = Artefakte bei naher Ansicht Oversampling and Verschwendung von Ressorsen, wenn vom weiten gesehen
Direktes Rändern von Objekten Vorteile - Kein LOD - Speichern von Funktionen(Auflösungsunabhängig) - weniger Speicher und Busbandbreite - Für die Beleuchtung können echte Normalen benutzt werden
Agebraische Struktur in einem Bezier Tetraeder - gleischschenklinge Dreiecke - 4 Flächen - algebraische Struktur definiert durch eine polynomiale Gleichung
Rendern der Struktur innerhalb eines Tetraeders Wir beschränken uns auf Tetraeder kombiniert durch einfache Fortsetzungsbedingungen von adjazenten Tetraedern ermöglicht das Rändern von Stückweise glatt übergehenden Strukturen Erstellt aus einer Funktion und in mehrere Tetraeder abgebildet
Analytische Methoden für die Nullstellensuche - Einschränkung auf Grad 4 Strukturen - Die möglichkeiten von Grad 4 Funktionen sind riesig - Keine höhergradigen Strukturen, da eine robuste Nullstellensuche auf der GPU mit einschränkende Iterationen nicht existiert
Modelierung Primitive benutzt GPU Algorithmen für das Rendern von impliziten Strukturen über Voxel Grids, aber nicht von Polynomialfunktionen
Dekodieren der Koeffizienten als Attribute von Eckpunkten - rasterizieren der projezierten Dreiecke Pixel Shader -Berechnungder Koeffizieten einer univariaten Gleichung in z - Finden der Nullstellen für die Berechnung der Sichtbarkeit - Bestimmen, ob das Objekt im Tetraeder liegt - Berechnen der Normalen - Erstellung der Beleuchtung
Gleichung definiert den Tetraeder Wenn die Gleichung erfüllt wird und alle Koordinaten(r,s,t,u) positiv sind, dann liegt die Fläche innerhalb des Tetraeder T Ecken der Tetraeder
Gleichung erfüllt und alle Werte(r,s,t,u) positiv Auf diese Weise ergeben sich die Verteilungen der Gewichte unter den Koordinaten
Evaluierung 1. DeCastejau's algorithm 2. Evaluierung durch symmetrische Tensoren - Tensoren sind höhergradige Analog einer Matrix - Anzahl der Indizes abhängig vom Grad - Evaluierung durch Punkt Multiplikation(von GPU unterstützt)
Bevorzugen Tensoren, weil sie auf Punktmultiplikationen basieren Tensi ist ein generelle LineareMenge or ein geometrische Gebilde dass als multidimensionales Array zu einer gegeben Basis definiert wird. 3^3 = 27 4^3 = 64 4^3 = 64 4^4 = 256
T = Eckpunkte in Baryzentrischen Koordinaten B = Gewichte des Tetraeder als Tensor M = Transformationsmatrix Als Produkt der Welt, Ansicht und Perspektive der Matrizen Operationen sind in der GPU im Vertex Shader durchführbar
Baryzentrische Koordinaten x = r * T = Vektor x Matrix Transformation von baryzentrischen in den Screen Space
Vorteile - Sichtstrahlen verlaufen parallel zur z Achse - Dadurch kompaktere Formeln für die Koeffizienten der Punkte - Es werden weniger interpolierte Eckpunkte benötigt - Alternativer Ansatz - Transformation der Ansicht in die Baryzentrischen Koordinaten aus dem Screen Space - Lösen einer univariaten Gleichung - Vorteil: genauere Gewichte, da keine Transformation stattgefunden hat ( 32 Bit Genauigkeit bei heutiger Hardware)
1. Ansatz für das Rendern von Tetraedern: - Rändern aller vier Dreiecke für die verschiedenen Sichten - Vertex Shader für die Transformation der Daten Nachteil: - Berechnung muss für jeden Tetraeder durchgeführt werden - Benötigen die Ansicht innerhalb des Tetraeders - müssen alle 4 Flächen des Tetraeders berechnen - Programmierung des Pixel Shader wird kompliziert, da man die Ansicht passend zu allen vier Flächen des Tetraeders berechnen muss
Alternativer Ansatz: - Berechnung der Eckpunte auf der CPU - Übergabe der Dreiecke an die GPU für die weitere Transformation Wird von der heutigen Hardware nicht unterstützt - Mit der Hoffnung, dass es in der zukünftigen Hardware Aufrufe pro Dreieck unterstützt werden und damit eine Portierung zurück auf die GPU erfolgen kann
Wir rändern sich nicht überschneidende Dreiecke, die die Konvexe Hülle im Screen Space bilden - T~ - T~ ^-1 3 oder 4 negative z Werte - Speichern der z_min und z_max Werte für später
4. Per Pixel Processing For a given pixel [x,y]: we must determine if a real z exists so that x=[ x y z 1] satisfies equation: x x B T =0 At each pixel Compute the Bézier form of this univariate polynomial restricted to the interval [ z p, z q ] z p and z q are interpolated values of z min and z max Representing the z extent of the interior of the tetrahedron at the current pixel. Use Bézier form to get optimal numerical conditioning: allow a pixel shader an early exist test if all coefficients have the same sign 21 Für ein gegegebenes Pixel müssen wir heraus finden, ob ein z in dem Tetraeder existiert, dass auf der Oberfläche der Struktur liegt Wir berechnen eine univariate Gleichung in dem Interval z_p und z_q, da wir wissen, dass nur in diesem Bereich ein Wert existieren kann z_p und z_q sind z_max und z_min in dem Tetraeder Durch die Bezier Form können wir effektiv entscheiden, ob ein Wert existiert oder nicht
Compute Coefficients Find a univariate polynomial in Bézier form d d i=0 i 1 vd i v i a i =0 (4) corresponds to (3) with x and y held constant so that v [0,1] corresponds to z [ z p, z q ] x 1... x d B 1 (3)... d =0 Each Bézier coefficient will depend on pixel coordinates x and y. a i 22 Um die Berechnung durchzuführen muss die folgende Gleichung gelöst werden diese Entspircht der Gleichung x~... x~ B~ = 0 für Tensorrechnungen v muss in dem Bereich [0,1] liegen z liegt in dem Bereich z_p und z_q was z_min und z_max entspricht Jeder Bezier Koeffinzient a_i wird abhängig von dem jeweiligen Pixel x und y, die für die Berechnung konstant gehalten werden
Compute Coefficients (2) To find the coefficients, we define a i p=[ x y z p 1] q=[ x y z q 1] point in screen space (5) x=1 v pvq Plug this into Equation (3) the coefficients can be written (for d=2): a i a 0 = p p B a 1 =q p B (6) a 2 =q q B 23 Um die Gleichung zu lösen, definieren wir p und q z_p = z_min und z_q = z_max damit lässt sich der Punkt auf dem Screenspace berechnen Um die Koeffizienten effektiv auf der GPU im Pixel Shader zu berechnen, benutzen wir wieder die Tensor Algebra und kriegen damit für Grad 2 die folgenden Gleichungen Gleichungungen a_0 und a_2 werden auf den nächsten Folien benötigt
4.1 Interpolating Coefficients At each pixel evaluate Equations (6) given p and q derived from pixel. Problem: pass the tensor B to the pixel shader. This data will be different for every tetrahedron (every 3 to 4 triangles) store a variant of the tensor B as attributes on the vertices of triangles The GPU will interpolate vertex attributes when rasterizing a triangle. Vertex attributes are interpolated with any projective foreshortening induced by the viewing transformation 24 Wir müssen die Gleichungen evaluieren für die gegebenen p und q erstellt für jedes Pixel Problem: Tenso B~ dem Pixel Shader übergeben - dieser ändert sich alle 3 bis 4 Dreiecke - Lösung: speichern wir eine Variante des Tensors B~ auf den Eckpunkten der Dreiecke auf denen wir mit dem Pixelshader arbeiten Die GPU interpoliert über die Eckpunkte und rasterisiert die Dreiecke - Die Eckpunkte werden dazu noch abhängig von der Ansicht interpoliert und das spart wieder Berechnungen
Symmetric tensor Each of the coefficients a 0,... a d 1 (all but a d } in equation (6) have a common factor of p d B 1... d p B (7) Is a symmetric tensor of rank (d-1) Suppose that p=rw 0 sw 1 tw 2 where each w j =[ x j y j z min j 1] are the vertices of a screen space triangle. It follows by linearity of dot products that p B=r w 0 Bsw 1 Bt w 2 B Need only to evaluate w j B at vertices of a triangle 25 Alle Koeffizienten von a_0 bis a_d-1 mit der Ausnahme von a_d haben einen gemeinsamen Faktor Dadurch verkleinern wir den Tensor schon mal Vorraus um einen Grad für alle Berechnungen. 1. Sparen Platz bei der Übergabe eines Tensor mit dem Grad d-1 2. GPU spart für die weitere Berechnung für alle anderen a_i p stellt die Eckpunkte des Dreiecks in dem Screen Space dar. Durch die Linearität der Produkte ergibt sich die folgende Gleichung Dadurch müssen wir nur an den Eckpunkten die Werte w_i * B~ evaluieren und nicht jedes Pixel
Early exit on zeros Once we have determined the Bézier coefficients of a i, we see if any zeroes that lie in the range [0,1] If all of the a i have the same sign then, by the convex hull property, there can be no roots in [0,1] and the pixel shader can exit early. Torus model shaded: Blue: pixel culled by Bézier coefficient sign test Red: Positive quartic discrimanant Green: negative quartic discriminant 26 Nachdem wir die Koeffizienten der Gleichung erhalten haben, müssen wir die Nullstellen im Bereich [0,1] berechnen Wenn alle a_i Werte das selbe Vorzeichen haben, dann kann nach der Eigenschaft der konvexen Hülle keine Nullpunkte geben und der Pixel Shader kann aufhören Blau: Durch den Vorzeichen Test raus gefallen Red: Strukturen des Torus Grün: Negative Diskriminanten
4.2 Computing Surface Normals If no root v [0,1] is found then the current pixel shader instance is terminated. Otherwise we take the smallest root v and shade the pixel by first computing the normal to a point on the surface x=1 v pvq By collapsing the tensor B down to the tangent plane using 1 1 = x 2 B 27 Wenn keine Nullstellen gefunden wurden, dann terminiert der Pixelshader Ansonsten wird der kleinste Nullpunkt genommen un die Normale auf diesem Punkt berechnet durch herunterbrechen des Tensor B~ auf die Tangente
Computing Surface Normals By making the substitution x= pv z we can write the tangent plane (d = 2) as with 1 1 = pv z 2 B 1 = z q z p and smallest root v (9) as a polynomial in v. 28 Durch die Substitution x ~ = p + (v delate) z können wir die Gleichung für den Grad 2 auch auf die folgende Art und Weise schreiben: 1_beta1 auf dem Interval delta = Differenz zwischen dem minimalen und maximalen z-wert auf der kleinsten Nullstelle als Polynomial auf v delta
Save Memory Send Data from CPU to GPU b2000 t 10 t 11 t 12 b 1100 b 0200 t 13 z min t 1010 b 0110 b 0020 z max b 1001 b 0101 b 0011 b 0002 h=[t 10 t 11 t 12 t 13 ] p=[ x y z min 1] q=[ x y z max 1] = z max z min 29
5. Results Described by one equation, but rendered piecewise Assembler Instructions for various shader tasks Degree Coefficients Roots Shading Total 2 15 65 37 117 3 37 168 37 242 4 66 193 37 296 30 Anzahl Assembler Befehle, die ausgeführt werden müssen Degree = Grad des Tetraeders Coefficients = Anzahl univariater Koeffizienten für die Berechnung eines einzelnen Pixels Roots = Nullstellensuche in einer univariaten Gleichung Shading = Beleuchtungseffekte berechnen Total = Anzahl der Assembler Instruktionen, die für den jeweiligen Grad auf dem Shader ausgeführt werden müssen
GeForce 7800 GTX (640x480) Fps for single Tetrahedron: Quadratic:1200 fps Quartic: 500 fps Animated blobs(degree 4): 300 fps Depth complexity: 75 fps 31 Renderpipes = 24 Vertexpipes = 8 Texturen pro Pass = 24 Geschwindigkeit auf einer GPU is relativ zu der Anzahl der Pixel shader Instanzen, die parallel ausgeführt werden können pro Bild. Das ist Abhängig von der Auflösung des Bildes und der Anzahl, Größe und Grad des Tetraeders
More Objects 32 @ Symbol wurde mit einer speziellen Technik durch mehrere Funktionen dargestellt Quadratische Funktion Kubische Funktion, die einen Torus darstellt
Problems on intersections Root finding is stable where only one root exists Sometimes numerical noise will cause this to be reported as a complex conjugate pair and be rejected in the real-root-finding process. This can occur: near silhouette edges near self intersections 33 Stabile Nullstellensuche ist nur an den Stellen möglich, die nur eine Nullstelle besitzen. Teilweise durch nummerische Fehler die dann durch komplexe konjugierte Paare auftauchen und zum Abbruch in der Nullstellensuche führen Diese können auftreten an: - Nahe der Silhouette einer Kante(hier sind keine Artefakte durch fehlende Pixel zu sehen - Nahe der Stellen, an der sich die Funktion selbst schneidet (hier entsteht ein sichtbares Loch im Objekt)
Hardware Based Bézier Patch Renderer by Gerd Reis Quadric Bézier structures: Bi-cubic Bézier structures combined with standard graphics object: 34 Gerd Reis hat sich ebenfalls mit dem Thema beschäftigt Hat sich nicht auf Tetraeder beschränkt, sondern behandelt Bezier Patches im Allgemeinen Allerdings hat er sich auch mit der Kombination von Bezier Patches mit graphischen Standardobjekten beschäftigt