Scan Line Rendering System
Basic System
Image *img = NULL;
View *view = NULL;
Light *lights = NULL;
OBJECT *objs = NULL;
Matrix4 mclip, mdpy;
RContext *rc;
int main(int argc, char **argv)
{
OBJECT *o; Poly *p; Color c;
read_scene();
init_render();
for (o = objs; o != NULL; o = o->next) {
for (p = o->shp; p != NULL; p = p->next) {
if (is_backfacing(p, view->normal))
continue;
c = flat_shade(p, view->center, rc, lights, o->mat);
if (poly_clip(view->front/view->back, poly_transform(p, mclip)))
scan_obj(poly_round_xy(poly_homoxform(p, mdpy)), pix_paint, &c);
}
}
img_write(img, "stdout", 0);
exit(0);
}
void pix_paint(Vector3 v, int lv, Real lt, int rv, Real rt, Real st, Color *c)
{
if (zbuf_store(v))
img_puti(img, v.x, v.y, col_dpymap((*c)));
}
void init_render(void)
{
if (view == NULL)
view = initview();
mclip = m4_m4prod(view->C, view->V);
mdpy = m4_m4prod(view->S, view->P);
if (img == NULL)
img = img_init(view->sc_max.x, view->sc_max.y, 0);
zbuf_init(img->w, img->h);
if (lights == NULL)
LIST_INSERT(lights, light_ambient(.5), Light);
rc = NEWSTRUCT(RContext);
}
Input-Output
Input
scene {
camera = view {from = {0, 0, -3}, to = {0, 0, 0}, roll = 0, fov = 60},
light = dist_light {direction = {0, 0, 1} },
object = polyobj {
material = metal { se = 2 },
shape = trilist {
{{0.5, 0, 0.866025}, {2, 0, 0}, {2, 2, 0}},
{{0.5, 2, 0.866025}, {0.5, 0, 0.866025}, {2, 2, 0}},
{{0.5, 0, -0.866025}, {0.5, 0, 0.866025}, {0.5, 2, 0.866025}},
{{0.5, 2, -0.866025}, {0.5, 0,-0.866025}, {0.5, 2, 0.866025}},
{{2, 0, 0}, {0.5, 0, -0.866025}, {0.5, 2, -0.866025}},
{{2, 2, 0}, {2, 0, 0}, {0.5, 2, -0.866025}},
}
}
};
Output
Image file (stdout)
Extension Options
-
Include global illumination using radiosity as a pre-processing step.
-
Include radiosity acceleration: Hiererchical or Progressive.
-
Include implicit primitives and CSG.
Copyright © 1997 Luiz Velho