mirror of
https://github.com/minetest/minetest.git
synced 2024-11-27 18:13:46 +01:00
parent
b19241b9bc
commit
2d9f0d344e
@ -24,9 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
#ifndef SERVER
|
#ifndef SERVER
|
||||||
|
|
||||||
// Length of LIGHT_MAX + 1 means LIGHT_MAX is the last value.
|
static u8 light_LUT[LIGHT_SUN + 1];
|
||||||
// LIGHT_SUN is read as LIGHT_MAX from here.
|
|
||||||
u8 light_LUT[LIGHT_MAX + 1];
|
|
||||||
|
|
||||||
// The const ref to light_LUT is what is actually used in the code
|
// The const ref to light_LUT is what is actually used in the code
|
||||||
const u8 *light_decode_table = light_LUT;
|
const u8 *light_decode_table = light_LUT;
|
||||||
@ -48,9 +46,9 @@ void set_light_table(float gamma)
|
|||||||
// Gamma correction
|
// Gamma correction
|
||||||
gamma = rangelim(gamma, 0.5f, 3.0f);
|
gamma = rangelim(gamma, 0.5f, 3.0f);
|
||||||
|
|
||||||
for (size_t i = 0; i < LIGHT_MAX; i++) {
|
for (size_t i = 0; i < LIGHT_SUN; i++) {
|
||||||
float x = i;
|
float x = i;
|
||||||
x /= LIGHT_MAX;
|
x /= LIGHT_SUN;
|
||||||
float brightness = a * x * x * x + b * x * x + c * x;
|
float brightness = a * x * x * x + b * x * x + c * x;
|
||||||
float boost = d * std::exp(-((x - e) * (x - e)) / (2.0f * f * f));
|
float boost = d * std::exp(-((x - e) * (x - e)) / (2.0f * f * f));
|
||||||
brightness = powf(brightness + boost, 1.0f / gamma);
|
brightness = powf(brightness + boost, 1.0f / gamma);
|
||||||
@ -58,6 +56,6 @@ void set_light_table(float gamma)
|
|||||||
if (i > 1 && light_LUT[i] <= light_LUT[i - 1])
|
if (i > 1 && light_LUT[i] <= light_LUT[i - 1])
|
||||||
light_LUT[i] = light_LUT[i - 1] + 1;
|
light_LUT[i] = light_LUT[i - 1] + 1;
|
||||||
}
|
}
|
||||||
light_LUT[LIGHT_MAX] = 255;
|
light_LUT[LIGHT_SUN] = 255;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
15
src/light.h
15
src/light.h
@ -18,7 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <cassert>
|
||||||
#include "irrlichttypes.h"
|
#include "irrlichttypes.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -54,11 +54,12 @@ inline u8 diminish_light(u8 light, u8 distance)
|
|||||||
|
|
||||||
inline u8 undiminish_light(u8 light)
|
inline u8 undiminish_light(u8 light)
|
||||||
{
|
{
|
||||||
|
assert(light <= LIGHT_SUN);
|
||||||
// We don't know if light should undiminish from this particular 0.
|
// We don't know if light should undiminish from this particular 0.
|
||||||
// Thus, keep it at 0.
|
// Thus, keep it at 0.
|
||||||
if (light == 0)
|
if (light == 0)
|
||||||
return 0;
|
return 0;
|
||||||
if (light == LIGHT_MAX)
|
if (light >= LIGHT_MAX)
|
||||||
return light;
|
return light;
|
||||||
|
|
||||||
return light + 1;
|
return light + 1;
|
||||||
@ -84,9 +85,9 @@ extern const u8 *light_decode_table;
|
|||||||
// 0 <= return value <= 255
|
// 0 <= return value <= 255
|
||||||
inline u8 decode_light(u8 light)
|
inline u8 decode_light(u8 light)
|
||||||
{
|
{
|
||||||
if (light > LIGHT_MAX)
|
// assert(light <= LIGHT_SUN);
|
||||||
light = LIGHT_MAX;
|
if (light > LIGHT_SUN)
|
||||||
|
light = LIGHT_SUN;
|
||||||
return light_decode_table[light];
|
return light_decode_table[light];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,8 +99,8 @@ inline float decode_light_f(float light_f)
|
|||||||
|
|
||||||
if (i <= 0)
|
if (i <= 0)
|
||||||
return (float)light_decode_table[0] / 255.0;
|
return (float)light_decode_table[0] / 255.0;
|
||||||
if (i >= LIGHT_MAX)
|
if (i >= LIGHT_SUN)
|
||||||
return (float)light_decode_table[LIGHT_MAX] / 255.0;
|
return (float)light_decode_table[LIGHT_SUN] / 255.0;
|
||||||
|
|
||||||
float v1 = (float)light_decode_table[i - 1] / 255.0;
|
float v1 = (float)light_decode_table[i - 1] / 255.0;
|
||||||
float v2 = (float)light_decode_table[i] / 255.0;
|
float v2 = (float)light_decode_table[i] / 255.0;
|
||||||
|
Loading…
Reference in New Issue
Block a user