summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2024-09-13 13:16:06 +0000
committerrodri <rgl@antares-labs.eu>2024-09-13 13:16:06 +0000
commitf89e4e8e5ddcbf7de6aa8310f11204e5e019f7cb (patch)
tree18f39bdec0a5c74bdf4b3ed6dff5d002765016b0
parentbe27f4dff3e949b012d7fac9b872fc911123cf3a (diff)
downloadlibgraphics-f89e4e8e5ddcbf7de6aa8310f11204e5e019f7cb.tar.gz
libgraphics-f89e4e8e5ddcbf7de6aa8310f11204e5e019f7cb.tar.bz2
libgraphics-f89e4e8e5ddcbf7de6aa8310f11204e5e019f7cb.zip
render: discard non-colors.
-rw-r--r--render.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/render.c b/render.c
index 9495f30..52328ab 100644
--- a/render.c
+++ b/render.c
@@ -196,15 +196,16 @@ rasterize(Rastertask *task)
p = Pt(prim->v[0].p.x, prim->v[0].p.y);
z = fclamp(prim->v[0].p.z, 0, 1);
- if(params->camera->enabledepth){
- if(z <= getdepth(zr, p))
- break;
- putdepth(zr, p, z);
- }
+ if(params->camera->enabledepth && z <= getdepth(zr, p))
+ break;
fsp.v = &prim->v[0];
fsp.p = p;
c = params->fshader(&fsp);
+ if(c.a == 0) /* discard non-colors */
+ break;
+ if(params->camera->enabledepth)
+ putdepth(zr, p, z);
if(params->camera->enableAbuff)
pushtoAbuf(params->fb, p, c, z);
else
@@ -245,11 +246,9 @@ rasterize(Rastertask *task)
z = flerp(prim->v[0].p.z, prim->v[1].p.z, perc);
/* TODO get rid of the bounds check and make sure the clipping doesn't overflow */
- if(params->camera->enabledepth){
- if(!ptinrect(p, params->fb->r) || z <= getdepth(zr, p))
- goto discard;
- putdepth(zr, p, z);
- }
+ if(params->camera->enabledepth &&
+ !ptinrect(p, params->fb->r) || z <= getdepth(zr, p))
+ goto discard;
/* interpolate z⁻¹ and get actual z */
pcz = flerp(prim->v[0].p.w, prim->v[1].p.w, perc);
@@ -261,6 +260,10 @@ rasterize(Rastertask *task)
fsp.p = p;
c = params->fshader(&fsp);
+ if(c.a == 0) /* discard non-colors */
+ goto discard;
+ if(params->camera->enabledepth)
+ putdepth(zr, p, z);
if(params->camera->enableAbuff)
pushtoAbuf(params->fb, p, c, z);
else
@@ -288,11 +291,8 @@ discard:
continue;
z = fberp(prim->v[0].p.z, prim->v[1].p.z, prim->v[2].p.z, bc);
- if(params->camera->enabledepth){
- if(z <= getdepth(zr, p))
- continue;
- putdepth(zr, p, z);
- }
+ if(params->camera->enabledepth && z <= getdepth(zr, p))
+ continue;
/* interpolate z⁻¹ and get actual z */
pcz = fberp(prim->v[0].p.w, prim->v[1].p.w, prim->v[2].p.w, bc);
@@ -306,6 +306,10 @@ discard:
fsp.p = p;
c = params->fshader(&fsp);
+ if(c.a == 0) /* discard non-colors */
+ continue;
+ if(params->camera->enabledepth)
+ putdepth(zr, p, z);
if(params->camera->enableAbuff)
pushtoAbuf(params->fb, p, c, z);
else