summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2024-03-06 22:09:24 +0000
committerrodri <rgl@antares-labs.eu>2024-03-06 22:09:24 +0000
commit2b19d1a580c0e281010fd200128081b8e3f4af7f (patch)
tree87d771a8445c090070475739f3abaff3f587a259
parente848ff8f07c022537fd6b369db8f126251e9b96e (diff)
downloadlibgraphics-2b19d1a580c0e281010fd200128081b8e3f4af7f.tar.gz
libgraphics-2b19d1a580c0e281010fd200128081b8e3f4af7f.tar.bz2
libgraphics-2b19d1a580c0e281010fd200128081b8e3f4af7f.zip
pass material properties to the fshader.
this way users can refer to per-surface material features when shading pixels.
-rw-r--r--render.c2
-rw-r--r--vertex.c2
2 files changed, 3 insertions, 1 deletions
diff --git a/render.c b/render.c
index ef87792..aba3d45 100644
--- a/render.c
+++ b/render.c
@@ -415,7 +415,7 @@ shaderunit(void *arg)
}
idxtab = &(*ep)->indextab[OBJVTexture];
- if(params->entity->mdl->tex != nil && idxtab->nindex == 3){
+ if(idxtab->nindex == 3){
t[0][0].uv = Pt2(tverts[idxtab->indices[0]].u,
tverts[idxtab->indices[0]].v, 1);
t[0][1].uv = Pt2(tverts[idxtab->indices[1]].u,
diff --git a/vertex.c b/vertex.c
index 0cd6ce7..d18d9ac 100644
--- a/vertex.c
+++ b/vertex.c
@@ -53,6 +53,7 @@ lerpvertex(Vertex *v, Vertex *v0, Vertex *v1, double t)
v->n = lerp3(v0->n, v1->n, t);
v->c = lerp3(v0->c, v1->c, t);
v->uv = lerp2(v0->uv, v1->uv, t);
+ v->mtl = v0->mtl != nil? v0->mtl: v1->mtl;
v->attrs = nil;
v->nattrs = 0;
for(i = 0; i < v0->nattrs; i++){
@@ -87,6 +88,7 @@ berpvertex(Vertex *v, Vertex *v0, Vertex *v1, Vertex *v2, Point3 bc)
mulpt2(v0->uv, bc.x),
mulpt2(v1->uv, bc.y)),
mulpt2(v2->uv, bc.z));
+ v->mtl = v0->mtl != nil? v0->mtl: v1->mtl != nil? v1->mtl: v2->mtl;
v->attrs = nil;
v->nattrs = 0;
for(i = 0; i < v0->nattrs; i++){