Painter's algorithm: Difference between revisions

Content deleted Content added
Citation bot (talk | contribs)
Removed URL that duplicated identifier. Removed parameters. | Use this bot. Report bugs. | Suggested by Headbomb | Linked from Wikipedia:WikiProject_Academic_Journals/Journals_cited_by_Wikipedia/Sandbox | #UCB_webform_linked 10/967
 
(27 intermediate revisions by 16 users not shown)
Line 1:
{{Short description|Algorithm for visible surface determination in 3D computer graphics}}
{{Distinguish|Schlemiel the Painter's algorithm}}
[[File:Genesis fractal landscape software (Commodore Amiga).webm|thumb|upright=1.2|A [[fractal landscape]] being rendered using the painter’spainter's algorithm on aan [[Commodore Amiga]]]]
The '''painter’s algorithm''' (also '''depth-sort algorithm''' and '''priority fill''') is an algorithm for [[Hidden surface determination#Visible%20surface%20determination|visible surface determination]] in [[3D computer graphics]] that works on a [[polygon|polygon-by-polygon]] basis rather than a [[pixel|pixel-by-pixel]], row by row, or area by area basis of other [[Hidden surface removal|Hidden Surface Removal]] algorithms.<ref>{{Cite journal|last=Appel|first=Arthur|date=1968|editor-last=Morrel|editor-first=A. J. H.|title=On calculating the illusion of reality|url=http://graphics.stanford.edu/courses/Appel.pdf|journal=Information Processing, Proceedings of IFIP Congress 1968, Edinburgh, UK, 5-10 August 1968, Volume 2 - Hardware, Applications|pages=945–950}}</ref><ref>{{Cite journal|last=Romney|first=Gordon Wilson|date=1969-09-01|title=Computer Assisted Assembly and Rendering of Solids.|url=https://apps.dtic.mil/sti/citations/AD0753673|archive-url=https://web.archive.org/web/20201102232139/https://apps.dtic.mil/sti/citations/AD0753673|url-status=live|archive-date=November 2, 2020|language=en}}</ref><ref>Gary Scott Watkins. 1970. [https://archive.org/details/utech-csc-70-101_watkins_dissertation_jun70 "A real time visible surface algorithm. Ph.D. Dissertation."] The University of Utah. Order Number: AAI7023061.</ref> The painter’s algorithm creates images by sorting the polygons within the image by their depth and placing each polygon in order from the farthest to the closest object.<ref name=":0" /><ref>{{Cite journal|last=Bouknight|first=W. Jack|date=1970-09-01|title=A procedure for generation of three-dimensional half-toned computer graphics presentations|url=https://doi.org/10.1145/362736.362739|journal=Communications of the ACM|volume=13|issue=9|pages=527–536|doi=10.1145/362736.362739|s2cid=15941472|issn=0001-0782}}</ref>
 
The '''painter’spainter's algorithm''' (also '''depth-sort algorithm''' and '''priority fill''') is an algorithm for [[Hidden -surface determination#Visible%20surface%20determination surface determination|visible surface determination]] in [[3D computer graphics]] that works on a [[polygon|polygon-by-polygon]] basis rather than a [[pixel|pixel-by-pixel]], row by row, or area by area basis of other [[Hidden hidden-surface removal|Hidden Surface Removaldetermination]] algorithms.<ref>{{Cite journal|last=Appel|first=Arthur|date=1968|editor-last=Morrel|editor-first=A. J. H.|title=On calculating the illusion of reality|url=http://graphics.stanford.edu/courses/Appel.pdf |archive-url=https://web.archive.org/web/20080720031432/http://graphics.stanford.edu/courses/Appel.pdf |archive-date=2008-07-20 |url-status=live|journal=Information Processing, Proceedings of IFIP Congress 1968, Edinburgh, UK, 5-10 August 1968, Volume 2 - Hardware, Applications|pages=945–950}}</ref><ref>{{Cite journal|last=Romney|first=Gordon Wilson|date=1969-09-01|title=Computer Assisted Assembly and Rendering of Solids.|url=https://apps.dtic.mil/sti/citations/AD0753673|archive-url=https://web.archive.org/web/20201102232139/https://apps.dtic.mil/sti/citations/AD0753673|url-status=live|archive-date=November 2, 2020|language=en}}</ref><ref>Gary Scott Watkins. 1970. [https://archive.org/details/utech-csc-70-101_watkins_dissertation_jun70 "A real time visible surface algorithm. Ph.D. Dissertation."] The University of Utah. Order Number: AAI7023061.</ref> The painter’spainter's algorithm creates images by sorting the polygons within the image by their depth and placing each polygon in order from the farthest to the closest object.<ref name=":0" /><ref>{{Cite journal|last=Bouknight|first=W. Jack|date=1970-09-01|title=A procedure for generation of three-dimensional half-toned computer graphics presentations|url=https://doi.org/10.1145/362736.362739|journal=Communications of the ACM|volume=13|issue=9|pages=527–536|doi=10.1145/362736.362739|s2cid=15941472|issn=0001-0782|doi-access=free}}</ref>
The painter's algorithm was initially proposed as a basic method to address the [[Hidden-surface determination]] problem by [[Martin Newell (computer scientist)|Martin Newell]], [[Dick Newell|Richard Newell]], and Tom Sancha in 1972, while all three were working at [[CADCentre]].<ref name=":0">{{Cite journal|last1=Newell|first1=M. E.|last2=Newell|first2=R. G.|last3=Sancha|first3=T. L.|date=1972-08-01|title=A solution to the hidden surface problem|url=https://ohiostate.pressbooks.pub/app/uploads/sites/45/2017/09/newell-newell-sancha.pdf|journal=Proceedings of the ACM Annual Conference - Volume 1|series=ACM '72|___location=Boston, Massachusetts, USA|publisher=Association for Computing Machinery|volume=1|pages=443–450|doi=10.1145/800193.569954|isbn=978-1-4503-7491-0|s2cid=13829930}}</ref> The name "painter's algorithm" refers to the technique employed by many painters where they begin by painting distant parts of a scene before parts that are nearer, thereby covering some areas of distant parts.<ref>{{Cite book|last=Berland|first=Dinah|title=Historical Painting Techniques, Materials, and Studio Practice|publisher=The Getty Conservation Institute|year=1995|url=https://www.getty.edu/conservation/publications_resources/pdf_publications/pdf/historical_paintings.pdf}}</ref><ref>{{Cite journal|last1=Wylie|first1=Chris|last2=Romney|first2=Gordon|last3=Evans|first3=David|last4=Erdahl|first4=Alan|date=1967-11-14|title=Half-tone perspective drawings by computer|url=https://doi.org/10.1145/1465611.1465619|journal=Proceedings of the November 14–16, 1967, Fall Joint Computer Conference|series=AFIPS '67 (Fall)|___location=Anaheim, California|publisher=Association for Computing Machinery|pages=49–58|doi=10.1145/1465611.1465619|isbn=978-1-4503-7896-3|s2cid=3282975}}</ref> Similarly, the painter's algorithm sorts all the polygons in a scene by their depth and then paints them in this order, farthest to closest.<ref name=":2">{{Cite book|last=Desai|first=Apurva|title=Computer Graphics|publisher=PHI Learning Pvt. Ltd.|year=2008|isbn=9788120335240|url=https://books.google.com/books?id=WQiIj8ZS0IoC&dq=%22hewells%22+painter%27s+algorithm&pg=PA256}}</ref> It will paint over the parts that are normally not visible — thus solving the visibility problem — at the cost of having painted invisible areas of distant objects.<ref name=":1">{{Cite book|last=de Berg|first=Mark|title=Computational Geometry|publisher=Springer|year=2008|url=https://people.inf.elte.hu/fekete/algoritmusok_msc/terinfo_geom/konyvek/Computational%20Geometry%20-%20Algorithms%20and%20Applications,%203rd%20Ed.pdf}}</ref> The ordering used by the algorithm is called a '''<nowiki>depth order'</nowiki>'' and does not have to respect the numerical distances to the parts of the scene: the essential property of this ordering is, rather, that if one object obscures part of another, then the first object is painted after the object that it obscures.<ref name=":1" /> Thus, a valid ordering can be described as a [[topological ordering]] of a [[directed acyclic graph]] representing occlusions between objects.<ref>{{Cite book|title=Ray Shooting, Depth Orders and Hidden Surface Removal|volume=703|series=Lecture Notes in Computer Science|first=Mark|last=de Berg|publisher=Springer|year=1993|isbn=9783540570202|url=https://books.google.com/books?id=b1INPTC3w_QC&pg=PA130|page=130}}.</ref>{{wide image|Painter's algorithm.svg|600px|The distant mountains are painted first, followed by the closer meadows; finally, the trees, are painted. Although some trees are more distant from the viewpoint than some parts of the meadows, the ordering (mountains, meadows, trees) forms a valid depth order, because no object in the ordering obscures any part of a later object.}}
 
The painter's algorithm was initially proposed as a basic method to address the [[Hiddenhidden-surface determination]] problem by [[Martin Newell (computer scientist)|Martin Newell]], [[Dick Newell|Richard Newell]], and Tom Sancha in 1972, while all three were working at [[CADCentre]].<ref name=":0">{{Cite journalbook|last1=Newell|first1=M. E.|last2=Newell|first2=R. G.|last3=Sancha|first3=T. L.|datetitle=1972Proceedings of the ACM annual conference on -08-01 ACM'72 |titlechapter=A solution to the hidden surface problem |date=1972-08-01|chapter-url=https://ohiostate.pressbooks.pub/app/uploads/sites/45/2017/09/newell-newell-sancha.pdf |journalarchive-url=Proceedings of the ACM Annual Conferencehttps://web.archive.org/web/20200922053518/https://ohiostate.pressbooks.pub/app/uploads/sites/45/2017/09/newell-newell-sancha.pdf |archive-date=2020-09-22 Volume 1|url-status=live|series=ACM '72|___location=Boston, Massachusetts, USA|publisher=Association for Computing Machinery|volume=1|pages=443–450|doi=10.1145/800193.569954|isbn=978-1-4503-7491-0|s2cid=13829930}}</ref> The name "painter's algorithm" refers to the technique employed by many painters where they begin by painting distant parts of a scene before parts that are nearer, thereby covering some areas of distant parts.<ref>{{Cite book|last=Berland|first=Dinah|title=Historical Painting Techniques, Materials, and Studio Practice|publisher=The Getty Conservation Institute|year=1995|url=https://www.getty.edu/conservation/publications_resources/pdf_publications/pdf/historical_paintings.pdf}}</ref><ref>{{Cite journalbook|last1=Wylie|first1=Chris|last2=Romney|first2=Gordon|last3=Evans|first3=David|last4=Erdahl|first4=Alan|datetitle=Proceedings of the November 14-16, 1967, fall joint computer conference on -11-14 AFIPS '67 (Fall) |titlechapter=Half-tone perspective drawings by computer |date=1967-11-14|chapter-url=https://doi.org/10.1145/1465611.1465619|journal=Proceedings of the November 14–16, 1967, Fall Joint Computer Conference|series=AFIPS '67 (Fall)|___location=Anaheim, California|publisher=Association for Computing Machinery|pages=49–58|doi=10.1145/1465611.1465619|isbn=978-1-4503-7896-3|s2cid=3282975}}</ref> Similarly, the painter's algorithm sorts all the polygons in a scene by their depth and then paints them in this order, farthest to closest.<ref name=":2">{{Cite book|last=Desai|first=Apurva|title=Computer Graphics|publisher=PHI Learning Pvt. Ltd.|year=2008|isbn=9788120335240|url=https://books.google.com/books?id=WQiIj8ZS0IoC&dq=%22hewells%22+painter%27s+algorithm&pg=PA256}}</ref> It will paint over the parts that are normally not visible — thus solving the visibility problem — at the cost of having painted invisible areas of distant objects.<ref name=":1">{{Cite book|last=de Berg|first=Mark|title=Computational Geometry|publisher=Springer|year=2008|url=https://people.inf.elte.hu/fekete/algoritmusok_msc/terinfo_geom/konyvek/Computational%20Geometry%20-%20Algorithms%20and%20Applications,%203rd%20Ed.pdf |archive-url=https://web.archive.org/web/20160803163744/http://people.inf.elte.hu/fekete/algoritmusok_msc/terinfo_geom/konyvek/Computational%20Geometry%20-%20Algorithms%20and%20Applications,%203rd%20Ed.pdf |archive-date=2016-08-03 |url-status=live}}</ref> The ordering used by the algorithm is called a '''<nowiki>depth order'</nowiki>'' and does not have to respect the numerical distances to the parts of the scene: the essential property of this ordering is, rather, that if one object obscures part of another, then the first object is painted after the object that it obscures.<ref name=":1" /> Thus, a valid ordering can be described as a [[topological ordering]] of a [[directed acyclic graph]] representing occlusions between objects.<ref>{{Cite book|title=Ray Shooting, Depth Orders and Hidden Surface Removal|volume=703|series=Lecture Notes in Computer Science|first=Mark|last=de Berg|publisher=Springer|year=1993|isbn=9783540570202|url=https://books.google.com/books?id=b1INPTC3w_QC&pg=PA130|page=130}}.</ref>{{wide image|Painter's algorithm.svg|600px|The distant mountains are painted first, followed by the closer meadows; finally, the trees, are painted. Although some trees are more distant from the viewpoint than some parts of the meadows, the ordering (mountains, meadows, trees) forms a valid depth order, because no object in the ordering obscures any part of a later object.}}
 
== Algorithm ==
Line 19 ⟶ 20:
 
=== Time complexity ===
The painter's algorithm's time-complexity is heavily dependentdepends on the [[sorting algorithm]] used to order the polygons. Assuming the use of the mostan optimal sorting algorithm, painter's algorithm has a worst-case complexity of ''[[Big O notation|O]]''(''n'' log ''n + m*n''), where ''n'' is the number of polygons and ''m'' is the number of pixels to be filled.
 
=== Space complexity ===
 
The painter's algorithm's worst-case space-complexity is ''O''(''n+m''), where ''n'' is the number of polygons and ''m'' is the number of pixels to be filled.
 
== Advantages ==
There are two primary technical requisites that favor the use of the painter’spainter's algorithm.
 
=== Basic graphical structure ===
The painter's algorithm is not as complex in structure as its other depth sorting algorithm counterparts.<ref name=":1" /><ref>{{Cite journal|last=Warnock|first=John E.|date=1969-06-01|title=A Hidden Surface Algorithm for Computer Generated Halftone Pictures|url=https://apps.dtic.mil/sti/citations/AD0753671|archive-url=https://web.archive.org/web/20201108193625/https://apps.dtic.mil/sti/citations/AD0753671|url-status=live|archive-date=November 8, 2020|language=en}}</ref> Components such as the depth-based rendering order, as employed by the painter’spainter's algorithm, are one of the simplest ways to designate the order of graphical production.<ref name=":2" /> This simplicity makes it useful in basic computer graphics output scenarios where an unsophisticated render will need to be made with little struggle.<ref name=":1" />
 
=== Memory efficiency ===
In the early 70s, when the painter’spainter's algorithm was developed, physical memory was relatively small.<ref>{{Cite journal|last1=Freiser|first1=M.|last2=Marcus|first2=P.|date=June 1969|title=A survey of some physical limitations on computer elements|url=https://ieeexplore.ieee.org/document/1066403|journal=IEEE Transactions on Magnetics|volume=5|issue=2|pages=82–90|doi=10.1109/TMAG.1969.1066403|bibcode=1969ITM.....5...82F|issn=1941-0069}}</ref> This required programs to manage memory as efficiently as possible to conduct large tasks without crashing. The painter’spainter's algorithm prioritizes the efficient use of memory but at the expense of higher processing power since all parts of all images must be rendered.<ref name=":1" />[[File:Painters problem.svg|thumb|right|Overlapping polygons can cause the algorithm to fail|285x285px]]
 
== Limitations ==
[[File:Painters problem.svg|thumb|Overlapping polygons can cause the algorithm to fail.]]
The algorithm can fail in some cases, including cyclic overlap or piercing polygons.
 
=== Cyclical Overlappingoverlapping ===
In the case of cyclic overlap, as shown in the figure to the right, Polygons A, B, and C overlap each other in such a way that it is impossible to determine which polygon is above the others. In this case, the offending polygons must be cut to allow sorting.<ref name=":0" />
 
Line 43 ⟶ 46:
=== Efficiency ===
In basic implementations, the painter's algorithm can be inefficient. It forces the system to [[rendering (computer graphics)|render]] each point on every polygon in the visible set, even if that polygon is occluded in the finished scene. This means that, for detailed scenes, the painter's algorithm can overly tax the computer hardware.
 
== Reducing visual errors ==
There are a few ways to reduce the visual errors that can happen with sorting:
 
=== Binary Space Partitioning ===
BSP is a method that involves making a BSP tree, and splitting triangles where they intersect. It can be extremely hard to implement, but it fixes most visual errors.
 
=== Backface culling ===
Backface culling involves calculations to see if a triangles points will appear clockwise or counter-clockwise once projected to the screen, and doesn't draw triangles that shouldn't be visible anyway. It reduces some visual errors, as well as reducing the total triangles drawn.
 
== Variants ==
 
Line 52 ⟶ 65:
 
== Other computer graphics algorithms ==
The flaws of painter's algorithm led to the development of [[Z-buffering|Z-buffer]] techniques, which can be viewed as a development of the painter's algorithm by resolving depth conflicts on a pixel-by-pixel basis, reducing the need for a depth-based rendering order.<ref>{{Cite book|last=Nyberg|first=Daniel|url=http://urn.kb.se/resolve?urn=urn:nbn:se:kth:diva-130849|title=Analysis of Two Common Hidden Surface Removal Algorithms, Painter&apos;'s Algorithm & Z-Buffering.|date=2011}}</ref> Even in such systems, a variant of the painter's algorithm is sometimes employed. As Z-buffer implementations generally rely on fixed-precision depth-buffer registers implemented in hardware, there is scope for visibility problems due to rounding error. These are overlaps or gaps at joints between polygons. To avoid this, some graphics engines implement "over-rendering",{{Citation needed|date=January 2008}}, drawing the affected edges of both polygons in the order given by the painter's algorithm. This means that some pixels are actually drawn twice (as in the full painter's algorithm), but this happens on only small parts of the image and has a negligible performance effect.
 
== References ==
* {{cite book
|last1 = Foley
|first1 = James
|author-link = James D. Foley
|title = Computer Graphics: Principles and Practice
|publisher = [[Addison-Wesley]]
Line 68 ⟶ 82:
|last3 = Hughes
|first3 = John F.
|title-link = Computer Graphics: Principles and Practice
|author-link3 = John F. Hughes (computer scientist)
}}
Line 78 ⟶ 92:
* https://www.clear.rice.edu/comp360/lectures/old/HiddenSurfText.pdf
* https://www.cs.princeton.edu/courses/archive/spring01/cs598b/papers/greene93.pdf
 
{{Computer graphics}}
 
[[Category:3D computer graphics]]