0

fixed top smooth lighting tesselation error

This commit is contained in:
Aaron Griffith
2011-10-18 09:56:01 -04:00
parent 0fa734d0c5
commit 4bddf2c78a
3 changed files with 67 additions and 7 deletions

View File

@@ -375,7 +375,9 @@ draw_triangle(PyObject *dest, int inclusive,
int x1, int y1, int x1, int y1,
unsigned char r1, unsigned char g1, unsigned char b1, unsigned char r1, unsigned char g1, unsigned char b1,
int x2, int y2, 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 */ /* destination image */
Imaging imDest; Imaging imDest;
/* ranges of pixels that are affected */ /* 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; return dest;
} }

View File

@@ -57,7 +57,8 @@ PyObject *draw_triangle(PyObject *dest, int inclusive,
int x1, int y1, int x1, int y1,
unsigned char r1, unsigned char g1, unsigned char b1, unsigned char r1, unsigned char g1, unsigned char b1,
int x2, int y2, 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 */ /* forward declaration of RenderMode object */
typedef struct _RenderMode RenderMode; typedef struct _RenderMode RenderMode;

View File

@@ -36,10 +36,32 @@ struct SmoothLightingFace {
/* the points that form the corners of this face */ /* the points that form the corners of this face */
struct SmoothLightingCorner corners[4]; 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! */ /* the lighting face rule list! */
static struct SmoothLightingFace lighting_rules[] = { 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 */ /* top */
{0, 0, 1, { {0, 0, 1, {
{0, 6, {0, 6,
@@ -54,7 +76,9 @@ static struct SmoothLightingFace lighting_rules[] = {
{12, 12, {12, 12,
-1, 0, 0, -1, 0, 0,
0, 1, 0}, 0, 1, 0},
}}, },
top_touchups, 3},
/* left */ /* left */
{-1, 0, 0, { {-1, 0, 0, {
{12, 24, {12, 24,
@@ -69,7 +93,9 @@ static struct SmoothLightingFace lighting_rules[] = {
{12, 12, {12, 12,
0, 1, 0, 0, 1, 0,
0, 0, 1}, 0, 0, 1},
}}, },
NULL, 0},
/* right */ /* right */
{0, 1, 0, { {0, 1, 0, {
{12, 12, {12, 12,
@@ -84,7 +110,8 @@ static struct SmoothLightingFace lighting_rules[] = {
{24, 6, {24, 6,
1, 0, 0, 1, 0, 0,
0, 0, 1}, 0, 0, 1},
}}, },
NULL, 0},
}; };
/* helpers for indexing the rule list */ /* helpers for indexing the rule list */
@@ -147,11 +174,13 @@ do_shading_with_rule(RenderModeSmoothLighting *self, RenderState *state, struct
draw_triangle(state->img, 1, draw_triangle(state->img, 1,
x+pts[0].imgx, y+pts[0].imgy, pts_r[0], pts_g[0], pts_b[0], 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[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, draw_triangle(state->img, 0,
x+pts[0].imgx, y+pts[0].imgy, pts_r[0], pts_g[0], pts_b[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[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 static int