X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Frasterize;a=blobdiff_plain;f=raster.c;h=b4f466fcb0504dfc9b69a7a32e8770e7b01f1b93;hp=766e6ea7ba4ce6cb22ad0b687e5eccd8bc377c0e;hb=95850b98f73ad7033af60a30e324e9c3cda55389;hpb=34efcdbb29b75754fef5066c5999671bc2d2fb12 diff --git a/raster.c b/raster.c index 766e6ea..b4f466f 100644 --- a/raster.c +++ b/raster.c @@ -258,6 +258,32 @@ fail: fprintf(stderr, "Cannot write to %s: %s\n", filename, strerror(errno)); #undef _CHECK_WRITE +void raster_draw_model(raster_t* p, const model_t* model) +{ +#if VERBOSITY >= 4 +#define PROGRESS_FMT "\033[80D\033[2K %s\t %9d / %d" + int tri; +#endif + + model_transformation(model, &p->model); + p->dirty = true; + raster_material(p, model_specular(model), model_shininess(model)); + IF_RENDER_PROGRESS(tri = 0); + for (const list_t* ti = model_geometry(model); ti; ti = ti->link) { +#if VERBOSITY >= 4 + if (++tri % 100 == 0) { + printf(PROGRESS_FMT, model_name(model), tri, model_size(model)); + fflush(stdout); + } +#endif + raster_draw_tri(p, (tri_t*)ti->val); + } +#if VERBOSITY >= 4 + printf(PROGRESS_FMT"\n", model_name(model), tri, model_size(model)); +#endif +} + + /* * See if the triangle is at all visible in the viewport. Also, minimize the * rectangle around the area that includes the triangle. @@ -308,6 +334,7 @@ color_t _do_phong_lighting(raster_t* p, vert_t vert) { #if LIGHTING color_t color = COLOR_BLACK; + color.a = vert.c.a; for (list_t* i = p->lights; i; i = i->link) { light_t light = *(light_t*)i->val; vec_t mpos = vert.v; @@ -366,9 +393,6 @@ void raster_draw_tri(raster_t* p, const tri_t* triangle) #if LIGHTING >= 1 tri_t tl = tri_transform(*triangle, p->model); -#if !PRE_NORMALS - tl.a.n = tl.b.n = tl.c.n = vec_normalize(tri_normal(tl)); -#endif #endif #if LIGHTING == 1 @@ -405,18 +429,25 @@ void raster_draw_tri(raster_t* p, const tri_t* triangle) if (S(-1.0) < v.z && v.z < *n) { #endif color_t* c = p->pixels + y * p->w + x; + color_t newC; #if LIGHTING == 2 || (!LIGHTING && SMOOTH_COLOR) - *c = color_interp2(color1, color2, color3, b); + newC = color_interp2(color1, color2, color3, b); #elif LIGHTING == 3 && SMOOTH_COLOR - *c = _do_phong_lighting(p, tri_interp(tl, b)); + newC = _do_phong_lighting(p, tri_interp(tl, b)); #elif LIGHTING == 3 && !SMOOTH_COLOR vert_t d = vert_new(tri_point(t, b)); d.c = tri_color(t); d.n = tri_normal2(t, b); - *c = _do_phong_lighting(p, d); + newC = _do_phong_lighting(p, d); +#else + newC = color; +#endif + +#if BLENDING + *c = color_blend(*c, newC); #else - *c = color; + *c = newC; #endif #if DEPTH_TEST