0

added proper occlusion tracking to lighting function

This commit is contained in:
Aaron Griffith
2010-10-14 13:36:20 -04:00
parent e51556f314
commit b44cb9c3f8

View File

@@ -332,10 +332,11 @@ class ChunkRenderer(object):
"""Calculates the lighting coefficient for the given """Calculates the lighting coefficient for the given
coordinate, using default lighting and peeking into coordinate, using default lighting and peeking into
neighboring chunks, if needed. A lighting coefficient of 1.0 neighboring chunks, if needed. A lighting coefficient of 1.0
means fully black. Returns a tuple (coefficient, occluded), means fully black.
where occluded is true if the given coordinate is filled with
a solid block, and therefore the returned coefficient is Returns a tuple (coefficient, occluded), where occluded is
just the default.""" True if the given coordinate is filled with a solid block, and
therefore the returned coefficient is just the default."""
# fill it in with the default first (full skylight) # fill it in with the default first (full skylight)
coefficient = self.calculate_darkness(15, 0) coefficient = self.calculate_darkness(15, 0)
@@ -347,11 +348,14 @@ class ChunkRenderer(object):
local_x = x local_x = x
local_y = y local_y = y
local_z = z local_z = z
is_local_chunk = False
# find out what chunk we're in, and translate accordingly
if x >= 0 and y < 16: if x >= 0 and y < 16:
blocks = self.blocks blocks = self.blocks
skylight = self.skylight skylight = self.skylight
blocklight = self.blocklight blocklight = self.blocklight
is_local_chunk = True
elif x < 0: elif x < 0:
local_x += 16 local_x += 16
blocks = self.left_blocks blocks = self.left_blocks
@@ -371,11 +375,21 @@ class ChunkRenderer(object):
# we have no useful info, return default # we have no useful info, return default
return (coefficient, False) return (coefficient, False)
# calculate the return # calculate the return...
occluded = not (blocks[local_x, local_y, local_z] in transparent_blocks) occluded = not (blocks[local_x, local_y, local_z] in transparent_blocks)
# only calculate the coefficient if we're not occluded
if not occluded: if not occluded:
coefficient = self.calculate_darkness(skylight[local_x, local_y, local_z], blocklight[local_x, local_y, local_z]) coefficient = self.calculate_darkness(skylight[local_x, local_y, local_z], blocklight[local_x, local_y, local_z])
# only say we're occluded if the point is in the CURRENT
# chunk, so that we don't get obvious inter-chunk dependencies
# (we want this here so we still have the default coefficient
# for occluded blocks, even when we don't report them as
# occluded)
if not is_local_chunk:
occluded = False
return (coefficient, occluded) return (coefficient, occluded)
def chunk_render(self, img=None, xoff=0, yoff=0, cave=False): def chunk_render(self, img=None, xoff=0, yoff=0, cave=False):
@@ -509,15 +523,18 @@ class ChunkRenderer(object):
img.paste(t[0], (imgx, imgy), t[1]) img.paste(t[0], (imgx, imgy), t[1])
# top face # top face
black_coeff, _ = self.get_lighting_coefficient(x, y, z + 1) black_coeff, face_occlude = self.get_lighting_coefficient(x, y, z + 1)
if not face_occlude:
img.paste((0,0,0), (imgx, imgy), ImageEnhance.Brightness(facemasks[0]).enhance(black_coeff)) img.paste((0,0,0), (imgx, imgy), ImageEnhance.Brightness(facemasks[0]).enhance(black_coeff))
# left face # left face
black_coeff, _ = self.get_lighting_coefficient(x - 1, y, z) black_coeff, face_occlude = self.get_lighting_coefficient(x - 1, y, z)
if not face_occlude:
img.paste((0,0,0), (imgx, imgy), ImageEnhance.Brightness(facemasks[1]).enhance(black_coeff)) img.paste((0,0,0), (imgx, imgy), ImageEnhance.Brightness(facemasks[1]).enhance(black_coeff))
# right face # right face
black_coeff, _ = self.get_lighting_coefficient(x, y + 1, z) black_coeff, face_occlude = self.get_lighting_coefficient(x, y + 1, z)
if not face_occlude:
img.paste((0,0,0), (imgx, imgy), ImageEnhance.Brightness(facemasks[2]).enhance(black_coeff)) img.paste((0,0,0), (imgx, imgy), ImageEnhance.Brightness(facemasks[2]).enhance(black_coeff))
# Draw edge lines # Draw edge lines