]>
Dogcows Code - chaz/rasterize/blob - element.hh
5130a8ed7fee9ba15fcc2a51dd37219ccaf9f642
3 * CS5600 University of Utah
5 * mcgarvey@eng.utah.edu
23 * A base class for an object in a scene.
33 kd(COLOR_WHITE
), tx(NULL
)
40 * Determine if a ray intersects this element.
42 virtual bool intersect(ray_t ray
, contact_t
& hit
) const = 0;
45 * Get the material color of the element at a surface point.
47 virtual color_t
color(vec_t point
) const
53 * Get texture-coordinates from a surface point.
55 virtual vec_t
txcoord(vec_t point
) const
61 * Cast a ray to this element, returning the correct color value.
63 color_t
cast(const contact_t
& hit
, const scene_t
* scene
) const
65 color_t kd
= txcolor(hit
.p
);
66 color_t Ia
= color_mult(scene_ambient(scene
), kd
);
67 color_t Id
= diffuse(kd
, hit
, scene
);
68 return color_clamp(color_add(Ia
, Id
));
72 * Get whether or not a particular surface point is shadowed by other
73 * objects for a given light source.
75 bool is_shadowed(const contact_t
& hit
, const scene_t
* scene
, const light_t
* light
) const
78 ray_t ray
= ray_normalize(ray_new(hit
.p
, vec_sub(light
->v
, hit
.p
)));
79 for (list_t
* i
= scene_elements(scene
); i
; i
= i
->link
) {
80 rt::element
* obj
= (rt::element
*)i
->val
;
82 if (this != obj
&& obj
->intersect(ray
, hit
)) {
92 * Get the color of the element at a surface point after diffuse
95 color_t
diffuse(color_t kd
, const contact_t
& hit
, const scene_t
* scene
) const
97 vec_t n
= vec_normalize(hit
.n
);
99 color_t c
= COLOR_BLACK
;
101 for (list_t
* i
= scene_lights(scene
); i
; i
= i
->link
) {
102 light_t
* l
= (light_t
*)i
->val
;
103 if (!is_shadowed(hit
, scene
, l
)) {
104 vec_t I
= vec_normalize(vec_sub(l
->v
, hit
.p
));
105 scal_t dot
= scal_max(vec_dot(I
, n
), S(0.0));
106 color_t Id
= color_scale2(kd
, l
->d
, dot
);
107 c
= color_add(c
, Id
);
114 color_t
txcolor(vec_t point
) const
118 vec_t uv
= txcoord(point
);
120 return raster_uv(tx
, uv
);
122 return color_mult(color(point
), raster_uv(tx
, uv
));
129 void material(color_t color
)
134 void texture(raster_t
* texture
)
143 #endif // _ELEMENT_HH_
This page took 0.040327 seconds and 4 git commands to generate.