Skip to content

Commit 9c8fec8

Browse files
numberZeronerzhul
authored andcommittedAug 16, 2017
New lighting curve (#5279)
* New lighting curve * Make polynomial lighting curve * Update default lighting settings
1 parent 1d8d010 commit 9c8fec8

File tree

5 files changed

+34
-44
lines changed

5 files changed

+34
-44
lines changed
 

‎builtin/settingtypes.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,11 @@ zoom_fov (Field of view for zoom) int 15 7 160
602602

603603
# Adjust the gamma encoding for the light tables. Higher numbers are brighter.
604604
# This setting is for the client only and is ignored by the server.
605-
display_gamma (Gamma) float 2.2 1.0 3.0
605+
display_gamma (Gamma) float 1.0 0.5 3.0
606+
607+
lighting_alpha (Darkness sharpness) float 0.0 0.0 4.0
608+
609+
lighting_beta (Lightness sharpness) float 0.0 0.0 4.0
606610

607611
# Path to texture directory. All textures are first searched from here.
608612
texture_path (Texture path) path

‎minetest.conf.example

+8-2
Original file line numberDiff line numberDiff line change
@@ -702,8 +702,14 @@
702702

703703
# Adjust the gamma encoding for the light tables. Higher numbers are brighter.
704704
# This setting is for the client only and is ignored by the server.
705-
# type: float min: 1 max: 3
706-
# display_gamma = 2.2
705+
# type: float min: 0.5 max: 3.0
706+
# display_gamma = 1.0
707+
708+
# type: float min: 0.0 max: 4.0
709+
# lighting_alpha = 0.0
710+
711+
# type: float min: 0.0 max: 4.0
712+
# lighting_beta = 0.0
707713

708714
# Path to texture directory. All textures are first searched from here.
709715
# type: path

‎src/defaultsettings.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ void set_default_settings(Settings *settings)
168168
settings->setDefault("leaves_style", "fancy");
169169
settings->setDefault("connected_glass", "false");
170170
settings->setDefault("smooth_lighting", "true");
171-
settings->setDefault("display_gamma", "2.2");
171+
settings->setDefault("lighting_alpha", "0.0");
172+
settings->setDefault("lighting_beta", "0.0");
173+
settings->setDefault("display_gamma", "1.0");
172174
settings->setDefault("texture_path", "");
173175
settings->setDefault("shader_path", "");
174176
settings->setDefault("video_driver", "opengl");

‎src/light.cpp

+16-40
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2020
#include "light.h"
2121
#include <math.h>
2222
#include "util/numeric.h"
23+
#include "settings.h"
2324

2425
#ifndef SERVER
2526

@@ -32,52 +33,27 @@ u8 light_LUT[LIGHT_MAX+1];
3233
const u8 *light_decode_table = light_LUT;
3334

3435
/** Initialize or update the light value tables using the specified \p gamma.
35-
* If \p gamma == 1.0 then the light table is linear. Typically values for
36-
* gamma range between 1.8 and 2.2.
37-
*
38-
* @note The value for gamma will be restricted to the range 1.1 <= gamma <= 3.0.
39-
*
40-
* @note This function is not, currently, a simple linear to gamma encoding
41-
* because adjustments are made so that a gamma of 1.8 gives the same
42-
* results as those hardcoded for use by the server.
4336
*/
4437
void set_light_table(float gamma)
4538
{
46-
static const float brightness_step = 255.0f / (LIGHT_MAX + 1);
47-
48-
// this table is pure arbitrary values, made so that
49-
// at gamma 2.2 the game looks not too dark at light=1,
50-
// and mostly linear for the rest of the scale.
51-
// we could try to inverse the gamma power function, but this
52-
// is simpler and quicker.
53-
static const int adjustments[LIGHT_MAX + 1] = {
54-
-67,
55-
-91,
56-
-125,
57-
-115,
58-
-104,
59-
-85,
60-
-70,
61-
-63,
62-
-56,
63-
-49,
64-
-42,
65-
-35,
66-
-28,
67-
-22,
68-
0
69-
};
70-
71-
gamma = rangelim(gamma, 1.0, 3.0);
72-
73-
float brightness = brightness_step;
39+
// lighting curve derivatives
40+
const float alpha = g_settings->getFloat("lighting_alpha");
41+
const float beta = g_settings->getFloat("lighting_beta");
42+
// lighting curve coefficients
43+
const float a = alpha + beta - 2;
44+
const float b = 3 - 2 * alpha - beta;
45+
const float c = alpha;
46+
// gamma correction
47+
gamma = rangelim(gamma, 0.5, 3.0);
7448

7549
for (size_t i = 0; i < LIGHT_MAX; i++) {
76-
light_LUT[i] = (u8)(255 * powf(brightness / 255.0f, 1.0 / gamma));
77-
light_LUT[i] = rangelim(light_LUT[i] + adjustments[i], 0, 255);
78-
if (i > 1 && light_LUT[i] < light_LUT[i - 1])
50+
float x = i;
51+
x /= LIGHT_MAX;
52+
float brightness = a * x * x * x + b * x * x + c * x;
53+
brightness = powf(brightness, 1.0 / gamma);
54+
light_LUT[i] = rangelim((u32)(255 * brightness), 0, 255);
55+
if (i > 1 && light_LUT[i] <= light_LUT[i - 1])
7956
light_LUT[i] = light_LUT[i - 1] + 1;
80-
brightness += brightness_step;
8157
}
8258
light_LUT[LIGHT_MAX] = 255;
8359
}

‎src/settings_translation_file.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ fake_function() {
245245
gettext("Field of view while zooming in degrees.\nThis requires the \"zoom\" privilege on the server.");
246246
gettext("Gamma");
247247
gettext("Adjust the gamma encoding for the light tables. Higher numbers are brighter.\nThis setting is for the client only and is ignored by the server.");
248+
gettext("Darkness sharpness");
249+
gettext("Lightness sharpness");
248250
gettext("Texture path");
249251
gettext("Path to texture directory. All textures are first searched from here.");
250252
gettext("Video driver");

0 commit comments

Comments
 (0)
Please sign in to comment.