From 7fdc25da4dc85bc6902f6ecdabccf55e601146de Mon Sep 17 00:00:00 2001 From: rodri Date: Tue, 1 Oct 2024 20:22:18 +0000 Subject: use the new uniforms interface. --- procgen.c | 7 +++++-- shaders.inc | 27 +++++++++++++++++---------- vis.c | 7 +++++++ 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/procgen.c b/procgen.c index e66e815..d015ecb 100644 --- a/procgen.c +++ b/procgen.c @@ -107,15 +107,18 @@ vs(Shaderparams *sp) 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); 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; diff --git a/shaders.inc b/shaders.inc index 8b6f670..19a77c4 100644 --- a/shaders.inc +++ b/shaders.inc @@ -133,7 +133,6 @@ phongshader(Shaderparams *sp) 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 @@ phongshader(Shaderparams *sp) 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 @@ blinnshader(Shaderparams *sp) 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 @@ blinnshader(Shaderparams *sp) 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 @@ triangleshader(Shaderparams *sp) 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,18 +369,22 @@ circleshader(Shaderparams *sp) 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); 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); diff --git a/vis.c b/vis.c index 71384a7..7533eb4 100644 --- a/vis.c +++ b/vis.c @@ -172,6 +172,7 @@ renderproc(void *) { uvlong t0, Δt; int fd; + double time; threadsetname("renderproc"); @@ -187,15 +188,21 @@ renderproc(void *) t0 = nsec(); for(;;){ + time = t0; + setuniform(shader, "time", VANumber, &time); + shootcamera(maincam, shader); + Δt = nsec() - t0; if(Δt > HZ2MS(60)*1000000ULL){ lockdisplay(display); 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); -- cgit v1.2.3