#include "color.hh"
#include "contact.hh"
#include "light.hh"
+#include "raster.hh"
#include "ray.hh"
#include "scene.hh"
*/
class element
{
+ color_t kd;
+ raster_t* tx;
+
public:
+ element() :
+ kd(COLOR_WHITE), tx(NULL)
+ {}
+
virtual ~element()
{}
*/
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;
}
/*
*/
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));
}
* 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;
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;
+ }
};