Class Rasterize_Clip_AntiAlias_Line
- java.lang.Object
-
- renderer.pipeline.Rasterize_Clip_AntiAlias_Line
-
public final class Rasterize_Clip_AntiAlias_Line extends Object
Rasterize a projectedLineSegmentinto shaded pixels in aFrameBuffer.Viewportand (optionally) anti-alias and gamma-encode the line at the same time. Also, (optionally) do not rasterize any part of theLineSegmentthat is not contained in theCamera's view rectangle.This pipeline stage takes a
LineSegmentwhose vertices have been projected into theCamera's view plane coordinate system and rasterizes theLineSegmentinto shaded, anti-aliased pixels in aFrameBuffer.Viewport.In addition, this rasterizer has the option to "clip" the
LineSegmentby not rasterizing into theFrameBuffer.Viewportany part of the projectedLineSegmentthat is not within theCamera's view rectangle.This rasterization algorithm is based on
"Fundamentals of Computer Graphics", 3rd Edition, by Peter Shirley, pages 163-165.This rasterizer implements a simple version of Xiaolin_Wu's anti-aliasing algorithm. See https://en.wikipedia.org/wiki/Xiaolin_Wu's_line_algorithm
Recall that a
FrameBuffer.Viewportis a two-dimensional array of pixel data. So a viewport has an integer "coordinate system". That is, we locate a pixel in a viewport using two integers, which we think of as row and column. On the other hand, aCamera's view rectangle has a two-dimensional real number (not integer) coordinate system. Since a framebuffer's viewport and a camera's view rectangle have such different coordinate systems, rasterizing line segments from a two-dimensional real number coordinate system to an two-dimensional integer grid can be tricky. The "logical pixel-plane" and the "viewport transformation" try to make this rasterization step a bit easier.(0,0) +-------------------------------------------+ y-axis |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-| | |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-| | (+1,+1) |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-| +-----|-----+ |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-| | | | |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-| | | | |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-| ----------+----------- x-axis |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-| | | | |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-| | | | |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-| +-----|-----+ |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-| (-1,-1) | |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-| | |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-| |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-| Camera's View Rectangle +-------------------------------------------+ (in the View Plane) (w-1,h-1) FrameBuffer's ViewportThe viewport transformation places the logical pixel-plane between the camera's view rectangle and the framebuffer's viewport. The pixel-plane has a real number coordinate system (like the camera's view plane) but is has dimensions more like the dimensions of the framebuffer's viewport.
(w+0.5, h+0.5) +----------------------------------------------+ | . . . . . . . . . . . . . . . . . . . . . . | | . . . . . . . . . . . . . . . . . . . . . . | | . . . . . . . . . . . . . . . . . . . . . . | | . . . . . . . . . . . . . . . . . . . . . . | | . . . . . . . . . . . . . . . . . . . . . . | The "logical pixels" | . . . . . . . . . . . . . . . . . . . . . . | are the points in | . . . . . . . . . . . . . . . . . . . . . . | the pixel-plane with | . . . . . . . . . . . . . . . . . . . . . . | integer coordinates. | . . . . . . . . . . . . . . . . . . . . . . | | . . . . . . . . . . . . . . . . . . . . . . | | . . . . . . . . . . . . . . . . . . . . . . | | . . . . . . . . . . . . . . . . . . . . . . | | . . . . . . . . . . . . . . . . . . . . . . | +----------------------------------------------+ (0.5, 0.5) pixel-plane's "logical viewport" containing "logical pixels"Notice that we have two uses of the word "viewport",
- The "logical viewport" is a rectangle in the pixel-plane (so its points have real number coordinates). The "logical pixels" are the points in the logical viewport with integer coordinates.
- The "physical viewport" is part of the
FrameBuffer's pixel array (so its entries have integer coordinates). The "physical pixels" are the entries in the physical viewport.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidrasterize(Model model, LineSegment ls, FrameBuffer.Viewport vp)Rasterize and (possibly) clip a projectedLineSegmentinto pixels in theFrameBuffer.Viewport.
-
-
-
Method Detail
-
rasterize
public static void rasterize(Model model, LineSegment ls, FrameBuffer.Viewport vp)
Rasterize and (possibly) clip a projectedLineSegmentinto pixels in theFrameBuffer.Viewport.- Parameters:
model-Modelthat theLineSegmentlscomes fromls-LineSegmentto rasterize into theFrameBuffer.Viewportvp-FrameBuffer.Viewportto hold rasterized pixels
-
-