Skip to content

Commit

Permalink
Improved rendering performance by disabling z-fight when a line super…
Browse files Browse the repository at this point in the history
…cedes a primitive.
  • Loading branch information
elfprince13 committed Feb 8, 2016
1 parent 19ef652 commit 35b18e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 4 additions & 3 deletions ScanLineRender/ScanLineRender/Primitive.c
Expand Up @@ -52,6 +52,7 @@ void makeQuad(Primitive *o, Color c, const Edge e1, const Edge e2, const Edge e3

float getZForXY(const Primitive *p, float x, float y){
Point **const boundary = p->boundary;
float ret;
if(p->arity == 1){
const Point *const vs = boundary[START],
* ve = boundary[END];
Expand All @@ -71,7 +72,7 @@ float getZForXY(const Primitive *p, float x, float y){
const float xEst = (dx == 0) ? min(0, dz) : (xNumer / dx),
yEst = (dy == 0) ? min(0, dz) : (yNumer / dy);

return sz + (xEst + yEst) / 2;
ret = sz + (xEst + yEst) / 2;
} else {
Point **const e1 = boundary,
**const e2 = e1 + 1;
Expand All @@ -97,9 +98,9 @@ float getZForXY(const Primitive *p, float x, float y){
-nz * us->z,
numer = (-d - nx * x - ny * y);

return (nz == 0) ? ((numer > 0) ? HUGE_VAL : -HUGE_VAL) : (numer / nz) ;
ret = (nz == 0) ? ((numer > 0) ? HUGE_VAL : -HUGE_VAL) : (numer / nz) ;
}

return ret;
}


Expand Down
8 changes: 5 additions & 3 deletions ScanLineRender/ScanLineRender/ScanlineRenderer.c
Expand Up @@ -191,10 +191,12 @@ void render(Color *raster, int lineWidth, int numLines, const rb_red_blk_tree *s
if(++j == 1 || testZ <= bestZ){
dPrintf(("\t\tHit: %f <= %f || "SZF" == 1 for %s\n",testZ, bestZ, j,fmtColor(prim->color)));
if (testZ == bestZ && j != 1) {
zFight = true;
if (prim->arity == 1) {
zFight = curDraw->arity == 1;
curDraw = prim;
solitary = RBSetContains(&deFlags, prim);
} else {
zFight = curDraw->arity != 1;
}
} else {
zFight = false;
Expand All @@ -209,10 +211,10 @@ void render(Color *raster, int lineWidth, int numLines, const rb_red_blk_tree *s
#ifndef NDEBUG
if(nextEdge || solitary){
#endif
const int drawWidth = (zFight || solitary) ? 1 : ((nextEdge ? nextX : lineWidth) - curPixel),
const int drawWidth = (zFight || solitary) ? 1 : ((nextEdge ? nextX : lineWidth) - curPixel),
stopPixel = curPixel + min(lineWidth - curPixel,
max(0, drawWidth));
const Color drawColor = curDraw->color;
const Color drawColor = /*(uint16_t)roundOwn(63 * bestZ / 100) << 5;*/curDraw->color;
dPrintf(("Drawing %d @ (%d, %d)\n",drawWidth,curPixel,line));
dPrintf(("Drawing %d @ (%d, %d)\n",stopPixel - curPixel,curPixel,line));
while(curPixel < stopPixel){
Expand Down

0 comments on commit 35b18e5

Please sign in to comment.