shithub: 3dee

Download patch

ref: fe76590b8d9e7ff1b23a5b4ada446e8540c8a602
parent: b7c3f36539569f5861b259b136ba2f9f14ae9e78
author: rodri <[email protected]>
date: Tue Jul 9 17:00:40 EDT 2024

adapt to recent changes in libgraphics.

also set the normals correctly in the phong shader
after mapping from tangent space. that way we can
see the actual normals being used in the normals
framebuffer.

--- a/med.c
+++ b/med.c
@@ -284,9 +284,9 @@
 	Color tc, c;
 
 	if(sp->v.mtl != nil && sp->v.mtl->diffusemap != nil && sp->v.uv.w != 0)
-		tc = texture(sp->v.mtl->diffusemap, sp->v.uv, tsampler);
+		tc = sampletexture(sp->v.mtl->diffusemap, sp->v.uv, tsampler);
 	else if(sp->su->entity->mdl->tex != nil && sp->v.uv.w != 0)
-		tc = texture(sp->su->entity->mdl->tex, sp->v.uv, tsampler);
+		tc = sampletexture(sp->su->entity->mdl->tex, sp->v.uv, tsampler);
 	else
 		tc = Pt3(1,1,1,1);
 
@@ -357,7 +357,7 @@
 		n = sp->v.n;
 	else{
 		/* TODO implement this on the VS instead and apply Gram-Schmidt here */
-		n = texture(sp->v.mtl->normalmap, sp->v.uv, neartexsampler);
+		n = sampletexture(sp->v.mtl->normalmap, sp->v.uv, neartexsampler);
 		n = normvec3(subpt3(mulpt3(n, 2), Vec3(1,1,1)));
 
 		TBN.p = Pt3(0,0,0,1);
@@ -366,6 +366,7 @@
 		TBN.by = crossvec3(TBN.bz, TBN.bx);	/* B */
 
 		n = normvec3(invrframexform3(n, TBN));
+		sp->v.n = n;
 	}
 
 	Kd = fmax(0, dotvec3(n, lightdir));
@@ -379,9 +380,9 @@
 	specular = modulapt3(specular, m.specular);
 
 	if(sp->v.mtl != nil && sp->v.mtl->diffusemap != nil && sp->v.uv.w != 0)
-		tc = texture(sp->v.mtl->diffusemap, sp->v.uv, tsampler);
+		tc = sampletexture(sp->v.mtl->diffusemap, sp->v.uv, tsampler);
 	else if(sp->su->entity->mdl->tex != nil && sp->v.uv.w != 0)
-		tc = texture(sp->su->entity->mdl->tex, sp->v.uv, tsampler);
+		tc = sampletexture(sp->su->entity->mdl->tex, sp->v.uv, tsampler);
 	else
 		tc = Pt3(1,1,1,1);
 
@@ -406,9 +407,9 @@
 	Color tc, c;
 
 	if(sp->v.mtl != nil && sp->v.mtl->diffusemap != nil && sp->v.uv.w != 0)
-		tc = texture(sp->v.mtl->diffusemap, sp->v.uv, tsampler);
+		tc = sampletexture(sp->v.mtl->diffusemap, sp->v.uv, tsampler);
 	else if(sp->su->entity->mdl->tex != nil && sp->v.uv.w != 0)
-		tc = texture(sp->su->entity->mdl->tex, sp->v.uv, tsampler);
+		tc = sampletexture(sp->su->entity->mdl->tex, sp->v.uv, tsampler);
 	else
 		tc = Pt3(1,1,1,1);
 
@@ -467,14 +468,8 @@
 void
 redraw(void)
 {
-	static Image *bg;
-
-	if(bg == nil)
-		bg = eallocimage(display, UR, RGB24, 1, 0x888888FF);
-
 	lockdisplay(display);
 	cam.vp->draw(cam.vp, screenb);
-	draw(screen, screen->r, bg, nil, ZP);
 	draw(screen, screen->r, screenb, nil, ZP);
 	if(showhud)
 		drawstats();
@@ -801,7 +796,7 @@
 	if((mctl = initmouse(nil, screen)) == nil)
 		sysfatal("initmouse: %r");
 
-	screenb = eallocimage(display, rectsubpt(screen->r, screen->r.min), RGBA32, 0, DNofill);
+	screenb = eallocimage(display, rectsubpt(screen->r, screen->r.min), XRGB32, 0, DNofill);
 	v = mkviewport(screenb->r);
 	placecamera(&cam, camcfg.p, camcfg.lookat, camcfg.up);
 	configcamera(&cam, v, camcfg.fov, camcfg.clipn, camcfg.clipf, camcfg.ptype);
--- a/solar.c
+++ b/solar.c
@@ -350,7 +350,7 @@
 identshader(FSparams *sp)
 {
 	if(sp->v.mtl != nil && sp->v.mtl->diffusemap != nil && sp->v.uv.w != 0)
-		return texture(sp->v.mtl->diffusemap, sp->v.uv, neartexsampler);
+		return sampletexture(sp->v.mtl->diffusemap, sp->v.uv, neartexsampler);
 	return sp->v.c;
 }
 
@@ -814,7 +814,7 @@
 		else
 			cmds[i].r = rectaddpt(cmds[i].r, Pt(cmds[i-1].r.max.x+Cmdmargin,cmds[i-1].r.min.y));
 	}
