From ce5ea422af4c635df83b3c878551d664051fac51 Mon Sep 17 00:00:00 2001 From: David Vierra Date: Thu, 10 Sep 2015 11:54:52 -1000 Subject: [PATCH] Change Brightness slider to use the 'gamma' argument to generateLightmap --- src/mcedit2/editorsession.py | 17 ++++++++++------- src/mcedit2/rendering/lightmap.py | 20 +++++++++----------- src/mcedit2/rendering/textureatlas.py | 26 +++++++++++++++++++++++--- 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/src/mcedit2/editorsession.py b/src/mcedit2/editorsession.py index 77906fa..b645eb2 100644 --- a/src/mcedit2/editorsession.py +++ b/src/mcedit2/editorsession.py @@ -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() diff --git a/src/mcedit2/rendering/lightmap.py b/src/mcedit2/rendering/lightmap.py index 0211915..e53db31 100644 --- a/src/mcedit2/rendering/lightmap.py +++ b/src/mcedit2/rendering/lightmap.py @@ -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 diff --git a/src/mcedit2/rendering/textureatlas.py b/src/mcedit2/rendering/textureatlas.py index 02bfb6b..1f44c4c 100644 --- a/src/mcedit2/rendering/textureatlas.py +++ b/src/mcedit2/rendering/textureatlas.py @@ -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()