diff options
author | rodri <rgl@antares-labs.eu> | 2024-07-05 18:21:18 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2024-07-05 18:21:18 +0000 |
commit | b7c3f36539569f5861b259b136ba2f9f14ae9e78 (patch) | |
tree | bf373888f3680c41c9d20d4452f6a619ac78191a | |
parent | 27724b010694549f17cad50158cf73ca035e9cad (diff) | |
download | 3dee-b7c3f36539569f5861b259b136ba2f9f14ae9e78.tar.gz 3dee-b7c3f36539569f5861b259b136ba2f9f14ae9e78.tar.bz2 3dee-b7c3f36539569f5861b259b136ba2f9f14ae9e78.zip |
adapt to the new texture interface and fix the identvshader.
the identvshader was used for the toon shader as well,
and that forced it to do a light computation when its
fragment shader won't ever use it. split it in two
vshaders, each for their own purpose, so we don't get
slow identity rendering.
-rw-r--r-- | med.c | 7 | ||||
-rw-r--r-- | vis.c | 29 |
2 files changed, 20 insertions, 16 deletions
@@ -92,7 +92,7 @@ LightSource light; /* global point light */ static int doprof; static int showhud; -Color (*tsampler)(Memimage*,Point2); +Color (*tsampler)(Texture*,Point2); static int min(int a, int b) @@ -358,7 +358,6 @@ phongshader(FSparams *sp) else{ /* TODO implement this on the VS instead and apply Gram-Schmidt here */ n = texture(sp->v.mtl->normalmap, sp->v.uv, neartexsampler); - n = linear2srgb(n); /* TODO not all textures require color space conversion */ n = normvec3(subpt3(mulpt3(n, 2), Vec3(1,1,1))); TBN.p = Pt3(0,0,0,1); @@ -396,11 +395,9 @@ phongshader(FSparams *sp) Point3 identvshader(VSparams *sp) { - sp->v->n = model2world(sp->su->entity, sp->v->n); - sp->v->p = model2world(sp->su->entity, sp->v->p); if(sp->v->mtl != nil) sp->v->c = sp->v->mtl->diffuse; - return world2clip(sp->su->camera, sp->v->p); + return world2clip(sp->su->camera, model2world(sp->su->entity, sp->v->p)); } Color @@ -91,7 +91,7 @@ static int doprof; static int inception; static int showhud; static int shownormals; -Color (*tsampler)(Memimage*,Point2); +Color (*tsampler)(Texture*,Point2); static int min(int a, int b) @@ -240,7 +240,6 @@ phongshader(FSparams *sp) else{ /* TODO implement this on the VS instead and apply Gram-Schmidt here */ n = texture(sp->v.mtl->normalmap, sp->v.uv, neartexsampler); - n = linear2srgb(n); /* TODO not all textures require color space conversion */ n = normvec3(subpt3(mulpt3(n, 2), Vec3(1,1,1))); TBN.p = Pt3(0,0,0,1); @@ -276,14 +275,13 @@ phongshader(FSparams *sp) } Point3 -identvshader(VSparams *sp) +toonvshader(VSparams *sp) { Point3 pos, lightdir; double intens; sp->v->n = model2world(sp->su->entity, sp->v->n); - sp->v->p = model2world(sp->su->entity, sp->v->p); - pos = sp->v->p; + pos = model2world(sp->su->entity, sp->v->p); lightdir = normvec3(subpt3(light.p, pos)); intens = fmax(0, dotvec3(sp->v->n, lightdir)); addvattr(sp->v, "intensity", VANumber, &intens); @@ -305,6 +303,14 @@ toonshader(FSparams *sp) return Pt3(intens, 0.6*intens, 0, 1); } +Point3 +identvshader(VSparams *sp) +{ + if(sp->v->mtl != nil) + sp->v->c = sp->v->mtl->diffuse; + return world2clip(sp->su->camera, model2world(sp->su->entity, sp->v->p)); +} + Color identshader(FSparams *sp) { @@ -424,7 +430,7 @@ Shadertab shadertab[] = { { "circle", ivshader, circleshader }, { "box", ivshader, boxshader }, { "sf", ivshader, sfshader }, - { "toon", identvshader, toonshader }, + { "toon", toonvshader, toonshader }, { "ident", identvshader, identshader }, { "gouraud", gouraudvshader, gouraudshader }, { "phong", phongvshader, phongshader }, @@ -506,8 +512,8 @@ renderproc(void *) fd = open("/dev/screen", OREAD); if(fd < 0) sysfatal("open: %r"); - freememimage(model->tex); - if((model->tex = readmemimage(fd)) == nil) + model->tex = alloctexture(sRGBTexture, nil); + if((model->tex->image = readmemimage(fd)) == nil) sysfatal("readmemimage: %r"); } @@ -525,9 +531,9 @@ renderproc(void *) nbsend(drawc, nil); t0 += Δt; if(inception){ - freememimage(model->tex); + freememimage(model->tex->image); seek(fd, 0, 0); - if((model->tex = readmemimage(fd)) == nil) + if((model->tex->image = readmemimage(fd)) == nil) sysfatal("readmemimage: %r"); } } @@ -868,7 +874,8 @@ threadmain(int argc, char *argv[]) fd = open(texpath, OREAD); if(fd < 0) sysfatal("open: %r"); - if((model->tex = readmemimage(fd)) == nil) + model->tex = alloctexture(sRGBTexture, nil); + if((model->tex->image = readmemimage(fd)) == nil) sysfatal("readmemimage: %r"); close(fd); } |