0

Merge pull request #455 from Fenixin/fix-lighting

Fix lighting for water, ice and leaves.
This commit is contained in:
Andrew Chin
2011-08-04 09:32:01 -07:00
4 changed files with 38 additions and 11 deletions

View File

@@ -174,7 +174,7 @@ generate_pseudo_data(RenderState *state, unsigned char ancilData) {
data = (check_adjacent_blocks(state, x, y, z, state->block) ^ 0x0f); data = (check_adjacent_blocks(state, x, y, z, state->block) ^ 0x0f);
return data; return data;
} }
} else if (state->block == 20) { /* glass */ } else if ((state->block == 20) || (state->block == 79)) { /* glass and ice */
/* an aditional bit for top is added to the 4 bits of check_adjacent_blocks */ /* an aditional bit for top is added to the 4 bits of check_adjacent_blocks */
if ((z != 127) && (getArrayByte3D(state->blocks, x, y, z+1) == 20)) { if ((z != 127) && (getArrayByte3D(state->blocks, x, y, z+1) == 20)) {
data = 0; data = 0;
@@ -412,11 +412,18 @@ chunk_render(PyObject *self, PyObject *args) {
PyObject *tmp; PyObject *tmp;
unsigned char ancilData = getArrayByte3D(state.blockdata_expanded, state.x, state.y, state.z); unsigned char ancilData = getArrayByte3D(state.blockdata_expanded, state.x, state.y, state.z);
state.block_data = ancilData;
/* block that need pseudo ancildata:
* grass, water, glass, chest, restone wire,
* ice, fence and portal. */
if ((state.block == 2) || (state.block == 9) || if ((state.block == 2) || (state.block == 9) ||
(state.block == 20) || (state.block == 54) || (state.block == 20) || (state.block == 54) ||
(state.block == 55) || (state.block == 85) || (state.block == 55) || (state.block == 79) ||
(state.block == 90)) { (state.block == 85) || (state.block == 90)) {
ancilData = generate_pseudo_data(&state, ancilData); ancilData = generate_pseudo_data(&state, ancilData);
state.block_pdata = ancilData;
} else {
state.block_pdata = 0;
} }
tmp = PyTuple_New(2); tmp = PyTuple_New(2);

View File

@@ -70,6 +70,8 @@ typedef struct {
/* the block position and type, and the block array */ /* the block position and type, and the block array */
int x, y, z; int x, y, z;
unsigned char block; unsigned char block;
unsigned char block_data;
unsigned char block_pdata;
PyObject *blockdata_expanded; PyObject *blockdata_expanded;
PyObject *blocks; PyObject *blocks;
PyObject *up_left_blocks; PyObject *up_left_blocks;

View File

@@ -293,7 +293,22 @@ rendermode_lighting_draw(void *data, RenderState *state, PyObject *src, PyObject
self = (RenderModeLighting *)data; self = (RenderModeLighting *)data;
x = state->x, y = state->y, z = state->z; x = state->x, y = state->y, z = state->z;
if (is_transparent(state->block)) { if ((state->block == 9) || (state->block == 79)) { /* special case for water and ice */
/* looks like we need a new case for lighting, there are
* blocks that are transparent for occlusion calculations and
* need per-face shading if the face is drawn. */
if ((state->block_pdata & 16) == 16) {
do_shading_with_mask(self, state, x, y, z+1, self->facemasks[0]);
}
if ((state->block_pdata & 2) == 2) { /* bottom left */
do_shading_with_mask(self, state, x-1, y, z, self->facemasks[1]);
}
if ((state->block_pdata & 4) == 4) { /* bottom right */
do_shading_with_mask(self, state, x, y+1, z, self->facemasks[2]);
}
/* leaves are transparent for occlusion calculations but they
* per face-shading to look as in game */
} else if (is_transparent(state->block) && (state->block != 18)) {
/* transparent: do shading on whole block */ /* transparent: do shading on whole block */
do_shading_with_mask(self, state, x, y, z, mask_light); do_shading_with_mask(self, state, x, y, z, mask_light);
} else { } else {

View File

@@ -431,7 +431,7 @@ def _build_blockimages():
# 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 # 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
36, 37, -1, -1, 65, -1, -1, -1, 50, 24, -1, -1, 86, -1, -1, -1, 36, 37, -1, -1, 65, -1, -1, -1, 50, 24, -1, -1, 86, -1, -1, -1,
# 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 # 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
-1, -1, -1, -1, -1, -1, -1, -1, -1, 51, 51, -1, -1, -1, 66, 67, -1, -1, -1, -1, -1, -1, -1, -1, -1, 51, 51, -1, -1, -1, 66, -1,
# 80 81 82 83 84 85 86 87 88 89 90 91 # 80 81 82 83 84 85 86 87 88 89 90 91
66, 69, 72, 73, 75, -1,102,103,104,105,-1, 102 # clay? 66, 69, 72, 73, 75, -1,102,103,104,105,-1, 102 # clay?
] ]
@@ -448,7 +448,7 @@ def _build_blockimages():
# 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 # 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
36, 37, -1, -1, 65, -1, -1,101, 50, 24, -1, -1, 86, -1, -1, -1, 36, 37, -1, -1, 65, -1, -1,101, 50, 24, -1, -1, 86, -1, -1, -1,
# 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 # 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
-1, -1, -1, -1, -1, -1, -1, -1, -1, 51, 51, -1, -1, -1, 66, 67, -1, -1, -1, -1, -1, -1, -1, -1, -1, 51, 51, -1, -1, -1, 66, -1,
# 80 81 82 83 84 85 86 87 88 89 90 91 # 80 81 82 83 84 85 86 87 88 89 90 91
66, 70, 72, 73, 74,-1 ,118,103,104,105, -1, 118 66, 70, 72, 73, 74,-1 ,118,103,104,105, -1, 118
] ]
@@ -551,12 +551,14 @@ def generate_special_texture(blockID, data):
return generate_texture_tuple(img, blockID) return generate_texture_tuple(img, blockID)
if blockID == 9 or blockID == 20: # spring water, flowing water and waterfall water, AND glass if blockID == 9 or blockID == 20 or blockID == 79: # spring water, flowing water and waterfall water, AND glass, AND ice
# water and glass share the way to be rendered # water,glass and ice share the way to be rendered
if blockID == 9: if blockID == 9:
texture = _load_image("water.png") texture = _load_image("water.png")
else: elif blockID == 20:
texture = terrain_images[49] texture = terrain_images[49]
else:
texture = terrain_images[67]
if (data & 0b10000) == 16: if (data & 0b10000) == 16:
top = texture top = texture
@@ -1749,8 +1751,8 @@ def getBiomeData(worlddir, chunkX, chunkY):
special_blocks = set([ 2, 6, 9, 17, 18, 20, 26, 23, 27, 28, 29, 31, 33, special_blocks = set([ 2, 6, 9, 17, 18, 20, 26, 23, 27, 28, 29, 31, 33,
34, 35, 43, 44, 50, 51, 53, 54, 55, 58, 59, 61, 62, 34, 35, 43, 44, 50, 51, 53, 54, 55, 58, 59, 61, 62,
63, 64, 65, 66, 67, 68, 71, 75, 76, 85, 86, 90, 91, 63, 64, 65, 66, 67, 68, 71, 75, 76, 79, 85, 86, 90,
92, 93, 94, 96]) 91, 92, 93, 94, 96])
# this is a map of special blockIDs to a list of all # this is a map of special blockIDs to a list of all
# possible values for ancillary data that it might have. # possible values for ancillary data that it might have.
@@ -1789,6 +1791,7 @@ special_map[68] = (2,3,4,5) # wall sing, orientation
special_map[71] = range(16) # iron door, open/close and orientation special_map[71] = range(16) # iron door, open/close and orientation
special_map[75] = (1,2,3,4,5) # off redstone torch, orientation special_map[75] = (1,2,3,4,5) # off redstone torch, orientation
special_map[76] = (1,2,3,4,5) # on redstone torch, orientation special_map[76] = (1,2,3,4,5) # on redstone torch, orientation
special_map[79] = range(32) # ice, used to only render the exterior surface, uses pseudo data
special_map[85] = range(17) # fences, all the possible combination, uses pseudo data special_map[85] = range(17) # fences, all the possible combination, uses pseudo data
special_map[86] = range(5) # pumpkin, orientation special_map[86] = range(5) # pumpkin, orientation
special_map[90] = (1,2,4,8) # portal, in 2 orientations, 4 cases, uses pseudo data special_map[90] = (1,2,4,8) # portal, in 2 orientations, 4 cases, uses pseudo data