shithub: 3dee

Download patch

ref: 7fdc25da4dc85bc6902f6ecdabccf55e601146de
parent: a6ea992058998552ad308a04261a53e5e2c2d523
author: rodri <rgl@antares-labs.eu>
date: Tue Oct 1 16:22:18 EDT 2024

use the new uniforms interface.

--- a/procgen.c
+++ b/procgen.c
@@ -107,8 +107,9 @@
 static Color
 fs(Shaderparams *sp)
 {
+	Vertexattr *va;
 	Point2 uv;
-	double dt, shift, h;
+	double dt, shift, h, time;
 
 	uv = Pt2(sp->p.x,sp->p.y,1);
 	uv.x /= Dx(sp->su->fb->r);
@@ -115,7 +116,9 @@
 	uv.y /= Dy(sp->su->fb->r);
 	uv.y = 1 - uv.y;		/* make [0 0] the bottom-left corner */
 
-	dt = sp->su->uni_time/1e9;
+	va = sp->getuniform(sp, "time");
+	time = va == nil? 0: va->n;
+	dt = time/1e9;
 	shift = 0.09*dt + 0.2;
 	uv.x += shift;
 
--- a/shaders.inc
+++ b/shaders.inc
@@ -133,7 +133,6 @@
 		TBN.by = crossvec3(TBN.bz, TBN.bx);	/* B */
 
 		n = normvec3(invrframexform3(n, TBN));
-		sp->v->n = n;
 	}
 
 	if(sp->su->entity->mdl->tex != nil && sp->v->uv.w != 0)
@@ -157,8 +156,8 @@
 	specular = mulpt3(lightc, spec*Ks);
 	specular = modulapt3(specular, m.specular);
 
-	sp->v->n.w = 1;
-	sp->toraster(sp, "normals", &sp->v->n);
+	n.w = 1;
+	sp->toraster(sp, "normals", &n);
 
 	c = addpt3(ambient, addpt3(diffuse, specular));
 	c.a = m.diffuse.a;
@@ -212,7 +211,6 @@
 		TBN.by = crossvec3(TBN.bz, TBN.bx);	/* B */
 
 		n = normvec3(invrframexform3(n, TBN));
-		sp->v->n = n;
 	}
 
 	if(sp->su->entity->mdl->tex != nil && sp->v->uv.w != 0)
@@ -236,8 +234,8 @@
 	specular = mulpt3(lightc, spec*Ks);
 	specular = modulapt3(specular, m.specular);
 
-	sp->v->n.w = 1;
-	sp->toraster(sp, "normals", &sp->v->n);
+	n.w = 1;
+	sp->toraster(sp, "normals", &n);
 
 	c = addpt3(ambient, addpt3(diffuse, specular));
 	c.a = m.diffuse.a;
@@ -346,14 +344,19 @@
 Color
 circleshader(Shaderparams *sp)
 {
+	Vertexattr *va;
 	Point2 uv;
-	double r, d;
+	double r, d, time;
 
 	uv = Pt2(sp->p.x,sp->p.y,1);
 	uv.x /= Dx(sp->su->fb->r);
 	uv.y /= Dy(sp->su->fb->r);
+
+	va = sp->getuniform(sp, "time");
+	time = va == nil? 0: va->n;
+
 //	r = 0.3;
-	r = 0.3*fabs(sin(sp->su->uni_time/1e9));
+	r = 0.3*fabs(sin(time/1e9));
 	d = vec2len(subpt2(uv, Vec2(0.5,0.5)));
 
 	if(d > r + r*0.05 || d < r - r*0.05)
@@ -366,8 +369,9 @@
 Color
 sfshader(Shaderparams *sp)
 {
+	Vertexattr *va;
 	Point2 uv;
-	double y, pct;
+	double y, pct, time;
 
 	uv = Pt2(sp->p.x,sp->p.y,1);
 	uv.x /= Dx(sp->su->fb->r);
@@ -374,10 +378,13 @@
 	uv.y /= Dy(sp->su->fb->r);
 	uv.y = 1 - uv.y;		/* make [0 0] the bottom-left corner */
 
+	va = sp->getuniform(sp, "time");
+	time = va == nil? 0: va->n;
+
 //	y = step(0.5, uv.x);
 //	y = pow(uv.x, 5);
 //	y = sin(uv.x);
-	y = sin(uv.x*sp->su->uni_time/1e8)/2.0 + 0.5;
+	y = sin(uv.x*time/1e8)/2.0 + 0.5;
 //	y = smoothstep(0.1, 0.9, uv.x);
 	pct = smoothstep(y-0.02, y, uv.y) - smoothstep(y, y+0.02, uv.y);
 
--- a/vis.c
+++ b/vis.c
@@ -172,6 +172,7 @@
 {
 	uvlong t0, Δt;
 	int fd;
+	double time;
 
 	threadsetname("renderproc");
 
@@ -187,7 +188,11 @@
 
 	t0 = nsec();
 	for(;;){
+		time = t0;
+		setuniform(shader, "time", VANumber, &time);
+
 		shootcamera(maincam, shader);
+
 		Δt = nsec() - t0;
 		if(Δt > HZ2MS(60)*1000000ULL){
 			lockdisplay(display);
@@ -194,8 +199,10 @@
 			draw(screenb, screenb->r, clr, nil, ZP);
 			maincam->view->draw(maincam->view, screenb, curraster);
 			unlockdisplay(display);
+
 			nbsend(drawc, nil);
 			t0 += Δt;
+
 			if(inception){
 				freememimage(model->tex->image);
 				seek(fd, 0, 0);