added semi-correct lighting for half-blocks
This commit is contained in:
36
chunk.py
36
chunk.py
@@ -328,7 +328,7 @@ class ChunkRenderer(object):
|
||||
# Nighttime
|
||||
return 1.0 - pow(0.8, 15 - max(blocklight, skylight - 11))
|
||||
|
||||
def get_lighting_coefficient(self, x, y, z):
|
||||
def get_lighting_coefficient(self, x, y, z, norecurse=False):
|
||||
"""Calculates the lighting coefficient for the given
|
||||
coordinate, using default lighting and peeking into
|
||||
neighboring chunks, if needed. A lighting coefficient of 1.0
|
||||
@@ -338,9 +338,6 @@ class ChunkRenderer(object):
|
||||
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)
|
||||
coefficient = self.calculate_darkness(15, 0)
|
||||
|
||||
# placeholders for later data arrays, coordinates
|
||||
blocks = None
|
||||
skylight = None
|
||||
@@ -373,13 +370,36 @@ class ChunkRenderer(object):
|
||||
local_x >= 0 and local_x < 16 and local_y >= 0 and local_y < 16 and
|
||||
local_z >= 0 and local_z < 128):
|
||||
# we have no useful info, return default
|
||||
return (coefficient, False)
|
||||
return (self.calculate_darkness(15, 0), False)
|
||||
|
||||
# special handling for half-blocks
|
||||
# (don't recurse more than once!)
|
||||
if blocks[local_x, local_y, local_z] == 44 and not norecurse:
|
||||
# average gathering variables
|
||||
averagegather = 0.0
|
||||
averagecount = 0
|
||||
|
||||
# how bright we need before we consider a side "lit"
|
||||
threshold = self.calculate_darkness(0, 0)
|
||||
# iterate through all the sides of the block
|
||||
sides = [(x-1, y, z), (x+1, y, z), (x, y, z-1), (x, y, z+1), (x, y-1, z), (x, y+1, z)]
|
||||
|
||||
for side in sides:
|
||||
val, occ = self.get_lighting_coefficient(*side, norecurse=True)
|
||||
if (not occ) and (val < threshold):
|
||||
averagegather += val
|
||||
averagecount += 1
|
||||
|
||||
# if at least one side was lit, return the average
|
||||
if averagecount > 0:
|
||||
return (averagegather / averagecount, False)
|
||||
|
||||
# calculate the return...
|
||||
occluded = not (blocks[local_x, local_y, local_z] in transparent_blocks)
|
||||
|
||||
# only calculate the coefficient if we're not occluded
|
||||
if not occluded:
|
||||
# only calculate the non-default coefficient if we're not occluded
|
||||
if occluded:
|
||||
coefficient = self.calculate_darkness(15, 0)
|
||||
else:
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user