34
[CS7031] Graphics and Console Hardware and Real-time Rendering 15 th Lecture :: GPU - Rasterisation (one) Dr. Michael Manzke [email protected] Trinity College Dublin Dr. Michael Manzke - CS7031 :: 15 th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 1/34

[CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

  • Upload
    others

  • View
    9

  • Download
    0

Embed Size (px)

Citation preview

Page 1: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

[CS7031] Graphics and Console Hardwareand Real-time Rendering

15th Lecture :: GPU - Rasterisation (one)Dr. Michael Manzke

[email protected]

Trinity College Dublin

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 1/34

Page 2: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Rasterisation orScan Convertion

Outline:

FundamentalsSystem examplesSpecial topics

Suggested reading:

Triangle Scan Conversion Using 2D HomogeneousCoordinates [OG97]Optimal Depth Buffer for Low-cost GraphicHardware [LJ99]Minimum Triangle Seperation for Correct Z-bufferOcclusion [AS06]

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 2/34

Page 3: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Recall that...

Straight lines project to straight lines:

When projection is to a plan (our assumption)Only vertexes need to be transformedThat’s why we’re interested in lines and polygones

Parameterizations(e.g., projected distance) arewarped:

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 3/34

Page 4: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Recall that ...

Ideal screen coordinates are continuous

Implementations always use discrete math, but withsubstantial sub-pixel precisionA pixel is a big thing

Addressable resolution equal to pixels on screenLots of data

Points and lines have no geometric area ...

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 4/34

Page 5: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Terminology

Rasterisation: convertion of primitives to fragments

Primitive: point, line, polygon, glyph, image, ...Fragment: transient data structure, e.g.,

short x, y;

long depth;

short r, g, b, a;

Pixels exist in an array (e.g., framebuffer)

Have implicit < x, y > cooordinates

Fragment are routed to appropriate pixels

This is the "sort" we saw in the previpus lectureThere will be more sorting ...

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 5/34

Page 6: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Two Fundamental Operation

Fragment selection

Identify pixels for which fragment are to begeneratedMust be conservative, efficiency matters< x, y > paratemers are special

Attribute assignment

Assign attribute value to each fragmentE.g., color, depth, ...

Scheduling: the third fundamental operation

Assign fragment to parallel fragment shaders

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 6/34

Page 7: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Fragment Selection

Generate one fragment for each pixel that isintersected by the primitive

Intersect could mean that the primitive’s areaintersects the pixel’s:

Centre point, orSquare region, orFilter-function

Some examples on the following slides:

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 7/34

Page 8: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Point Sampled Fragment Selection

Aliased rasterisation

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 8/34

Page 9: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Box Sampled Fragment Selection

Tiled rasterisation (scaling the primitive doesn’t do this)

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 9/34

Page 10: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Filtered Fragment Selection

Antialiased rasterisation

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 10/34

Page 11: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Fragment Selection (continued)

What if the primitive doesn’t have a geometric area?

Points don’tLines don’t

Two choises

Rule-based approach (e.g., Bresenham line)allow desired propertiies to be maintained, butmay require additional hardware complexity

Assign an screen-scace area (e.g. circle for point,rectangle for line)

can utilize polygon rasterisation algprithm, butmay result in wavy lines, flashing points, etc.

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 11/34

Page 12: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Attribute Assignment

Identify a parameterisation for each attribute

e.g. planar

Sample this parameterisation as required

Which parameterisation?

Lots of possiblities (linear, cuic, . . . )Always define implisitly by vertex values

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 12/34

Page 13: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Attribute Assignment

Properties of vertex-defined parameterisation:

Zero-order continuityIf fully specified by the two vertexes that specifythe edge

Triangle allow planar parameterisationPolygons (4+ edges) are (almost) never planar

Parameterisation may vary with screenorientation

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 13/34

Page 14: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Linear Interpolation

Compute intermediate attribute value

Along a line: A = aA1 + bA2, a + b = 1

On a plan: A = aA1 + bA2 + cA3, a + b + c = 1

Only projected values interpolate linearly in screenspace (straight lines project to straight lines)

a and y are projected (divided by w)Attribute values are not naturally projected

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 14/34

Page 15: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Linear Interpolation

Choice for attribute interpolation in screen space

Interpolate unprojected valuesCheap and easy to do, but gives wrong valuesSometimes OK for color, butNever acceptable for texture coordinates

Do it right

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 15/34

Page 16: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Incorrect Attribute Interpolation

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 16/34

Page 17: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Perspective-correct LinearInterpolation

Only projected values interpolate correctly, so project A

Lineatly interpolate A1

w1

and A2

w2

Also interpolate 1

w1

and 1

w2

These also interpolate linearly in screen space

Divide interpolants at each sample point to recover A

A

w1

w

= A

Division is expensive (more than add or multiply, so)Recover w for the sample point (reciprocate), andMultiply each projected attribute by w

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 17/34

Page 18: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Perspective-correct LinearInterpolation

Barycentric triangle parameterization:

A =

aA1

w1

+bA2

w2

+cA3

w3

a

w1

+b

w2

+c

w3

a + b + c = 1

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 18/34

Page 19: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Example: Gouraud ShadedQuadrilateral

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 19/34

Page 20: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Example: Gouraud ShadedQuadrilateral

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 20/34

Page 21: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

All Polygons are Triangles

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 21/34

Page 22: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Normal-based Quad Decomposition

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 22/34

Page 23: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Point Sampled Triangles

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 23/34

Page 24: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Point Sampled Points and Lines

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 24/34

Page 25: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Outline Problem

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 25/34

Page 26: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Integer DDA Arithmetric

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 26/34

Page 27: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Triangle Rasterisation Examples

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 27/34

Page 28: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Algorithm Properties

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 28/34

Page 29: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Gouraud Shaded (GTX)

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 29/34

Page 30: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Engine per Pixel (Pixel Plane 4)

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 30/34

Page 31: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Engine per Pixel (Pixel Plane 4)

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 31/34

Page 32: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

Pixel Planes 4 Fragment Selection

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 32/34

Page 33: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

References

[OG97] Marc Olano and Trey Greer. Triangle scanconversion using 2d homogeneous coordinates. InHWWS ’97: Proceedings of the ACMSIGGRAPH/EUROGRAPHICS workshop on Graphicshardware, pages 89–95, New York, NY, USA, 1997.ACM.

[LJ99] Eugene Lapidous and Guofang Jiao. Optimaldepth buffer for low-cost graphics hardware. In HWWS’99: Proceedings of the ACMSIGGRAPH/EUROGRAPHICS workshop on Graphicshardware, pages 67–73, New York, NY, USA, 1999.ACM.

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 33/34

Page 34: [CS7031] Graphics and Console Hardware and Real-time …and A2 w2 Also interpolate 1 w1 and 1 w2 These also interpolate linearly in screen space Divide interpolants at each sample

References

[AS06] Kurt Akeley and Jonathan Su. Minimumtriangle separation for correct z-buffer occlusion. In GH’06: Proceedings of the 21st ACMSIGGRAPH/Eurographics symposium on Graphicshardware, pages 27–30, New York, NY, USA, 2006.ACM.

Dr. Michael Manzke - CS7031 :: 15th Lecture :: GPU - Rasterisation (one) :: December 20, 2010 – p. 34/34