Tuesday, April 3, 2012

Rasterization Rules

People who have experience in graphics programming using graphics APIs such as DirectX, OpenGL, and OpenGL ES, must have been familiar with the term, "Rasterization". However, how many of you have heard about "rasterization RULES"? In other words, who do you know how hardware determines that a specific pixel on shared edge between two triangles belongs to which triangle? This could be a point of view from graphics hardware rather than programmer's because it is processed in driver software. Thereby, driver softwares should follow the rules up. As a result, programmers who develop the drivers should know how rasterization works. However, regardless that you are a graphics driver programmer or graphics software engineer using APIs, I believe that "understanding the basic theory" is always helpful and useful to learn other concepts as well as work in various environments. Today, I would like to go over "rasterization rules" in graphics.  As I briefly mentioned before, 1) two polygons could share their edges (i.e., a rectangle consisting of two triangles). Another case is that 2) two lines could share the point (i.e., a set of line segments). These are two cases for the rasterization rules.


1. Top-left rule:
A triangle rasterization rule (in Direct3D, OpenGL, GDI) defines how vector data is mapped into raster data. The raster data is snapped to integer locations that are then culled and clipped, and per-pixel attributes are interpolated before being passed to a pixel shader. Top-left rule ensures that adjacent triangles are drawn once.



The shared edge is the left edge of the Triangle (0,0, 5,0, 5,5). Thus pixels on the shared edge are included into the right triangle.  If we consider antialiasing or multisampling , it will be more complicated.


 
 
 
 
 
 
 

2. Diamond-exit rule:
This is a rasterization rule for line segments that share the end point. OpenGL uses a this rule to determine those fragments that are produce by rasterizing a line segment.
 
Hence, when rasterizing a series of connected line segments, shared end points will be produced only once. Then, the diamond regions where line segment exits cause rasterization to produce fragments. In the figure, two line segments share the end point that belongs to the green line based on the diamond-exit rule.

Friday, July 1, 2011

Add non-admin users to Developer Tools group on Mac

[Source: http://idtechnology.blogspot.com/2010/10/add-user-to-developer-tools-group.html]

To add a user to “Developer Tools” group:
dseditgroup -o edit -u {admin_user} -t user -a {user_name} _developer

Saturday, January 8, 2011

Bit Operation #9

Print out odd numbers from 1 to 100

void printOddNumber()
{
    for (int i = 1; i <= 100; ++i)
    {
        if (i & 0x01)
            cout << i << \n;
    }
}

Bit Operation #8


100000
100000
------
011111

000000
000000
------
000000

100000
000000
------
000000

000100
000100
------
111011

100100
100100
------
011011

100100
000100
------
111011

010101
101010
------
000000

111111
111111
------
000000

// A function using bitwise operators for above results.
unsigned int f(unsigned int a, unsigned int b)
{
if (a & b)
{
return ~(a & b);
}
return 0;
}

Bit Operation #7

Find the largest possible integer

int largestInt()
{
    return ~0;
}