270 likes | 380 Views
Image Synthesis. Rabie A. Ramadan, PhD 7. Image Rasterization. Rasterization and Fragment Processing. A precise sequence of steps for converting primitives into patterns of pixel values in the framebuffer.
E N D
Image Synthesis Rabie A. Ramadan, PhD 7
Rasterization andFragment Processing A precise sequence of steps for converting primitives into patterns of pixel values in the framebuffer. Digital images created or captured (for example, by scanning in a photo) as a set of samples of a given space.
Rasterization First job: enumerate the pixels covered by a primitive Simple, aliased definition: pixels whose centers fall inside Second job: interpolate values across the primitive e.g., colors computed at vertices Will see applications later on
visual accuracy speed Raster conversion algorithms: requirements
Screen made of pixels High-level language specifies line System must color pixels How does computer draw line?
Line definition: ax+by+c = 0 Also expressed as: y = mx + d m = slope d = distance For x=xmin to xmax compute y = m*x+d light pixel (x,y) Naïve algorithm for lines
Only works with -1 £m£ 1: Extension by symmetry m = 3 m = 1/3 Extend by symmetry for m > 1
2 floating-point operations per pixel Improvements: compute y = m*p+d For x=xmin to xmax y += m light pixel (x,y) Still 1 floating-point operation per pixel Compute in floats, pixels in integers Problems
input line endpoints, (x0,y0) and (xn, yn) set pixel at position (x0,y0) calculate slope m Case |m|≤1: repeat the following steps until (xn, yn) is reached: yi+1 = yi + y/ x xi+1 = xi + 1 set pixel at position (xi+1,Round(yi+1)) Case |m|>1: repeat the following steps until (xn, yn) is reached: xi+1 = xi + x/ y yi+1 = yi + 1 set pixel at position (Round(xi+1), yi+1) Digital Differential Algorithm
d2 y = m(x+1) + b d1 Bresenham's line algorithm y = mx + b y x x+1
input line endpoints, (x0,y0) and (xn, yn) calculate x = xn - x0 and y = yn - y0 calculate parameter p0 = 2 y - x set pixel at position (x0,y0) repeat the following steps until (xn, yn) is reached: if pi < 0 set the next pixel at position (xi +1, yi ) calculate new pi+1 = pi + 2 y if pi ≥ 0 set the next pixel at position (xi +1, yi + 1 ) calculate new pi+1 = pi + 2(y - x) Bresenham's line algorithm (slope ≤ 1)
DDA works with floating point arithmetic Rounding to integers necessary Bresenham’s algorithm uses integer arithmetic Constants need to be computed only once Bresenham’s algorithm generally faster than DDA DDA versus Bresenham’s Algorithm
Circle equation: x2+y2-r2 = 0 Simple algorithm: for x = xmin to xmax y = sqrt(r*r - x*x) draw pixel(x,y) Work by octants and use symmetry Circle: naïve algorithm
Choice between two pixels: Circle: Bresenham algorithm …or that one Circle drawn so far Either I lit this pixel…