From 4bddf2c78af096196a7f594f578ffabf928739ab Mon Sep 17 00:00:00 2001 From: Aaron Griffith Date: Tue, 18 Oct 2011 09:56:01 -0400 Subject: [PATCH] fixed top smooth lighting tesselation error --- overviewer_core/src/composite.c | 32 ++++++++++++++- overviewer_core/src/overviewer.h | 3 +- .../src/rendermode-smooth-lighting.c | 39 ++++++++++++++++--- 3 files changed, 67 insertions(+), 7 deletions(-) diff --git a/overviewer_core/src/composite.c b/overviewer_core/src/composite.c index 271f558..2a25706 100644 --- a/overviewer_core/src/composite.c +++ b/overviewer_core/src/composite.c @@ -375,7 +375,9 @@ draw_triangle(PyObject *dest, int inclusive, int x1, int y1, unsigned char r1, unsigned char g1, unsigned char b1, int x2, int y2, - unsigned char r2, unsigned char g2, unsigned char b2) { + unsigned char r2, unsigned char g2, unsigned char b2, + int tux, int tuy, int *touchups, unsigned int num_touchups) { + /* destination image */ Imaging imDest; /* ranges of pixels that are affected */ @@ -452,5 +454,33 @@ draw_triangle(PyObject *dest, int inclusive, } } + while (num_touchups > 0) { + float alpha, beta, gamma; + unsigned int r, g, b; + UINT8 *out; + + x = touchups[0] + tux; + y = touchups[1] + tuy; + touchups += 2; + num_touchups--; + + if (x < 0 || x >= imDest->xsize || y < 0 || y >= imDest->ysize) + continue; + + out = (UINT8 *)imDest->image[y] + x * 4; + + alpha = alpha_norm * ((a12 * x) + (b12 * y) + c12); + beta = beta_norm * ((a20 * x) + (b20 * y) + c20); + gamma = gamma_norm * ((a01 * x) + (b01 * y) + c01); + + r = alpha * r0 + beta * r1 + gamma * r2; + g = alpha * g0 + beta * g1 + gamma * g2; + b = alpha * b0 + beta * b1 + gamma * b2; + + *out = MULDIV255(*out, r, tmp); out++; + *out = MULDIV255(*out, g, tmp); out++; + *out = MULDIV255(*out, b, tmp); out++; + } + return dest; } diff --git a/overviewer_core/src/overviewer.h b/overviewer_core/src/overviewer.h index f08ecf6..8d10d81 100644 --- a/overviewer_core/src/overviewer.h +++ b/overviewer_core/src/overviewer.h @@ -57,7 +57,8 @@ PyObject *draw_triangle(PyObject *dest, int inclusive, int x1, int y1, unsigned char r1, unsigned char g1, unsigned char b1, int x2, int y2, - unsigned char r2, unsigned char g2, unsigned char b2); + unsigned char r2, unsigned char g2, unsigned char b2, + int tux, int tuy, int *touchups, unsigned int num_touchups); /* forward declaration of RenderMode object */ typedef struct _RenderMode RenderMode; diff --git a/overviewer_core/src/rendermode-smooth-lighting.c b/overviewer_core/src/rendermode-smooth-lighting.c index 38e500e..2af427c 100644 --- a/overviewer_core/src/rendermode-smooth-lighting.c +++ b/overviewer_core/src/rendermode-smooth-lighting.c @@ -36,10 +36,32 @@ struct SmoothLightingFace { /* the points that form the corners of this face */ struct SmoothLightingCorner corners[4]; + + /* pairs of (x,y) in order, as touch-up points, or NULL for none */ + int *touch_up_points; + unsigned int num_touch_up_points; }; +/* top face touchups, pulled from textures.py (_build_block) */ +static int top_touchups[] = {3, 4, 7, 2, 11, 0}; + /* the lighting face rule list! */ static struct SmoothLightingFace lighting_rules[] = { + /* since this is getting a little insane, here's the general layout: + + {dx, dy, dz, { // direction this face is towards + // now, a list of 4 corners... + {imgx, imgy, // where the corner is on the block image + x1, y1, z1, // two vectors, describing the 4 (!!!) + x2, y2, z2}, // blocks neighboring this corner + // ... + }, + {x, y, x, y}, 2}, // touch-up points, and how many there are (may be NULL) + + // ... + + */ + /* top */ {0, 0, 1, { {0, 6, @@ -54,7 +76,9 @@ static struct SmoothLightingFace lighting_rules[] = { {12, 12, -1, 0, 0, 0, 1, 0}, - }}, + }, + top_touchups, 3}, + /* left */ {-1, 0, 0, { {12, 24, @@ -69,7 +93,9 @@ static struct SmoothLightingFace lighting_rules[] = { {12, 12, 0, 1, 0, 0, 0, 1}, - }}, + }, + NULL, 0}, + /* right */ {0, 1, 0, { {12, 12, @@ -84,7 +110,8 @@ static struct SmoothLightingFace lighting_rules[] = { {24, 6, 1, 0, 0, 0, 0, 1}, - }}, + }, + NULL, 0}, }; /* helpers for indexing the rule list */ @@ -147,11 +174,13 @@ do_shading_with_rule(RenderModeSmoothLighting *self, RenderState *state, struct draw_triangle(state->img, 1, x+pts[0].imgx, y+pts[0].imgy, pts_r[0], pts_g[0], pts_b[0], x+pts[1].imgx, y+pts[1].imgy, pts_r[1], pts_g[1], pts_b[1], - x+pts[2].imgx, y+pts[2].imgy, pts_r[2], pts_g[2], pts_b[2]); + x+pts[2].imgx, y+pts[2].imgy, pts_r[2], pts_g[2], pts_b[2], + x, y, face.touch_up_points, face.num_touch_up_points); draw_triangle(state->img, 0, x+pts[0].imgx, y+pts[0].imgy, pts_r[0], pts_g[0], pts_b[0], x+pts[2].imgx, y+pts[2].imgy, pts_r[2], pts_g[2], pts_b[2], - x+pts[3].imgx, y+pts[3].imgy, pts_r[3], pts_g[3], pts_b[3]); + x+pts[3].imgx, y+pts[3].imgy, pts_r[3], pts_g[3], pts_b[3], + x, y, NULL, 0); } static int