X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=element.hh;h=5130a8ed7fee9ba15fcc2a51dd37219ccaf9f642;hb=9f13ae5fe777dd4f7a9302f6dcf3e0d99a1ce65d;hp=7eb898861187b00a90a15d7ab3efbf9c63779910;hpb=a737ad45e690daa3b39b8885e2b6574d2ea48833;p=chaz%2Frasterize diff --git a/element.hh b/element.hh index 7eb8988..5130a8e 100644 --- a/element.hh +++ b/element.hh @@ -11,6 +11,7 @@ #include "color.hh" #include "contact.hh" #include "light.hh" +#include "raster.hh" #include "ray.hh" #include "scene.hh" @@ -23,8 +24,15 @@ namespace rt { */ class element { + color_t kd; + raster_t* tx; + public: + element() : + kd(COLOR_WHITE), tx(NULL) + {} + virtual ~element() {} @@ -38,7 +46,15 @@ public: */ virtual color_t color(vec_t point) const { - return COLOR_WHITE; + return kd; + } + + /* + * Get texture-coordinates from a surface point. + */ + virtual vec_t txcoord(vec_t point) const + { + return VEC_ZERO; } /* @@ -46,8 +62,9 @@ public: */ color_t cast(const contact_t& hit, const scene_t* scene) const { - color_t Ia = color_mult(scene_ambient(scene), color(hit.p)); - color_t Id = diffuse(hit, scene); + color_t kd = txcolor(hit.p); + color_t Ia = color_mult(scene_ambient(scene), kd); + color_t Id = diffuse(kd, hit, scene); return color_clamp(color_add(Ia, Id)); } @@ -75,9 +92,8 @@ public: * Get the color of the element at a surface point after diffuse * lighting. */ - color_t diffuse(const contact_t& hit, const scene_t* scene) const + color_t diffuse(color_t kd, const contact_t& hit, const scene_t* scene) const { - color_t kd = color(hit.p); vec_t n = vec_normalize(hit.n); color_t c = COLOR_BLACK; @@ -94,6 +110,31 @@ public: return c; } + + color_t txcolor(vec_t point) const + { +#if TEXTURING + if (tx != NULL) { + vec_t uv = txcoord(point); +#if QUIRKS + return raster_uv(tx, uv); +#else + return color_mult(color(point), raster_uv(tx, uv)); +#endif + } +#endif + return color(point); + } + + void material(color_t color) + { + kd = color; + } + + void texture(raster_t* texture) + { + tx = texture; + } };