diff options
author | rodri <rgl@antares-labs.eu> | 2024-03-06 22:20:53 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2024-03-06 22:20:53 +0000 |
commit | 4aca8f7a843e66454ba1f62e63bd91d7da6b315c (patch) | |
tree | 68b5652468d0d5cbece8759b8ad1446ceef61bda | |
parent | 2f6efcecc3fb03a4c1a2ea6ed009bb286a2244d9 (diff) | |
download | 3dee-4aca8f7a843e66454ba1f62e63bd91d7da6b315c.tar.gz 3dee-4aca8f7a843e66454ba1f62e63bd91d7da6b315c.tar.bz2 3dee-4aca8f7a843e66454ba1f62e63bd91d7da6b315c.zip |
use the diffuse color map texture from the OBJMaterial for shading.
-rw-r--r-- | main.c | 29 |
1 files changed, 22 insertions, 7 deletions
@@ -128,7 +128,9 @@ gouraudshader(FSparams *sp) Color c; va = getvattr(&sp->v, "intensity"); - if(sp->su->entity->mdl->tex != nil && sp->v.uv.w != 0) + if(sp->v.mtl != nil && sp->v.mtl->map_Kd != nil && sp->v.uv.w != 0) + c = texture(sp->v.mtl->map_Kd, sp->v.uv, tsampler); + else if(sp->su->entity->mdl->tex != nil && sp->v.uv.w != 0) c = texture(sp->su->entity->mdl->tex, sp->v.uv, tsampler); else c = Pt3(1,1,1,1); @@ -186,20 +188,31 @@ phongshader(FSparams *sp) m.shininess = va != nil? va->n: 1; ambient = mulpt3(light.c, Ka); - ambient.r *= m.ambient.r; ambient.g *= m.ambient.g; ambient.b *= m.ambient.b; ambient.a *= m.ambient.a; + ambient.r *= m.ambient.r; + ambient.g *= m.ambient.g; + ambient.b *= m.ambient.b; + ambient.a *= m.ambient.a; lightdir = normvec3(subpt3(light.p, pos)); Kd = fmax(0, dotvec3(sp->v.n, lightdir)); diffuse = mulpt3(light.c, Kd); - diffuse.r *= m.diffuse.r; diffuse.g *= m.diffuse.g; diffuse.b *= m.diffuse.b; diffuse.a *= m.diffuse.a; + diffuse.r *= m.diffuse.r; + diffuse.g *= m.diffuse.g; + diffuse.b *= m.diffuse.b; + diffuse.a *= m.diffuse.a; lookdir = normvec3(subpt3(maincam->p, pos)); lightdir = qrotate(lightdir, sp->v.n, PI); spec = pow(fmax(0, dotvec3(lookdir, lightdir)), m.shininess); specular = mulpt3(light.c, spec*Ks); - specular.r *= m.specular.r; specular.g *= m.specular.g; specular.b *= m.specular.b; specular.a *= m.specular.a; - - if(sp->su->entity->mdl->tex != nil && sp->v.uv.w != 0) + specular.r *= m.specular.r; + specular.g *= m.specular.g; + specular.b *= m.specular.b; + specular.a *= m.specular.a; + + if(sp->v.mtl != nil && sp->v.mtl->map_Kd != nil && sp->v.uv.w != 0) + tc = texture(sp->v.mtl->map_Kd, sp->v.uv, tsampler); + else if(sp->su->entity->mdl->tex != nil && sp->v.uv.w != 0) tc = texture(sp->su->entity->mdl->tex, sp->v.uv, tsampler); else tc = Pt3(1,1,1,1); @@ -325,7 +338,9 @@ identshader(FSparams *sp) { Color c; - if(sp->su->entity->mdl->tex != nil && sp->v.uv.w != 0) + if(sp->v.mtl != nil && sp->v.mtl->map_Kd != nil && sp->v.uv.w != 0) + c = texture(sp->v.mtl->map_Kd, sp->v.uv, tsampler); + else if(sp->su->entity->mdl->tex != nil && sp->v.uv.w != 0) c = texture(sp->su->entity->mdl->tex, sp->v.uv, tsampler); else c = Pt3(1,1,1,1); |