Change Brightness slider to use the 'gamma' argument to generateLightmap
This commit is contained in:
parent
8a5bcd6dd2
commit
ce5ea422af
@ -1134,19 +1134,20 @@ class EditorTab(QtGui.QWidget):
|
||||
|
||||
self.dayTimeInput = SpinSlider(double=True,
|
||||
minimum=0.0, maximum=1.0, value=1.0)
|
||||
self.minBrightnessInput = SpinSlider(double=True,
|
||||
minimum=0.0, maximum=1.0, value=0.0)
|
||||
|
||||
self.gammaInput = SpinSlider(double=True,
|
||||
minimum=0.0, maximum=3.0, value=1.0)
|
||||
|
||||
self.dayTimeInput.valueChanged.connect(self.setDayTime)
|
||||
self.minBrightnessInput.valueChanged.connect(self.setMinBrightness)
|
||||
self.gammaInput.valueChanged.connect(self.setGamma)
|
||||
|
||||
self.viewButtonToolbar.addSeparator()
|
||||
self.viewButtonToolbar.addWidget(QtGui.QLabel("Time of day:"))
|
||||
self.viewButtonToolbar.addWidget(self.dayTimeInput)
|
||||
|
||||
self.viewButtonToolbar.addSeparator()
|
||||
self.viewButtonToolbar.addWidget(QtGui.QLabel("Minimum brightness:"))
|
||||
self.viewButtonToolbar.addWidget(self.minBrightnessInput)
|
||||
self.viewButtonToolbar.addWidget(QtGui.QLabel("Brightness:"))
|
||||
self.viewButtonToolbar.addWidget(self.gammaInput)
|
||||
|
||||
spacer = QtGui.QWidget()
|
||||
spacer.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)
|
||||
@ -1162,10 +1163,12 @@ class EditorTab(QtGui.QWidget):
|
||||
def setDayTime(self, value):
|
||||
if self.editorSession.textureAtlas:
|
||||
self.editorSession.textureAtlas.dayTime = value
|
||||
self.currentView().update()
|
||||
|
||||
def setMinBrightness(self, value):
|
||||
def setGamma(self, value):
|
||||
if self.editorSession.textureAtlas:
|
||||
self.editorSession.textureAtlas.minBrightness = value
|
||||
self.editorSession.textureAtlas.gamma = value
|
||||
self.currentView().update()
|
||||
|
||||
editorSession = weakrefprop()
|
||||
|
||||
|
@ -7,24 +7,22 @@ import numpy
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
lightBrightnessTable = range(16)
|
||||
|
||||
def generateLightBrightnessTable(minLight = 0.0):
|
||||
for index in range(16):
|
||||
darkness = 1.0 - index / 15.0
|
||||
lightBrightnessTable[index] = (1.0 - darkness) / (darkness * 3.0 + 1.0) * (1.0 - minLight) + minLight
|
||||
|
||||
generateLightBrightnessTable()
|
||||
|
||||
def generateLightmap(brightness, theEnd = False, gamma = 0.5):
|
||||
def generateLightmap(brightness, theEnd = False, minLight=0.0, gamma=0.5):
|
||||
|
||||
"""
|
||||
:type gamma: Brightness setting in the Minecraft Video Options. Usual values are 0.0 to 1.0
|
||||
"""
|
||||
|
||||
lightBrightnessTable = range(16)
|
||||
for index in range(16):
|
||||
darkness = 1.0 - index / 15.0
|
||||
lightBrightnessTable[index] = (1.0 - darkness) / (darkness * 3.0 + 1.0) * (1.0 - minLight) + minLight
|
||||
|
||||
lightmapColors = numpy.zeros((16, 16, 4), 'uint8')
|
||||
|
||||
torchFlickerX = 0.0
|
||||
log.info("Generating lightmap. brightness=%s, theEnd=%s, gamma=%s", brightness, theEnd, gamma)
|
||||
log.info("Generating lightmap. brightness=%s, minLight=%s, theEnd=%s, gamma=%s",
|
||||
brightness, minLight, theEnd, gamma)
|
||||
|
||||
for x, y in numpy.ndindex(16, 16):
|
||||
var4 = brightness * 0.95 + 0.05
|
||||
|
@ -238,6 +238,17 @@ class TextureAtlas(object):
|
||||
self._minBrightness = value
|
||||
self._lightTexture.minBrightness = value
|
||||
|
||||
_gamma = 0.0
|
||||
|
||||
@property
|
||||
def gamma(self):
|
||||
return self._gamma
|
||||
|
||||
@gamma.setter
|
||||
def gamma(self, value):
|
||||
self._gamma = value
|
||||
self._lightTexture.gamma = value
|
||||
|
||||
def bindLight(self):
|
||||
self._lightTexture.bind()
|
||||
|
||||
@ -255,15 +266,15 @@ class TextureAtlas(object):
|
||||
|
||||
|
||||
class LightTexture(glutils.Texture):
|
||||
def __init__(self, dayTime=1.0, minBrightness=0.0):
|
||||
def __init__(self, dayTime=1.0, minBrightness=0.0, gamma=1.0):
|
||||
self._dayTime = dayTime
|
||||
self._minBrightness = minBrightness
|
||||
self._gamma = gamma
|
||||
self.image = self.generateImage()
|
||||
super(LightTexture, self).__init__(name="Lightmap", image=self.image, width=16, height=16)
|
||||
|
||||
def generateImage(self):
|
||||
pixels = generateLightmap(self.dayTime)
|
||||
pixels.clip(int(self.minBrightness * 255), 255, pixels)
|
||||
pixels = generateLightmap(self.dayTime, minLight=self.minBrightness, gamma=self.gamma)
|
||||
return pixels
|
||||
|
||||
@property
|
||||
@ -284,6 +295,15 @@ class LightTexture(glutils.Texture):
|
||||
self._minBrightness = value
|
||||
self.updateLightmap()
|
||||
|
||||
@property
|
||||
def gamma(self):
|
||||
return self._gamma
|
||||
|
||||
@gamma.setter
|
||||
def gamma(self, value):
|
||||
self._gamma = value
|
||||
self.updateLightmap()
|
||||
|
||||
def updateLightmap(self):
|
||||
self.image = self.generateImage()
|
||||
|
||||
|
Reference in New Issue
Block a user