-	screenb = eallocimage(display, viewr, RGBA32, 0, DNofill);
+	screenb = eallocimage(display, viewr, XRGB32, 0, DNofill);
 	v = mkviewport(screenb->r);
 	placecamera(&camera, cameracfg.p, cameracfg.lookat, cameracfg.up);
 	configcamera(&camera, v, cameracfg.fov, cameracfg.clipn, cameracfg.clipf, cameracfg.ptype);
--- a/vis.c
+++ b/vis.c
@@ -162,9 +162,9 @@
 	Color tc, c;
 
 	if(sp->v.mtl != nil && sp->v.mtl->diffusemap != nil && sp->v.uv.w != 0)
-		tc = texture(sp->v.mtl->diffusemap, sp->v.uv, tsampler);
+		tc = sampletexture(sp->v.mtl->diffusemap, sp->v.uv, tsampler);
 	else if(sp->su->entity->mdl->tex != nil && sp->v.uv.w != 0)
-		tc = texture(sp->su->entity->mdl->tex, sp->v.uv, tsampler);
+		tc = sampletexture(sp->su->entity->mdl->tex, sp->v.uv, tsampler);
 	else
 		tc = Pt3(1,1,1,1);
 
@@ -239,7 +239,7 @@
 		n = sp->v.n;
 	else{
 		/* TODO implement this on the VS instead and apply Gram-Schmidt here */
-		n = texture(sp->v.mtl->normalmap, sp->v.uv, neartexsampler);
+		n = sampletexture(sp->v.mtl->normalmap, sp->v.uv, neartexsampler);
 		n = normvec3(subpt3(mulpt3(n, 2), Vec3(1,1,1)));
 
 		TBN.p = Pt3(0,0,0,1);
@@ -248,6 +248,7 @@
 		TBN.by = crossvec3(TBN.bz, TBN.bx);	/* B */
 
 		n = normvec3(invrframexform3(n, TBN));
+		sp->v.n = n;
 	}
 
 	Kd = fmax(0, dotvec3(n, lightdir));
@@ -261,9 +262,9 @@
 	specular = modulapt3(specular, m.specular);
 
 	if(sp->v.mtl != nil && sp->v.mtl->diffusemap != nil && sp->v.uv.w != 0)
-		tc = texture(sp->v.mtl->diffusemap, sp->v.uv, tsampler);
+		tc = sampletexture(sp->v.mtl->diffusemap, sp->v.uv, tsampler);
 	else if(sp->su->entity->mdl->tex != nil && sp->v.uv.w != 0)
-		tc = texture(sp->su->entity->mdl->tex, sp->v.uv, tsampler);
+		tc = sampletexture(sp->su->entity->mdl->tex, sp->v.uv, tsampler);
 	else
 		tc = Pt3(1,1,1,1);
 
@@ -317,9 +318,9 @@
 	Color tc, c;
 
 	if(sp->v.mtl != nil && sp->v.mtl->diffusemap != nil && sp->v.uv.w != 0)
-		tc = texture(sp->v.mtl->diffusemap, sp->v.uv, tsampler);
+		tc = sampletexture(sp->v.mtl->diffusemap, sp->v.uv, tsampler);
 	else if(sp->su->entity->mdl->tex != nil && sp->v.uv.w != 0)
-		tc = texture(sp->su->entity->mdl->tex, sp->v.uv, tsampler);
+		tc = sampletexture(sp->su->entity->mdl->tex, sp->v.uv, tsampler);
 	else
 		tc = Pt3(1,1,1,1);
 
@@ -481,17 +482,11 @@
 void
 redraw(void)
 {
-	static Image *bg;
-
-	if(bg == nil)
-		bg = eallocimage(display, UR, RGB24, 1, 0x888888FF);
-
 	lockdisplay(display);
 	if(shownormals)
 		maincam->vp->fbctl->drawnormals(maincam->vp->fbctl, screenb);
 	else
 		maincam->vp->draw(maincam->vp, screenb);
-	draw(screen, screen->r, bg, nil, ZP);
 	draw(screen, screen->r, screenb, nil, ZP);
 	if(showhud)
 		drawstats();
@@ -892,7 +887,7 @@
 	if((mctl = initmouse(nil, screen)) == nil)
 		sysfatal("initmouse: %r");
 
-	screenb = eallocimage(display, rectsubpt(screen->r, screen->r.min), RGBA32, 0, DNofill);
+	screenb = eallocimage(display, rectsubpt(screen->r, screen->r.min), XRGB32, 0, DNofill);
 	for(i = 0; i < nelem(cams); i++){
 		v = mkviewport(screenb->r);
 		placecamera(&cams[i], camcfgs[i].p, camcfgs[i].lookat, camcfgs[i].up);