summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2024-07-09 21:00:40 +0000
committerrodri <rgl@antares-labs.eu>2024-07-09 21:00:40 +0000
commitfe76590b8d9e7ff1b23a5b4ada446e8540c8a602 (patch)
tree38b1fb02456be936d6f1dd5de02749f12f403052
parentb7c3f36539569f5861b259b136ba2f9f14ae9e78 (diff)
download3dee-fe76590b8d9e7ff1b23a5b4ada446e8540c8a602.tar.gz
3dee-fe76590b8d9e7ff1b23a5b4ada446e8540c8a602.tar.bz2
3dee-fe76590b8d9e7ff1b23a5b4ada446e8540c8a602.zip
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.
-rw-r--r--med.c23
-rw-r--r--solar.c4
-rw-r--r--vis.c23
3 files changed, 20 insertions, 30 deletions
diff --git a/med.c b/med.c
index c3aa3eb..c4c0797 100644
--- a/med.c
+++ b/med.c
@@ -284,9 +284,9 @@ gouraudshader(FSparams *sp)
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 @@ phongshader(FSparams *sp)
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 @@ phongshader(FSparams *sp)
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 @@ phongshader(FSparams *sp)
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 @@ identshader(FSparams *sp)
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 @@ drawstats(void)
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 @@ threadmain(int argc, char *argv[])
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);
diff --git a/solar.c b/solar.c
index 5fa5497..f9b2712 100644
--- a/solar.c
+++ b/solar.c
@@ -350,7 +350,7 @@ Color
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 @@ threadmain(int argc, char *argv[])
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);
diff --git a/vis.c b/vis.c
index d8a00e6..e43c170 100644
--- a/vis.c
+++ b/vis.c
@@ -162,9 +162,9 @@ gouraudshader(FSparams *sp)
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 @@ phongshader(FSparams *sp)
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 @@ phongshader(FSparams *sp)
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 @@ phongshader(FSparams *sp)
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 @@ identshader(FSparams *sp)
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 @@ drawstats(void)
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 @@ threadmain(int argc, char *argv[])
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);