shithub: 3dee

Download patch

ref: 799c2a25df4283ba46747864dc669c8905b540fc
parent: 3b06ad551d6706907b0d6cbf25807e1ef7e62ca9
author: rodri <rgl@antares-labs.eu>
date: Thu Aug 29 15:27:26 EDT 2024

use the new raster interface.

--- a/med.c
+++ b/med.c
@@ -100,7 +100,7 @@
 	0,1,0,0,
 	0,0,1,0
 };
-LightSource light;		/* global point light */
+LightSource light;	/* global point light */
 
 static int doprof;
 static int showhud;
@@ -515,8 +515,8 @@
 		Δt = nsec() - t0;
 		if(Δt > HZ2MS(60)*1000000ULL){
 			lockdisplay(display);
-			cam->view->draw(cam->view, screenb);
-			compass.cam->view->draw(compass.cam->view, screenb);
+			cam->view->draw(cam->view, screenb, nil);
+			compass.cam->view->draw(compass.cam->view, screenb, nil);
 			unlockdisplay(display);
 			nbsend(drawc, nil);
 			t0 += Δt;
--- a/procgen.c
+++ b/procgen.c
@@ -100,7 +100,7 @@
 static Point3
 vs(VSparams *sp)
 {
-	return vcs2clip(sp->su->camera, sp->v->p);
+	return sp->v->p;
 }
 
 static Color
@@ -175,11 +175,11 @@
 	placecamera(cam, scn, Pt3(0,0,0,1), Vec3(0,0,-1), Vec3(0,1,0));
 
 	quad[0].type = quad[1].type = PTriangle;
-	quad[0].v[0].p = viewport2vcs(cam, Pt3(out->r.min.x, out->r.max.y, 1, 1));
-	quad[0].v[1].p = viewport2vcs(cam, Pt3(out->r.max.x, out->r.min.y, 1, 1));
-	quad[0].v[2].p = viewport2vcs(cam, Pt3(out->r.min.x, out->r.min.y, 1, 1));
+	quad[0].v[0].p = vcs2clip(cam, viewport2vcs(cam, Pt3(out->r.min.x, out->r.max.y, 1, 1)));
+	quad[0].v[1].p = vcs2clip(cam, viewport2vcs(cam, Pt3(out->r.max.x, out->r.min.y, 1, 1)));
+	quad[0].v[2].p = vcs2clip(cam, viewport2vcs(cam, Pt3(out->r.min.x, out->r.min.y, 1, 1)));
 	quad[1].v[0].p = quad[0].v[0].p;
-	quad[1].v[1].p = viewport2vcs(cam, Pt3(out->r.max.x, out->r.max.y, 1, 1));
+	quad[1].v[1].p = vcs2clip(cam, viewport2vcs(cam, Pt3(out->r.max.x, out->r.max.y, 1, 1)));
 	quad[1].v[2].p = quad[0].v[1].p;
 	mdl->addprim(mdl, quad[0]);
 	mdl->addprim(mdl, quad[1]);
@@ -186,7 +186,7 @@
 	scn->addent(scn, ent);
 
 	do shootcamera(cam, &shaders); while(skip--);
-	cam->view->memdraw(cam->view, out);
+	cam->view->memdraw(cam->view, out, nil);
 	writememimage(1, out);
 
 	threadexitsall(nil);
--- a/solar.c
+++ b/solar.c
@@ -573,7 +573,7 @@
 		Δt = nsec() - t0;
 		if(Δt > HZ2MS(60)*1000000ULL){
 			lockdisplay(display);
-			camera->view->draw(camera->view, screenb);
+			camera->view->draw(camera->view, screenb, nil);
 			unlockdisplay(display);
 			nbsend(drawc, nil);
 			t0 += Δt;
--- a/vis.c
+++ b/vis.c
@@ -166,6 +166,8 @@
 	else
 		tc = Pt3(1,1,1,1);
 
+	sp->toraster(sp, "normals", &sp->v.n);
+
 	return modulapt3(sp->v.c, tc);
 }
 
@@ -264,6 +266,8 @@
 	specular = mulpt3(lightc, spec*Ks);
 	specular = modulapt3(specular, m.specular);
 
+	sp->toraster(sp, "normals", &sp->v.n);
+
 	c = addpt3(ambient, addpt3(diffuse, specular));
 	c.a = m.diffuse.a;
 	return c;
@@ -336,6 +340,8 @@
 	specular = mulpt3(lightc, spec*Ks);
 	specular = modulapt3(specular, m.specular);
 
+	sp->toraster(sp, "normals", &sp->v.n);
+
 	c = addpt3(ambient, addpt3(diffuse, specular));
 	c.a = m.diffuse.a;
 	return c;
@@ -371,6 +377,8 @@
 		 intens > 0.30? 0.45:
 		 intens > 0.15? 0.30: 0.15;
 
+	sp->toraster(sp, "normals", &sp->v.n);
+
 	return Pt3(intens, 0.6*intens, 0, 1);
 }
 
@@ -394,6 +402,8 @@
 	else
 		tc = Pt3(1,1,1,1);
 
+	sp->toraster(sp, "normals", &sp->v.n);
+
 	return modulapt3(sp->v.c, tc);
 }
 
@@ -601,10 +611,7 @@
 		Δt = nsec() - t0;
 		if(Δt > HZ2MS(60)*1000000ULL){
 			lockdisplay(display);
-			if(shownormals)
-				maincam->view->fbctl->drawnormals(maincam->view->fbctl, screenb);
-			else
-				maincam->view->draw(maincam->view, screenb);
+			maincam->view->draw(maincam->view, screenb, shownormals? "normals": nil);
 			unlockdisplay(display);
 			nbsend(drawc, nil);
 			t0 += Δt;
@@ -659,6 +666,7 @@
 		}
 	}else{	/* DBG only */
 		Framebuf *fb;
+		Raster *cr, *zr, *nr;
 		Point2 p₂;
 		Point p;
 		Color c, n;
@@ -675,9 +683,12 @@
 			return;
 		qlock(maincam->view->fbctl);
 		fb = maincam->view->getfb(maincam->view);
-		c = ul2col(fb->cb[p.y*Dx(fb->r) + p.x]);
-		n = ul2col(fb->nb[p.y*Dx(fb->r) + p.x]);
-		z = fb->zb[p.y*Dx(fb->r) + p.x];
+		cr = fb->rasters;
+		zr = cr->next;
+		nr = maincam->view->fetchraster(maincam->view, "normals");
+		c = ul2col(cr->data[p.y*Dx(fb->r) + p.x]);
+		n = nr != nil? ul2col(nr->data[p.y*Dx(fb->r) + p.x]): Vec3(0,0,0);
+		z = *(float*)&zr->data[p.y*Dx(fb->r) + p.x];
 //		abuf = &fb->abuf;
 //		if(abuf->stk != nil){
 //			astk = &abuf->stk[p.y*Dx(fb->r) + p.x];
@@ -1112,6 +1123,7 @@
 			sysfatal("Cam: %r");
 		placecamera(cams[i], scene, camcfgs[i].p, camcfgs[i].lookat, camcfgs[i].up);
 		cams[i]->view->setscale(cams[i]->view, scale, scale);
+		cams[i]->view->createraster(cams[i]->view, "normals", COLOR32);
 
 		if(scale == 2)
 			cams[i]->view->setscalefilter(cams[i]->view, UFScale2x);