summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2023-12-21 16:01:34 +0000
committerrodri <rgl@antares-labs.eu>2023-12-21 16:01:34 +0000
commit752d971d8ff5ffa2afc250830b60c07ceeaba336 (patch)
tree161faf3f67021c9a65a4117a01262bbbe39c24ee
parent5d50d34ac95d2a63113697047afee180e5bd1e6c (diff)
downloadtinyrend-752d971d8ff5ffa2afc250830b60c07ceeaba336.tar.gz
tinyrend-752d971d8ff5ffa2afc250830b60c07ceeaba336.tar.bz2
tinyrend-752d971d8ff5ffa2afc250830b60c07ceeaba336.zip
experiments with sdfs and texture mapping.
-rw-r--r--main.c49
-rw-r--r--mdl/def.obj8
2 files changed, 38 insertions, 19 deletions
diff --git a/main.c b/main.c
index 5755065..403aa93 100644
--- a/main.c
+++ b/main.c
@@ -770,20 +770,6 @@ shade(Framebuf *fb, Shader *s)
chanfree(donec);
}
-Point3
-ivshader(VSparams *sp)
-{
- Matrix3 M, V;
-
- identity3(M);
- identity3(V);
- mulm3(M, rota);
- mulm3(V, view);
- mulm3(V, M);
-
- return xform3(*sp->p, V);
-}
-
Memimage *
triangleshader(FSparams *sp)
{
@@ -819,16 +805,17 @@ Memimage *
circleshader(FSparams *sp)
{
Point2 uv;
- double r;
+ double r, d;
uchar cbuf[4];
uv = Pt2(sp->p.x,sp->p.y,1);
uv.x /= Dx(sp->su->fb->r);
uv.y /= Dy(sp->su->fb->r);
// r = 0.3;
- r = 0.3*sin(sp->su->uni_time/1e9);
+ r = 0.3*fabs(sin(sp->su->uni_time/1e9));
+ d = vec2len(subpt2(uv, Vec2(0.5,0.5)));
- if(vec2len(subpt2(uv, Vec2(0.5,0.5))) > r)
+ if(d > r + r*0.05 || d < r - r*0.05)
return nil;
cbuf[0] = 0xFF;
@@ -898,6 +885,33 @@ boxshader(FSparams *sp)
return sp->frag;
}
+Point3
+ivshader(VSparams *sp)
+{
+ Matrix3 M, V, S = {
+ scale, 0, 0, 0,
+ 0, scale, 0, 0,
+ 0, 0, scale, 0,
+ 0, 0, 0, 1,
+ };
+
+ identity3(M);
+ identity3(V);
+ mulm3(M, rota);
+ mulm3(M, S);
+ mulm3(V, view);
+ mulm3(V, M);
+
+ return xform3(*sp->p, V);
+}
+
+Memimage *
+identshader(FSparams *sp)
+{
+ memfillcolor(sp->frag, *(ulong*)sp->cbuf);
+ return sp->frag;
+}
+
Shader shadertab[] = {
{ "triangle", ivshader, triangleshader },
{ "circle", ivshader, circleshader },
@@ -905,6 +919,7 @@ Shader shadertab[] = {
{ "sf", ivshader, sfshader },
{ "gouraud", vertshader, gouraudshader },
{ "toon", vertshader, toonshader },
+ { "ident", vertshader, identshader },
};
Shader *
getshader(char *name)
diff --git a/mdl/def.obj b/mdl/def.obj
index 48cc560..4c6dfa5 100644
--- a/mdl/def.obj
+++ b/mdl/def.obj
@@ -2,5 +2,9 @@ v -100 -100 0
v 100 -100 0
v -100 100 0
v 100 100 0
-f 1 2 3
-f 4 3 2
+vt 0 0
+vt 1 0
+vt 0 1
+vt 1 1
+f 1/1 2/2 3/3
+f 4/4 3/3 2/2