clipping and scan conversionmisha/fall20/13.pdfcohen-sutherland line clipping β’ associate a 4-bit...
TRANSCRIPT
![Page 1: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/1.jpg)
Clipping and Scan Conversion
Michael Kazhdan
(601.357/456)
HB Ch. 3.2, 3.11, 6.7, 6.8
FvDFH Ch. 3.2, 3.6, 3.12, 3.14
![Page 2: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/2.jpg)
Announcementsβ’ Assignment 2 posted
Start yesterday!!!
![Page 3: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/3.jpg)
Lighting
ViewingTransformation
3D Rendering Pipeline (for direct illumination)
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Image
ViewportTransformation
ScanConversion
2D Image Coordinates
3D Modeling Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
2D Screen Coordinates
3D Camera Coordinates
2D Image Coordinates
3D Model
2D Image
![Page 4: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/4.jpg)
Transformations
ModelingTransformation
ViewingTransformation
2D Image Coordinates
ProjectionTransformation
Window-to-ViewportTransformation
3D Object Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
(π₯π₯,π¦π¦, π§π§)
(π₯π₯β²,π¦π¦β²)
3D WorldCoordinates
3D ObjectCoordinates
![Page 5: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/5.jpg)
Transformations
ModelingTransformation
ViewingTransformation
2D Image Coordinates
ProjectionTransformation
Window-to-ViewportTransformation
3D Object Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
3D WorldCoordinates
Transform = ππππ = local to world transform
(π₯π₯,π¦π¦, π§π§)
(π₯π₯β²,π¦π¦β²)
![Page 6: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/6.jpg)
Transformations
ModelingTransformation
ViewingTransformation
2D Image Coordinates
ProjectionTransformation
Window-to-ViewportTransformation
3D Object Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
3D WorldCoordinates
3D CameraCoordinates
(π₯π₯,π¦π¦, π§π§)
(π₯π₯β²,π¦π¦β²)
Transform = ππππ = local to world transform
![Page 7: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/7.jpg)
Transformations
ModelingTransformation
ViewingTransformation
2D Image Coordinates
ProjectionTransformation
Window-to-ViewportTransformation
3D Object Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
Camera Right
Camera Up
x
y
zCamera Back
πππΆπΆβππ is the camera to world transformπ π π₯π₯ πππ₯π₯ π΅π΅π₯π₯ πΈπΈπ₯π₯π π π¦π¦ πππ¦π¦ π΅π΅π¦π¦ πΈπΈπ¦π¦π π π§π§ πππ§π§ π΅π΅π§π§ πΈπΈπ§π§0 0 0 1
(π₯π₯,π¦π¦, π§π§)
(π₯π₯β²,π¦π¦β²)
Transform = πππΆπΆβππβ1 ππ
![Page 8: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/8.jpg)
Transformations
ModelingTransformation
ViewingTransformation
2D Image Coordinates
ProjectionTransformation
Window-to-ViewportTransformation
3D Object Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
Transform = πππππΆπΆβππβ1 ππππ = projection transform
(π₯π₯,π¦π¦, π§π§)
(π₯π₯β²,π¦π¦β²)
ππππ =
1 0 πΏπΏ cosππ 00 1 πΏπΏ sinππ 00 0 0 00 0 0 1
ππππ =
1 0 0 00 1 0 00 0 1 00 0 1 0
![Page 9: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/9.jpg)
Transformations
ModelingTransformation
ViewingTransformation
2D Image Coordinates
ProjectionTransformation
Window-to-ViewportTransformation
3D Object Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
π£π£π₯π₯1 π£π£π₯π₯2π£π£π¦π¦1
π£π£π¦π¦2
π€π€π₯π₯1 π€π€π₯π₯2π€π€π¦π¦1
π€π€π¦π¦2Window Viewport
Screen Coordinates Image Coordinates
(π€π€π₯π₯,π€π€π¦π¦) (π£π£π₯π₯ , π£π£π¦π¦)
(π₯π₯,π¦π¦, π§π§)
(π₯π₯β²,π¦π¦β²)
ππ = viewport transform
ππ =1 0 π£π£π₯π₯1
0 1 π£π£π₯π₯20 0 1
π£π£π₯π₯2 β π£π£π₯π₯1
π€π€π₯π₯2 β π€π€π₯π₯10 0
0π£π£π¦π¦2 β π£π£π¦π¦1
π€π€π¦π¦2 β π€π€π¦π¦10
0 0 1
1 0 βπ€π€π₯π₯1
0 1 βπ€π€π¦π¦1
0 0 1
Transform = πππππππΆπΆβππβ1 ππ
![Page 10: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/10.jpg)
3D Rendering Pipeline (for direct illumination)
3D Model
ModelingTransformation
ViewingTransformation
2D Image Coordinates
ProjectionTransformation
Window-to-ViewportTransformation
3D Object Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
(π₯π₯,π¦π¦, π§π§)
(π₯π₯β²,π¦π¦β²) 2D Screen
![Page 11: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/11.jpg)
Transformationsππ
πΏπΏ1
πΏπΏ2
ππ
Viewer
πΌπΌ = πΌπΌπΈπΈ + οΏ½πΏπΏ
πΎπΎπ΄π΄ β πΌπΌπΏπΏπ΄π΄ + πΎπΎπ·π· β ππ, πΏπΏ + πΎπΎππ β ππ,π π ππ β πΌπΌπΏπΏ
3D Model2D Screen
Lighting
ViewingTransformation
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Image
ViewportTransformation
ScanConversion
![Page 12: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/12.jpg)
Lighting
ViewingTransformation
3D Rendering Pipeline (for direct illumination)
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Image
ViewportTransformation
ScanConversion
2D Image Coordinates
3D Modeling Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
2D Screen Coordinates
3D Camera Coordinates
2D Image Coordinates
![Page 13: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/13.jpg)
Clippingβ’ Avoid drawing parts of primitives outside window
Window defines part of scene being viewed Must draw geometric primitives only inside window
Screen Coordinates
Window
![Page 14: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/14.jpg)
Clippingβ’ Avoid drawing parts of primitives outside window
Points Line Segments Polygons
Screen Coordinates
Window
![Page 15: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/15.jpg)
β’ Is point (π₯π₯,π¦π¦) inside the clip window?
Point Clipping
Windowπ€π€π₯π₯1 π€π€π₯π₯2
π€π€π¦π¦2
π€π€π¦π¦1
(π₯π₯,π¦π¦)
![Page 16: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/16.jpg)
β’ Is point (π₯π₯,π¦π¦) inside the clip window?
Point Clipping
Window
(π₯π₯,π¦π¦)
inside = (x >= wx1) &&(x < wx2) &&(y >= wy1) &&(y < wy2);
π€π€π₯π₯1 π€π€π₯π₯2
π€π€π¦π¦2
π€π€π¦π¦1
![Page 17: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/17.jpg)
Clippingβ’ Avoid drawing parts of primitives outside window
Points Line Segments Polygons
Screen Coordinates
Window
![Page 18: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/18.jpg)
Line Segment Clippingβ’ Find the part of a line inside the clip window
Do this as efficiently as possible by identifying the easiest cases first
ππ1
ππ10
ππ9
ππ8
ππ7
ππ4ππ3
ππ6
ππ5
ππ2
![Page 19: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/19.jpg)
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππππππππππππππππ to each vertex
ππ0 = 1 if the vertex is left of the window ππ1 = 1 if the vertex is right of the window ππ2 = 1 if the vertex is below the window ππ3 = 1 if the vertex is above the window
ππ0 ππ1
ππ2
ππ3
0000 01001000
0001 01011001
0010 01101010
![Page 20: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/20.jpg)
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010
ππ1
ππ10
ππ9
ππ8
ππ7
ππ6
ππ5
ππ2
ππ4ππ3
ππ0 ππ1
ππ2
ππ3
![Page 21: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/21.jpg)
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010
ππ10
ππ9
ππ8
ππ7
ππ6
ππ5
ππ4ππ3
ππ1
ππ2
ππ0 ππ1
ππ2
ππ3
![Page 22: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/22.jpg)
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010
ππ10
ππ9
ππ8
ππ7
ππ6
ππ5
ππ4ππ3
ππ0 ππ1
ππ2
ππ3
![Page 23: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/23.jpg)
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010
ππ10
ππ9
ππ8
ππ7
ππ4ππ3
ππ6
ππ5
ππ0 ππ1
ππ2
ππ3
![Page 24: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/24.jpg)
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010
ππ10
ππ9
ππ8
ππ7
ππ4ππ3
ππ6
ππ5
ππ0 ππ1
ππ2
ππ3
![Page 25: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/25.jpg)
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010ππ5β²
ππ10
ππ9
ππ8
ππ7
ππ4ππ3
ππ6
ππ0 ππ1
ππ2
ππ3
![Page 26: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/26.jpg)
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010ππ5β²
ππ10
ππ9
ππ4ππ3
ππ6
ππ8
ππ7
ππ0 ππ1
ππ2
ππ3
![Page 27: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/27.jpg)
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010ππ5β²
ππ10
ππ9
ππ3
ππ6
ππ8
ππ7
ππ4
ππ0 ππ1
ππ2
ππ3
![Page 28: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/28.jpg)
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010
ππ7β²
ππ5β²
ππ10
ππ9
ππ3
ππ6
ππ8ππ4
ππ0 ππ1
ππ2
ππ3
![Page 29: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/29.jpg)
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010
ππ7β²
ππ5β²
ππ10
ππ9
ππ3
ππ6
ππ8ππ4
ππ0 ππ1
ππ2
ππ3
![Page 30: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/30.jpg)
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010
ππ8β²
ππ7β²
ππ5β²
ππ10
ππ9
ππ3
ππ6
ππ4
ππ0 ππ1
ππ2
ππ3
![Page 31: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/31.jpg)
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010
ππ8β²
ππ7β²
ππ5β²
ππ3
ππ6
ππ4
ππ10
ππ9
![Page 32: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/32.jpg)
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010
ππ8β²
ππ7β²
ππ5β²
ππ3
ππ6
ππ4
ππ10
ππ9
![Page 33: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/33.jpg)
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010ππ9β²
ππ8β²
ππ7β²
ππ5β²
ππ3
ππ6
ππ4
ππ10
ππ0 ππ1
ππ2
ππ3
![Page 34: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/34.jpg)
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010
ππ8β²
ππ7β²
ππ5β²
ππ3
ππ6
ππ4
ππ0 ππ1
ππ2
ππ3
![Page 35: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/35.jpg)
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes isnot 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010
ππ8β²
ππ7β²
ππ5β²
ππ3
ππ6
ππ4
ππ0 ππ1
ππ2
ππ3
How many bits would you need in 3D?
![Page 36: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/36.jpg)
Clippingβ’ Avoid drawing parts of primitives outside window
Points Line Segments Polygons
Screen Coordinates
Window
![Page 37: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/37.jpg)
Polygon Clippingβ’ Find the part of a polygon inside the clip window
Before Clipping
![Page 38: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/38.jpg)
Sutherland-Hodgeman Clippingβ’ Clip to each window boundary, one at a time
![Page 39: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/39.jpg)
Sutherland-Hodgeman Clippingβ’ Clip to each window boundary, one at a time
![Page 40: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/40.jpg)
Sutherland-Hodgeman Clippingβ’ Clip to each window boundary, one at a time
![Page 41: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/41.jpg)
Sutherland-Hodgeman Clippingβ’ Clip to each window boundary, one at a time
![Page 42: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/42.jpg)
Sutherland-Hodgeman Clippingβ’ Clip to each window boundary, one at a time
![Page 43: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/43.jpg)
Sutherland-Hodgeman Clippingβ’ How do we clip a convex polygon with respect to
a line?
OutsideInside
WindowBoundary
ππ1ππ2
ππ5
ππ4
ππ3
![Page 44: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/44.jpg)
Sutherland-Hodgeman Clippingβ’ Do inside test for each point in sequence,
Insert new points when cross window boundary, Remove points outside window boundary
OutsideInside
WindowBoundary
ππ1ππ2
ππ5
ππ4
ππ3
![Page 45: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/45.jpg)
Sutherland-Hodgeman Clippingβ’ Do inside test for each point in sequence,
Insert new points when cross window boundary, Remove points outside window boundary
OutsideInside
WindowBoundary
ππ1ππ2
ππ5
ππ4
ππ3
![Page 46: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/46.jpg)
Sutherland-Hodgeman Clippingβ’ Do inside test for each point in sequence,
Insert new points when cross window boundary, Remove points outside window boundary
OutsideInside
WindowBoundary
ππ1ππ2
ππ5
ππ4
ππ3
![Page 47: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/47.jpg)
Sutherland-Hodgeman Clippingβ’ Do inside test for each point in sequence,
Insert new points when cross window boundary, Remove points outside window boundary
OutsideInside
WindowBoundary
ππ1ππ2
ππ5
ππ4
ππ3
![Page 48: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/48.jpg)
Sutherland-Hodgeman Clippingβ’ Do inside test for each point in sequence,
Insert new points when cross window boundary, Remove points outside window boundary
OutsideInside
WindowBoundary πππ
ππ1ππ2
ππ5
ππ4
ππ3
![Page 49: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/49.jpg)
Sutherland-Hodgeman Clippingβ’ Do inside test for each point in sequence,
Insert new points when cross window boundary, Remove points outside window boundary
OutsideInside
WindowBoundary πππ
ππ1ππ2
ππ5
ππ4
ππ3
![Page 50: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/50.jpg)
Sutherland-Hodgeman Clippingβ’ Do inside test for each point in sequence,
Insert new points when cross window boundary, Remove points outside window boundary
OutsideInside
WindowBoundary πππ
ππ1ππ2
ππ5
ππ4
ππ3
![Page 51: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/51.jpg)
Sutherland-Hodgeman Clippingβ’ Do inside test for each point in sequence,
Insert new points when cross window boundary, Remove points outside window boundary
OutsideInside
WindowBoundary πππππππ
ππ1ππ2
ππ5
ππ4
ππ3
![Page 52: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/52.jpg)
Sutherland-Hodgeman Clippingβ’ Do inside test for each point in sequence,
Insert new points when cross window boundary, Remove points outside window boundary
OutsideInside
WindowBoundary πππππππ
ππ1ππ2
![Page 53: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/53.jpg)
Sutherland-Hodgeman Clippingβ’ Do inside test for each point in sequence,
Insert new points when cross window boundary, Remove points outside window boundary
OutsideInside
WindowBoundary πππππππ
ππ1ππ2
When polygons are clipped, per-vertex properties (e.g. lighting) is interpolated to the new vertices.
![Page 54: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/54.jpg)
Sutherland-Hodgeman Clippingβ’ Do inside test for each point in sequence,
Insert new points when cross window boundary, Remove points outside window boundary
OutsideInside
WindowBoundary
What happens if the polygon is not convex?
![Page 55: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/55.jpg)
Lighting
ViewingTransformation
3D Rendering Pipeline (for direct illumination)
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Image
ViewportTransformation
ScanConversion
2D Image Coordinates
3D Modeling Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
2D Screen Coordinates
3D Camera Coordinates
2D Image Coordinates3D Model
2D Screen
![Page 56: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/56.jpg)
2D Rendering Pipeline
ScanConversion
Clipping
2D Primitives
Image
Clip portions of geometric primitivesresiding outside the window
Fill pixels representing primitives in screen coordinates
3D Primitives
![Page 57: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/57.jpg)
Overviewβ’ Scan conversion
Figure out which pixels to fill
β’ Shading Determine a color for each filled pixel
β’ Depth test Determine when the color of a pixel should be
overwritten
![Page 58: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/58.jpg)
Scan Conversionβ’ Render an image of a geometric primitive
by setting pixel colors
β’ Example: Filling the inside of a triangle
ππ1
ππ2
ππ3
void SetPixel( int x , int y , Color rgba )
![Page 59: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/59.jpg)
Triangle Scan Conversionβ’ Properties of a good algorithm
Must be fast No cracks between adjacent primitives
ππ1
ππ2
ππ3
ππ4
![Page 60: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/60.jpg)
Triangle Scan Conversionβ’ Properties of a good algorithm
Must be fast No cracks between adjacent primitives
ππ1
ππ2
ππ3
ππ4
![Page 61: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/61.jpg)
Simple Algorithm
ππ1
ππ2
ππ3
void ScanTriangle( Triangle T , Color rgba ){
for each pixel center (x,y)if( PointInsideTriangle( (x,y) , T ) )
SetPixel( x , y , rgba );}
β’ Color all pixels inside triangle
![Page 62: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/62.jpg)
ππ1
ππ2
Line defines two halfspacesβ’ Test: use implicit equation for a line
On line: πππ₯π₯ + πππ¦π¦ + ππ = 0 To the right: πππ₯π₯ + πππ¦π¦ + ππ < 0 To the left: πππ₯π₯ + πππ¦π¦ + ππ > 0
πΏπΏ
![Page 63: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/63.jpg)
Inside Triangle Testβ’ A point is inside a triangle if it is in the
positive half-space of all three boundary lines Triangle vertices are ordered counter-clockwise Point must be on the left side of every boundary line
πππΏπΏ1
πΏπΏ2
πΏπΏ3
![Page 64: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/64.jpg)
Inside Triangle TestBoolean PointInsideTriangle( Point P , Triangle T ){
for each boundary line L of T{
Scalar d = L.a*P.x + L.b*P.y + L.c;if( d<0.0 ) return FALSE;
}return TRUE;
}
πΏπΏ1
πΏπΏ2
πΏπΏ3
![Page 65: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/65.jpg)
Simple Algorithm
ππ1
ππ2
ππ3
void ScanTriangle( Triangle T , Color rgba ){
for each pixel center (x,y)if( PointInsideTriangle( (x,y) , T ) )
SetPixel( x , y , rgba );}
β’ What is bad about this algorithm?
![Page 66: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/66.jpg)
Triangle Sweep-Line Algorithmβ’ Take advantage of spatial coherence
β’ Take advantage of edge linearity
πππ₯π₯πππ¦π¦
![Page 67: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/67.jpg)
Triangle Sweep-Line Algorithmvoid ScanTriangle( Triangle T , Color rgba ){
for both edge pairs{
initialize xL, xR, y;compute dxL/dyL and dxR/dyR;until y reaches the first end-point
for( int x=xL ; x<=xR ; x++ ) SetPixel( x , y , rgba );xL += dxL/dyL;xR += dxR/dyR;y++;
}} πππ₯π₯πΏπΏ
πππ¦π¦πΏπΏπππ₯π₯π π
πππ¦π¦π π
π₯π₯πΏπΏ π₯π₯π π
![Page 68: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/68.jpg)
Triangle Sweep-Line Algorithmvoid ScanTriangle( Triangle T , Color rgba ){
for both edge pairs{
initialize xL, xR, y;compute dxL/dyL and dxR/dyR;until y reaches the first end-point
for( int x=xL ; x<=xR ; x++ ) SetPixel( x , y , rgba );xL += dxL/dyL;xR += dxR/dyR;y++;
}}
π₯π₯πΏπΏ π₯π₯π π πππ₯π₯πΏπΏ
πππ¦π¦πΏπΏ
πππ₯π₯π π πππ¦π¦π π
![Page 69: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/69.jpg)
Triangle Sweep-Line Algorithmvoid ScanTriangle( Triangle T , Color rgba ){
for both edge pairs{
initialize xL, xR, y;compute dxL/dyL and dxR/dyR;until y reaches the first end-point
for( int x=xL ; x<=xR ; x++ ) SetPixel( x , y , rgba );xL += dxL/dyL;xR += dxR/dyR;y++;
}}
Bresenhamβs algorithmworks the same way, but uses only integer operations!
![Page 70: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/70.jpg)
Polygon Scan Conversionβ’ Will this method work for convex polygons?
![Page 71: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/71.jpg)
Polygon Scan Conversionβ’ Will this method work for convex polygons?
Yes, since each scan line will only intersect the polygon at two points.
![Page 72: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/72.jpg)
Polygon Scan Conversionβ’ How about these polygons?
![Page 73: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/73.jpg)
Polygon Scan Conversionβ’ How about these polygons?
![Page 74: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/74.jpg)
Polygon Scan Conversionβ’ Fill pixels inside a polygon
Triangle Quadrilateral Convex Star-shaped Concave Self-intersecting Holes
What problems do we encounter with arbitrary polygons?
![Page 75: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/75.jpg)
Polygon Scan Conversionβ’ Need better test for points inside polygon
Triangle method works only for convex polygons
Convex Polygon
πΏπΏ1
πΏπΏ2
πΏπΏ3
πΏπΏ4πΏπΏ5
πΏπΏ1
πΏπΏ2
π³π³ππππ
πΏπΏ4πΏπΏ5
Concave Polygon
πΏπΏ3π΅π΅
![Page 76: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/76.jpg)
Inside Polygon Rule
β’ What is a good rule for which pixels are inside?
Concave Self-Intersecting With Holes
![Page 77: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/77.jpg)
Inside Polygon Rule
Concave Self-Intersecting With Holes
β’ Odd-parity rule Any ray from inside ππ to infinity must cross an odd
number of edges
![Page 78: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/78.jpg)
Polygon Sweep-Line Algorithm Use incremental algorithm to find spans Determine βinsidenessβ with odd parity rule
β’ Takes advantage of scan line coherence
π₯π₯πΏπΏ π₯π₯π π
Triangle Polygon
![Page 79: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/79.jpg)
Polygon Sweep-Line Algorithmvoid ScanPolygon( Polygon P , Color rgba ){
sort edges by maxymake empty βactive edge listβfor each scanline ( top-to-bottom ){
insert/remove edges from βactive edge listβupdate x coordinate of every active edgesort active edges by x coordinatefor each succesive pair of edge-points (left-to-right)
SetPixels( xi , xi+1 , y , rgba );}
}
![Page 80: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/80.jpg)
Polygon Scan Conversionβ’ Convert everything into triangles
Scan convert the triangles
![Page 81: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/81.jpg)
Polygon Scan Conversionβ’ Convert everything into triangles
Scan convert the triangles
Note:OpenGL will render polygons, but it assumes that:β’ The polygon is planarβ’ The polygon is convex
Note:Even if you only pass in triangles for rendering, OpenGL may still have to render (convex planar) polygons after the triangle is clipped.
![Page 82: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/82.jpg)
Scan Conversionβ’ What about pixels on edges?
If we set them either βonβ or βoffβ we get aliasing or βjaggiesβ
ππ1
ππ2
ππ3
![Page 83: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/83.jpg)
Scan Conversionβ’ What about pixels on edges?
If we set them either βonβ or βoffβ we get aliasing or βjaggiesβ
ππ1
ππ2
ππ3This is like using a βnearestβ interpolation filter!
![Page 84: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/84.jpg)
Antialiasing Techniquesβ’ Display at higher resolution
Corresponds to increasing sampling rate Not always possible (fixed size monitors, fixed refresh
rates, etc.)
β’ Modify pixel intensities Vary pixel intensities along boundaries for antialiasing
![Page 85: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/85.jpg)
Scan Conversionβ’ What about pixels on edges?
Setting them either βonβ or βoffβ we get aliasing/βjaggiesβ Antialias by varying pixel intensities along boundaries
ππ1
ππ2
ππ3
![Page 86: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/86.jpg)
Antialiasingβ’ Method 1: Area sampling
Calculate percent of pixel covered by primitive Multiply this percentage by desired intensity/color
ππ1
ππ2
ππ3
ππ1
ππ2
ππ3
100%2% 25% 60%
![Page 87: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/87.jpg)
Antialiasingβ’ Method 1: Area sampling
Calculate percent of pixel covered by primitive Multiply this percentage by desired intensity/color
ππ1
ππ2
ππ3
ππ1
ππ2
ππ3
100%2% 25% 60%
This is like using a βbilinearβ interpolation filter!
![Page 88: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/88.jpg)
Antialiasingβ’ Method 2: Supersampling (aka postfiltering)
Sample as if screen were higher resolution Average multiple samples to get final intensity
Β» This can be done by rendering the scene multiple times with different (fractional) offsets
ππ1
ππ2
ππ3ππ3
ππ1
ππ2
![Page 89: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/89.jpg)
AntialiasingNote that this makes things harder because pixels are no longer βownedβ by a single triangle.
Triangles contribute color rather than set color Along edges the total contribution must sum to one. Makes depth-testing more complicated.
ππ4
ππ2
ππ3
ππ1
![Page 90: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/90.jpg)
Scan Conversionβ’ Example:
No Anti-Aliasing 4 x Anti-AliasingImages courtesy of NVIDIA
![Page 91: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/91.jpg)
Lighting
ViewingTransformation
3D Rendering Pipeline (for direct illumination)
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Image
ViewportTransformation
ScanConversion
2D Image Coordinates
3D Modeling Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
2D Screen Coordinates
3D Camera Coordinates
2D Image Coordinates3D Model
2D Window
2D Screen
![Page 92: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/92.jpg)
Overviewβ’ Scan conversion
Figure out which pixels to fill
β’ Shading Determine a color for each filled pixel
β’ Depth test Determine when the color of a pixel comes from the
front-most primitive
![Page 93: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/93.jpg)
β’ Recall:In the βlightingβ phase, we calculated the color at each vertex.
Gouraud Shading
ππ1 πΏπΏ1
ππ1
ππ2
ππ3πΏπΏ3
πΏπΏ2ππ3
ππ2
πΌπΌ1
πΌπΌ2
πΌπΌ3
Lighting
ViewingTransformation
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Image
ViewportTransformation
ScanConversion
![Page 94: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/94.jpg)
β’ Recall:In the βlightingβ phase, we calculated the color at each vertex. In the βscan conversionβ phase, linearly
interpolate colors at vertices
Gouraud Shading
πΌπΌ1
πΌπΌ2
πΌπΌ3
πΌπΌ
π½π½
πΎπΎ
π΅π΅ = (1 β π½π½) β πΌπΌ2 + π½π½ β πΌπΌ3
πΌπΌ = (1 β πΎπΎ) β π΄π΄ + πΎπΎ β π΅π΅
π΄π΄ π΅π΅πΌπΌ
Lighting
ViewingTransformation
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Image
ViewportTransformation
ScanConversion
π΄π΄ = (1 β πΌπΌ) β πΌπΌ1 + πΌπΌ β πΌπΌ2
![Page 95: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/95.jpg)
β’ Recall:In the βlightingβ phase, we calculated the color at each vertex. In the βscan conversionβ phase, linearly
interpolate colors at vertices
Gouraud Shading
πΌπΌ1
πΌπΌ2
πΌπΌ3
πΌπΌ
π½π½
πΎπΎ
π΅π΅ = (1 β π½π½) β πΌπΌ2 + π½π½ β πΌπΌ3
πΌπΌ = (1 β πΎπΎ) β π΄π΄ + πΎπΎ β π΅π΅
π΄π΄ π΅π΅
Lighting
ViewingTransformation
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Image
ViewportTransformation
ScanConversion
Note: The values of πΌπΌ and π½π½ only need to be updated as we move to the next scan-line. The value of πΎπΎ needs
to be updated as we advance along the scan-line.
π΄π΄ = (1 β πΌπΌ) β πΌπΌ1 + πΌπΌ β πΌπΌ2
πΌπΌ
![Page 96: Clipping and Scan Conversionmisha/Fall20/13.pdfCohen-Sutherland Line Clipping β’ Associate a 4-bit outcode ππ ππ ππ ππ ππ ππ ππ ππ](https://reader036.vdocuments.us/reader036/viewer/2022070212/6105a8ee43447a5af7291b28/html5/thumbnails/96.jpg)
Lighting
ViewingTransformation
3D Rendering Pipeline (for direct illumination)
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Image
ViewportTransformation
ScanConversion
2D Image Coordinates
3D Modeling Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
2D Screen Coordinates
3D Camera Coordinates
2D Image Coordinates3D Model
2D Screen