In this video, we have discussed about one of the algorithms from Computer Graphics - Painter's algorithm.
The painter’s algorithm deals with image painting. It uses image space and object space techniques. It is VSD (Virtual Surface Determination) algorithm similar to the Z-buffer algorithm. Its name is Painter’s because the working the algorithm is like a painter who is creating an oil painting.
It starts painting from the empty canvas and creates the background for the painting also known as first layer painting. After completing the previous layer then it works on the next layer and after completing the next layer it works on the final layer and so on. In this way covering all the layers to complete the previous one.
The painter's algorithm sorts all the polygons in a scene by their depth value and then paints them in this order, farthest to closest.
Painter's Algorithm:
This algorithm is used for polygon painting normally
Step 1: Sorting the surfaces based on given depth in increasing order.
Step 2: Start painting from the greatest depth
Step 3: Compare the surface which surfaces are visible or not based on the painting layer.
Step 4: This above process repeats until the complete all surface.
Step 5: If the surface layer is overlapped completely then the algorithm is stopped.
First, sort all objects and name it Zmin and Zmax
Suppose if Zmin and Zmax are adjacent in the sorted list, it is ok.
If two objects are overlap:
1. Check whether they overlap in X-coordinate
- if not, it's ok
2. Check whether they overlap in Y-coordinate
- if not, it's ok
- if yes, we have to split one.
The splitting technique is a little bit difficult
1. First try to find a plane to split in one polygon, so the new polygon is either present in front or behind the other.
2. If polygons intersect, they have to split by the other.
Advantages:
- For ordering polygons, Painter’s algorithm is a simple algorithm.
Disadvantages:
- The sorting technique is difficult.
- Many times it redraws the same pixel.
- The sorting technique is also expensive.
Painter's algorithm: https://www.geeksforgeeks.org/painters-algorithm-in-computer-graphics/