summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--camera.c4
-rw-r--r--graphics.h24
-rw-r--r--internal.h2
-rw-r--r--model.6.txt1
-rw-r--r--render.c25
-rw-r--r--vertex.c6
6 files changed, 33 insertions, 29 deletions
diff --git a/camera.c b/camera.c
index f89640f..607f033 100644
--- a/camera.c
+++ b/camera.c
@@ -16,7 +16,7 @@ skyboxvs(Shaderparams *sp)
{
Point3 p;
- addvattr(sp->v, "dir", VAPoint, &sp->v->p);
+ sp->setattr(sp, "dir", VAPoint, &sp->v->p);
/* only rotate along with the camera */
p = sp->v->p;
p.w = 0; p = world2vcs(sp->su->camera, p);
@@ -32,7 +32,7 @@ skyboxfs(Shaderparams *sp)
Vertexattr *va;
Color c;
- va = getvattr(sp->v, "dir");
+ va = sp->getattr(sp, "dir");
c = samplecubemap(sp->su->camera->scene->skybox, va->p, neartexsampler);
return c;
}
diff --git a/graphics.h b/graphics.h
index 3479c7d..047334d 100644
--- a/graphics.h
+++ b/graphics.h
@@ -51,6 +51,7 @@ typedef struct Color Color;
typedef struct Texture Texture;
typedef struct Cubemap Cubemap;
typedef struct Vertexattr Vertexattr;
+typedef struct Vertexattrs Vertexattrs;
typedef struct Vertex Vertex;
typedef struct LightSource LightSource;
typedef struct Material Material;
@@ -123,6 +124,12 @@ struct Vertexattr
};
};
+struct Vertexattrs
+{
+ Vertexattr *attrs;
+ ulong nattrs;
+};
+
struct Vertex
{
Point3 p; /* position */
@@ -131,10 +138,7 @@ struct Vertex
Point2 uv; /* texture coordinate */
Material *mtl;
Point3 tangent;
-
- /* TODO it'd be neat to use a dynamic hash table instead */
- Vertexattr *attrs; /* attributes (aka varyings) */
- ulong nattrs;
+ Vertexattrs; /* attributes (varyings) */
};
struct LightSource
@@ -219,15 +223,11 @@ struct Shaderparams
struct SUparams
{
Framebuf *fb;
+ Shadertab *stab;
Renderjob *job;
Camera *camera;
Entity *entity;
Primitive *eb, *ee;
-
- uvlong uni_time;
-
- Point3 (*vshader)(Shaderparams*);
- Color (*fshader)(Shaderparams*);
};
struct Shadertab
@@ -235,6 +235,7 @@ struct Shadertab
char *name;
Point3 (*vshader)(Shaderparams*); /* vertex shader */
Color (*fshader)(Shaderparams*); /* fragment shader */
+ Vertexattrs; /* uniforms */
};
struct Rendertime
@@ -387,6 +388,7 @@ void rmviewport(Viewport*);
/* render */
Renderer *initgraphics(void);
+void setuniform(Shadertab*, char*, int, void*);
/* xform */
Point3 model2world(Entity*, Point3);
@@ -421,10 +423,6 @@ Scene *dupscene(Scene*);
void delscene(Scene*);
void clearscene(Scene*);
-/* vertex */
-void addvattr(Vertex*, char*, int, void*);
-Vertexattr *getvattr(Vertex*, char*);
-
/* texture */
Texture *alloctexture(int, Memimage*);
Texture *duptexture(Texture*);
diff --git a/internal.h b/internal.h
index cbea04a..bf6883d 100644
--- a/internal.h
+++ b/internal.h
@@ -73,6 +73,8 @@ void lerpvertex(Vertex*, Vertex*, Vertex*, double);
void berpvertex(Vertex*, Vertex*, Vertex*, Vertex*, Point3);
void delvattrs(Vertex*);
void fprintvattrs(int, Vertex*);
+void addvattr(Vertexattrs*, char*, int, void*);
+Vertexattr *getvattr(Vertexattrs*, char*);
/* clip */
int clipprimitive(Primitive*, Primitive*);
diff --git a/model.6.txt b/model.6.txt
index 73fda4b..1f4ac2b 100644
--- a/model.6.txt
+++ b/model.6.txt
@@ -28,6 +28,7 @@ v vertex
T tangent
P primitive
mtl material definition
+ * name can contain spaces if quoted (see quote(2))
* ambient, diffuse and specular parameters take colors in linear RGB space
* diffusemap assumes the image colors are gamma-corrected (sRGBTexture)
* specularmap and normals both assume image contents are linear (RAWTexture)
diff --git a/render.c b/render.c
index cc5a201..672b4b5 100644
--- a/render.c
+++ b/render.c
@@ -12,8 +12,13 @@ Rectangle UR = {0,0,1,1};
static Vertexattr *
sparams_getuniform(Shaderparams *sp, char *id)
{
- USED(sp, id);
- return nil;
+ return getvattr(sp->su->stab, id);
+}
+
+void
+setuniform(Shadertab *st, char *id, int type, void *val)
+{
+ addvattr(st, id, type, val);
}
static Vertexattr *
@@ -202,7 +207,7 @@ rasterize(Rastertask *task)
fsp.v = &prim->v[0];
fsp.p = p;
- c = params->fshader(&fsp);
+ c = params->stab->fshader(&fsp);
if(c.a == 0) /* discard non-colors */
break;
if(ropts & RODepth)
@@ -268,7 +273,7 @@ rasterize(Rastertask *task)
lerpvertex(fsp.v, &prim->v[0], &prim->v[1], perc);
fsp.p = p;
- c = params->fshader(&fsp);
+ c = params->stab->fshader(&fsp);
if(c.a == 0) /* discard non-colors */
goto discard;
if(ropts & RODepth)
@@ -322,7 +327,7 @@ discard:
berpvertex(fsp.v, &prim->v[0], &prim->v[1], &prim->v[2], bc);
fsp.p = p;
- c = params->fshader(&fsp);
+ c = params->stab->fshader(&fsp);
if(c.a == 0) /* discard non-colors */
continue;
if(ropts & RODepth)
@@ -477,7 +482,7 @@ tiler(void *arg)
vsp.v = &p->v[0];
vsp.idx = 0;
- p->v[0].p = params->vshader(&vsp);
+ p->v[0].p = params->stab->vshader(&vsp);
if(!isvisible(p->v[0].p))
break;
@@ -512,7 +517,7 @@ tiler(void *arg)
vsp.v = &p->v[i];
vsp.idx = i;
- p->v[i].p = params->vshader(&vsp);
+ p->v[i].p = params->stab->vshader(&vsp);
}
if(!isvisible(p->v[0].p) || !isvisible(p->v[1].p)){
@@ -558,7 +563,7 @@ tiler(void *arg)
vsp.v = &p->v[i];
vsp.idx = i;
- p->v[i].p = params->vshader(&vsp);
+ p->v[i].p = params->stab->vshader(&vsp);
}
if(!isvisible(p->v[0].p) || !isvisible(p->v[1].p) || !isvisible(p->v[2].p)){
@@ -751,12 +756,10 @@ renderer(void *arg)
params = emalloc(sizeof *params);
memset(params, 0, sizeof *params);
params->fb = job->fb;
+ params->stab = job->shaders;
params->job = job;
params->camera = job->camera;
params->entity = ent;
- params->uni_time = time;
- params->vshader = job->shaders->vshader;
- params->fshader = job->shaders->fshader;
sendp(ep->paramsc, params);
}
/* mark end of job */
diff --git a/vertex.c b/vertex.c
index 715a4c2..318dcbb 100644
--- a/vertex.c
+++ b/vertex.c
@@ -8,7 +8,7 @@
#include "internal.h"
static void
-_addvattr(Vertex *v, Vertexattr *va)
+_addvattr(Vertexattrs *v, Vertexattr *va)
{
int i;
@@ -95,7 +95,7 @@ berpvertex(Vertex *v, Vertex *v0, Vertex *v1, Vertex *v2, Point3 bc)
}
void
-addvattr(Vertex *v, char *id, int type, void *val)
+addvattr(Vertexattrs *v, char *id, int type, void *val)
{
Vertexattr va;
@@ -110,7 +110,7 @@ addvattr(Vertex *v, char *id, int type, void *val)
}
Vertexattr *
-getvattr(Vertex *v, char *id)
+getvattr(Vertexattrs *v, char *id)
{
int i;