void SoftRasta::renderTriangleSolid16(RenderTriangle &t, unsigned char* buffer, unsigned short &pitch)
{
int i0 = 0, i1 = 1, i2 = 2;
// sort verts by height
if(t.coords[i0].y > t.coords[i1].y) mySwap(i0, i1);
if(t.coords[i0].y > t.coords[i2].y) mySwap(i0, i2);
if(t.coords[i1].y > t.coords[i2].y) mySwap(i1, i2);
int x0 = (int)t.coords[i0].x, y0 = (int)t.coords[i0].y;
int x1 = (int)t.coords[i1].x, y1 = (int)t.coords[i1].y;
int x2 = (int)t.coords[i2].x, y2 = (int)t.coords[i2].y;
unsigned short pitch16 = pitch >> 1;
// test for easy cases, else split trinagle in two and render both halfs
if(y1 == y2){
if(x1 > x2) mySwap(x1, x2);
renderFlatTriangle16(x1, y1, x2, y2, x0, y0, buffer, pitch16, t.color);
}
else if(y0 == y1){
if(x0 > x1) mySwap(x0, x1);
renderFlatTriangle16(x0, y0, x1, y1, x2, y2, buffer, pitch16, t.color);
}
else{
// compute x pos of the vert that builds the splitting line with x1
int tmp_x = x0 + (int)(0.5f + (float)(y1-y0) * (float)(x2-x0) / (float)(y2-y0));
if(x1 > tmp_x) mySwap(x1, tmp_x);
renderFlatTriangle16(x1, y1, tmp_x, y1, x0, y0, buffer, pitch16, t.color);
renderFlatTriangle16(x1, y1, tmp_x, y1, x2, y2, buffer, pitch16, t.color);
}
}
void SoftRasta::renderFlatTriangle16(int x0, int y0, int x1, int y1, int x2, int y2, unsigned char* buffer, unsigned short pitch16, unsigned short color)
{
unsigned short* pixel = NULL;
// compute slopes for the two triangle legs
float dx0 = (float)(x2 - x0) / (y2 - y0);
float dx1 = (float)(x2 - x1) / (y2 - y1);
int yRange = 0;
float lx = (float) x0, rx = (float) x1;
if(y0 < y2){ yRange = y2 - y0; pixel = (unsigned short*)buffer + y0 * pitch16; }
else { yRange = y0 - y2; pixel = (unsigned short*)buffer + y2 * pitch16; lx = rx = (float)x2; }
for(int i=0; i<yRange; ++i){
for(int j=(int)(lx); j<(int)((rx) + 1.0f); ++j){
*(pixel + j) = color;
}
lx += dx0;
rx += dx1;
pixel += pitch16;
}
}
rendering a triangle in software
#1
Posted 15 January 2004 - 06:29 PM
#2
Posted 15 January 2004 - 11:52 PM
maybe i can dig them up, too
#3
Posted 16 January 2004 - 03:59 AM
#4
Posted 16 January 2004 - 11:40 AM
#5
Posted 16 January 2004 - 04:01 PM
#6
Posted 17 January 2004 - 01:29 AM
#7
Posted 17 January 2004 - 09:26 AM
#8
Posted 20 January 2004 - 10:36 AM
#9
Posted 20 January 2004 - 12:49 PM
[EDIT] : nm, his own site is still active... [/EDIT]
#10
Posted 20 January 2004 - 12:54 PM
though it's not a very brilliant idea it might speed up rendering by a big margin...
#11
Posted 20 January 2004 - 12:56 PM
#12
Posted 20 January 2004 - 09:42 PM
i don't even know how to explain it better than he does. it's all there in his paper.
#13
Posted 24 January 2004 - 09:44 AM
P.S.
The stuff with the dissapearing knowledge is true!!!
#14
Posted 25 January 2004 - 05:43 PM
#15
Posted 07 September 2004 - 09:26 PM
void Rasterizer::drawTriangle(const Vertex *V1, const Vertex *V2, const Vertex *V3)
{
if(V1->y > V3->y) swap(V1, V3);
if(V2->y > V3->y) swap(V2, V3);
if(V1->y > V2->y) swap(V1, V2);
const Vertex &v1 = *V1;
const Vertex &v2 = *V2;
const Vertex &v3 = *V3;
...
Vertices get passed as pointers, then they are sorted by swapping the pointers, and finally the pointers are dereferences so you can work with . instead of -> all the time. All my other parameters are in a 'context' structure directly accessible for the Rasterizer class. This avoids passing all the arguments to the function.Just a suggestion. Makes the code very clean in my opinion...
#16
Posted 07 September 2004 - 09:33 PM
Anyway, even though he presents the legacy method of rendering triangles, there are (better) alternatives. Triangle Scan Conversion using 2D Homogeneous Coordinates is more optimal for advanced rasterization...
#17
Posted 07 September 2004 - 09:54 PM
#18
Posted 15 September 2004 - 10:41 AM
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....
#19
Posted 15 September 2004 - 01:53 PM
#20
Posted 15 September 2004 - 04:48 PM
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












