Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an...
Transcript of Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an...
![Page 1: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/2.jpg)
Announcements
• Assignment 2 posted!
![Page 3: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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 World
Coordinates
3D Object
Coordinates
![Page 5: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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 World
Coordinates
Transform = 𝑀𝑀 = local to world transform
(𝑥, 𝑦, 𝑧)
(𝑥′, 𝑦′)
![Page 6: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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 World
Coordinates
3D Camera
Coordinates(𝑥, 𝑦, 𝑧)
(𝑥′, 𝑦′)
Transform = 𝑀𝑀 = local to world transform
![Page 7: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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
𝑤𝑦2
Window Viewport
Screen Coordinates Image Coordinates
(𝑤𝑥, 𝑤𝑦) (𝑣𝑥 , 𝑣𝑦)
(𝑥, 𝑦, 𝑧)
(𝑥′, 𝑦′)
𝑉 = viewport transform
𝑉 =1 0 𝑣𝑥
1
0 1 𝑣𝑥2
0 0 1
𝑣𝑥2 − 𝑣𝑥
1
𝑤𝑥2 − 𝑤𝑥
1 0 0
0𝑣𝑦2 − 𝑣𝑦
1
𝑤𝑦2 − 𝑤𝑦
1 0
0 0 1
1 0 −𝑤𝑥1
0 1 −𝑤𝑦1
0 0 1
Transform = 𝑉𝑃𝑇𝐶→𝑊−1 𝑀
![Page 10: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/11.jpg)
Transformations
ModelingTransformation
ViewingTransformation
ProjectionTransformation
Lighting
Clipping
ScanConversion
3D Geometric Primitives
Image
𝑁
𝐿1
𝐿2
𝑉
Viewer
𝐼 = 𝐼𝐸 +
𝐿
𝐾𝐴 ⋅ 𝐼𝐿𝐴 + 𝐾𝐷 ⋅ 𝑁, 𝐿 + 𝐾𝑆 ⋅ 𝑉, 𝑅
𝑛 ⋅ 𝐼𝐿
3D Model2D Screen
![Page 12: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/15.jpg)
• Is point (𝑥, 𝑦) inside the clip window?
Point Clipping
Window
𝑤𝑥1 𝑤𝑥
2
𝑤𝑦2
𝑤𝑦1
(𝑥, 𝑦)
![Page 16: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/19.jpg)
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010
𝑃1
𝑃10
𝑃9
𝑃8
𝑃7
𝑃4𝑃3
𝑃6
𝑃5
𝑃2
![Page 20: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/20.jpg)
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010
𝑃1
𝑃10
𝑃9
𝑃8
𝑃7
𝑃6
𝑃5
𝑃2
𝑃4𝑃3
![Page 21: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/21.jpg)
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010
𝑃10
𝑃9
𝑃8
𝑃7
𝑃6
𝑃5
𝑃4𝑃3
𝑃1
𝑃2
![Page 22: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/22.jpg)
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010
𝑃10
𝑃9
𝑃8
𝑃7
𝑃6
𝑃5
𝑃4𝑃3
![Page 23: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/23.jpg)
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010
𝑃10
𝑃9
𝑃8
𝑃7
𝑃4𝑃3
𝑃6
𝑃5
![Page 24: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/24.jpg)
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010
𝑃10
𝑃9
𝑃8
𝑃7
𝑃4𝑃3
𝑃6
𝑃5
![Page 25: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/25.jpg)
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010𝑃5′
𝑃10
𝑃9
𝑃8
𝑃7
𝑃4𝑃3
𝑃6
![Page 26: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/26.jpg)
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010𝑃5′
𝑃10
𝑃9
𝑃4𝑃3
𝑃6
𝑃8
𝑃7
![Page 27: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/27.jpg)
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010𝑃5′
𝑃10
𝑃9
𝑃3
𝑃6
𝑃8
𝑃7
𝑃4
![Page 28: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/28.jpg)
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010
𝑃7′
𝑃5′
𝑃10
𝑃9
𝑃3
𝑃6
𝑃8𝑃4
![Page 29: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/29.jpg)
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010
𝑃7′
𝑃5′
𝑃10
𝑃9
𝑃3
𝑃6
𝑃8𝑃4
![Page 30: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/30.jpg)
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010
𝑃8′
𝑃7′
𝑃5′
𝑃10
𝑃9
𝑃3
𝑃6
𝑃4
![Page 31: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/31.jpg)
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010
𝑃8′
𝑃7′
𝑃5′
𝑃3
𝑃6
𝑃4
𝑃10
𝑃9
![Page 32: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/32.jpg)
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010
𝑃8′
𝑃7′
𝑃5′
𝑃3
𝑃6
𝑃4
𝑃10
𝑃9
![Page 33: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/33.jpg)
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010𝑃9′
𝑃8′
𝑃7′
𝑃5′
𝑃3
𝑃6
𝑃4
𝑃10
![Page 34: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/34.jpg)
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010
𝑃8′
𝑃7′
𝑃5′
𝑃3
𝑃6
𝑃4
![Page 35: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/35.jpg)
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010
𝑃8′
𝑃7′
𝑃5′
𝑃3
𝑃6
𝑃4
How many bits would you need in 3D?
![Page 36: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/37.jpg)
Polygon Clipping
• Find the part of a polygon inside the clip window
Before Clipping
![Page 38: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/38.jpg)
Sutherland-Hodgeman Clipping
• Clip to each window boundary one at a time
![Page 39: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/39.jpg)
Sutherland-Hodgeman Clipping
• Clip to each window boundary one at a time
![Page 40: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/40.jpg)
Sutherland-Hodgeman Clipping
• Clip to each window boundary one at a time
![Page 41: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/41.jpg)
Sutherland-Hodgeman Clipping
• Clip to each window boundary one at a time
![Page 42: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/42.jpg)
Sutherland-Hodgeman Clipping
• Clip to each window boundary one at a time
![Page 43: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/43.jpg)
Sutherland-Hodgeman Clipping
• How do we clip a polygon with respect to a line?
Outside
Inside
Window
Boundary
𝑃1𝑃2
𝑃5
𝑃4
𝑃3
![Page 44: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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
Outside
Inside
Window
Boundary
𝑃1𝑃2
𝑃5
𝑃4
𝑃3
![Page 45: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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
Outside
Inside
Window
Boundary
𝑃1𝑃2
𝑃5
𝑃4
𝑃3
![Page 46: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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
Outside
Inside
Window
Boundary
𝑃1𝑃2
𝑃5
𝑃4
𝑃3
![Page 47: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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
Outside
Inside
Window
Boundary
𝑃1𝑃2
𝑃5
𝑃4
𝑃3
![Page 48: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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
Outside
Inside
Window
Boundary 𝑃′
𝑃1𝑃2
𝑃5
𝑃4
𝑃3
![Page 49: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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
Outside
Inside
Window
Boundary 𝑃′
𝑃1𝑃2
𝑃5
𝑃4
𝑃3
![Page 50: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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
Outside
Inside
Window
Boundary 𝑃′
𝑃1𝑃2
𝑃5
𝑃4
𝑃3
![Page 51: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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
Outside
Inside
Window
Boundary 𝑃′′𝑃′
𝑃1𝑃2
𝑃5
𝑃4
𝑃3
![Page 52: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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
Outside
Inside
Window
Boundary 𝑃′′𝑃′
𝑃1𝑃2
![Page 53: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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
Outside
Inside
Window
Boundary 𝑃′′𝑃′
𝑃1𝑃2
When polygons are clipped, per-vertex properties
(e.g. lighting) is interpolated to the new vertices.
![Page 54: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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
Outside
Inside
Window
Boundary
What happens if the polygon is not convex?
![Page 55: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/56.jpg)
2D Rendering Pipeline
ScanConversion
Clipping
2D Primitives
Image
Clip portions of geometric primitives
residing outside the window
Fill pixels representing primitives
in screen coordinates
3D Primitives
![Page 57: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/64.jpg)
Inside Triangle Test
Boolean 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/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/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/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/66.jpg)
Triangle Sweep-Line Algorithm
• Take advantage of spatial coherence
• Take advantage of edge linearity
𝑑𝑥𝑑𝑦
![Page 67: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/67.jpg)
Triangle Sweep-Line Algorithm
void ScanTriangle( Triangle T , Color rgba ){
for both edge pairs{
initialize xL, xR;compute dxL/dyL and dxR/dyR;for each scanline at y
for( int x=xL ; x<=xR ; x++ ) SetPixel( x , y , rgba );xL += dxL/dyL;xR += dxR/dyR;
}}
𝑥𝐿 𝑥𝑅
𝑑𝑥𝐿𝑑𝑦𝐿
𝑑𝑥𝑅𝑑𝑦𝑅Bresenham’s algorithm
works the same way, but uses only integer operations!
![Page 68: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/68.jpg)
Polygon Scan Conversion
• Will this method work for convex polygons?
![Page 69: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/69.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 70: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/70.jpg)
Polygon Scan Conversion
• How about these polygons?
![Page 71: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/71.jpg)
Polygon Scan Conversion
• How about these polygons?
![Page 72: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/72.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 73: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/73.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 74: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/74.jpg)
Inside Polygon Rule
• What is a good rule for which pixels are inside?
Concave Self-Intersecting With Holes
![Page 75: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/75.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 76: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/76.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 77: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/77.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 78: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/78.jpg)
Polygon Scan Conversion
• Convert everything into triangles Scan convert the triangles
![Page 79: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/79.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 80: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/80.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 81: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/81.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 82: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/82.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 83: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/83.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 84: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/84.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 85: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/85.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 86: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/86.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 87: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/87.jpg)
Antialiasing
Note 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 88: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/88.jpg)
Scan Conversion
• Example:
No Anti-Aliasing 4 x Anti-Aliasing
Images courtesy of NVIDIA
![Page 89: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/89.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 90: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/90.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 91: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/91.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 92: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/92.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 93: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/93.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 94: Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an outcode to each vertex • If both outcodes are 0, line segment is inside • If AND](https://reader033.fdocuments.us/reader033/viewer/2022042022/5e798a987840b74cf0497b85/html5/thumbnails/94.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