TU25 Additions

Added getBlockLightColour for colored lights (Used in Halloween 2015)
getFogColor moved from dimension to biome.
Added isNatural and isFoggy (still not implemented)
This commit is contained in:
GabsPuNs
2026-04-24 21:36:03 -04:00
parent 85d36adf27
commit 9130eed526
18 changed files with 194 additions and 171 deletions

View File

@@ -876,17 +876,29 @@ void GameRenderer::updateLightTexture(float a)
Level *level = player->level;
int dimColor = level->dimension->getBlockLightColour();
float dimB = (float)((dimColor >> 16) & 0xFF) / 255.0f;
float dimG = (float)((dimColor >> 8) & 0xFF) / 255.0f;
float dimR = (float)(dimColor & 0xFF) / 255.0f;
const float skyDarken1 = level->getSkyDarken(1.0f);
#ifdef __AVX__
const float darken = skyDarken1 * 0.95f + 0.05f;
const float blockMult = (blr * 0.1f + 1.5f);
const float skyWeight = skyDarken1 * 0.65f + 0.35f;
const float darken = skyDarken1 * 0.95f + 0.05f;
#ifdef __AVX__
const float blockMult = (blr * 0.1f + 1.5f);
const __m256 vDarken = _mm256_set1_ps(darken);
const __m256 vSkyWeight = _mm256_set1_ps(skyWeight);
const __m256 vBlockMult = _mm256_set1_ps(blockMult);
const __m256 vDimR = _mm256_set1_ps(dimR);
const __m256 vDimG = _mm256_set1_ps(dimG);
const __m256 vDimB = _mm256_set1_ps(dimB);
const bool skyFlash = level->skyFlashTime < 0;
const bool isEnd = level->dimension->id == 1;
const bool hasNV = player->hasEffect(MobEffect::nightVision);
const float nvScale = hasNV ? getNightVisionScale(player, a) : 0.0f;
const __m256 vNVScale = _mm256_set1_ps(nvScale);
@@ -909,9 +921,13 @@ void GameRenderer::updateLightTexture(float a)
__m256 vGs = vRs;
__m256 vBs = vSky;
__m256 vRb = vBlock;
__m256 vGb = _mm256_mul_ps(vBlock, _mm256_add_ps(_mm256_mul_ps(_mm256_add_ps(_mm256_mul_ps(vBlock, _mm256_set1_ps(0.6f)), _mm256_set1_ps(0.4f)), _mm256_set1_ps(0.6f)), _mm256_set1_ps(0.4f)));
__m256 vBb = _mm256_mul_ps(vBlock, _mm256_add_ps(_mm256_mul_ps(_mm256_mul_ps(vBlock, vBlock), _mm256_set1_ps(0.6f)), _mm256_set1_ps(0.4f)));
__m256 vRb_base = vBlock;
__m256 vGb_base = _mm256_mul_ps(vBlock, _mm256_add_ps(_mm256_mul_ps(_mm256_add_ps(_mm256_mul_ps(vBlock, _mm256_set1_ps(0.6f)), _mm256_set1_ps(0.4f)), _mm256_set1_ps(0.6f)), _mm256_set1_ps(0.4f)));
__m256 vBb_base = _mm256_mul_ps(vBlock, _mm256_add_ps(_mm256_mul_ps(_mm256_mul_ps(vBlock, vBlock), _mm256_set1_ps(0.6f)), _mm256_set1_ps(0.4f)));
__m256 vRb = _mm256_mul_ps(vRb_base, vDimR);
__m256 vGb = _mm256_mul_ps(vGb_base, vDimG);
__m256 vBb = _mm256_mul_ps(vBb_base, vDimB);
__m256 vR = _mm256_add_ps(vRs, vRb);
__m256 vG = _mm256_add_ps(vGs, vGb);
@@ -921,23 +937,24 @@ void GameRenderer::updateLightTexture(float a)
vG = _mm256_add_ps(_mm256_mul_ps(vG, v096), v003);
vB = _mm256_add_ps(_mm256_mul_ps(vB, v096), v003);
if (darkenWorldAmount > 0) {
if (darkenWorldAmount > 0)
{
vR = _mm256_add_ps(_mm256_mul_ps(vR, vOneMinusAmount), _mm256_mul_ps(_mm256_mul_ps(vR, _mm256_set1_ps(0.7f)), vAmount));
vG = _mm256_add_ps(_mm256_mul_ps(vG, vOneMinusAmount), _mm256_mul_ps(_mm256_mul_ps(vG, _mm256_set1_ps(0.6f)), vAmount));
vB = _mm256_add_ps(_mm256_mul_ps(vB, vOneMinusAmount), _mm256_mul_ps(_mm256_mul_ps(vB, _mm256_set1_ps(0.6f)), vAmount));
}
if (isEnd) {
if (isEnd)
{
vR = _mm256_add_ps(_mm256_set1_ps(0.22f), _mm256_mul_ps(vRb, _mm256_set1_ps(0.75f)));
vG = _mm256_add_ps(_mm256_set1_ps(0.28f), _mm256_mul_ps(vGb, _mm256_set1_ps(0.75f)));
vB = _mm256_add_ps(_mm256_set1_ps(0.25f), _mm256_mul_ps(vBb, _mm256_set1_ps(0.75f)));
}
if (hasNV) {
__m256 vInvR = _mm256_rcp_ps(vR);
__m256 vInvG = _mm256_rcp_ps(vG);
__m256 vInvB = _mm256_rcp_ps(vB);
__m256 vDist = _mm256_min_ps(vInvR, _mm256_min_ps(vInvG, vInvB));
if (hasNV)
{
__m256 vMaxRGB = _mm256_max_ps(vR, _mm256_max_ps(vG, vB));
__m256 vDist = _mm256_rcp_ps(vMaxRGB);
vR = _mm256_add_ps(_mm256_mul_ps(vR, _mm256_sub_ps(vOne, vNVScale)), _mm256_mul_ps(_mm256_mul_ps(vR, vDist), vNVScale));
vG = _mm256_add_ps(_mm256_mul_ps(vG, _mm256_sub_ps(vOne, vNVScale)), _mm256_mul_ps(_mm256_mul_ps(vG, vDist), vNVScale));
@@ -970,22 +987,19 @@ void GameRenderer::updateLightTexture(float a)
#else
for (int i = 0; i < 256; i++)
{
const float darken = skyDarken1 * 0.95f + 0.05f;
float sky = level->dimension->brightnessRamp[i / 16] * darken;
const float block = level->dimension->brightnessRamp[i % 16] * (blr * 0.1f + 1.5f);
if (level->skyFlashTime < 0)
{
sky = level->dimension->brightnessRamp[i / 16];
}
const float rs = sky * (skyDarken1 * 0.65f + 0.35f);
const float gs = sky * (skyDarken1 * 0.65f + 0.35f);
const float rs = sky * skyWeight;
const float gs = sky * skyWeight;
const float bs = sky;
const float rb = block;
const float gb = block * ((block * 0.6f + 0.4f) * 0.6f + 0.4f);
const float bb = block * ((block * block) * 0.6f + 0.4f);
const float rb = block * dimR;
const float gb = (block * ((block * 0.6f + 0.4f) * 0.6f + 0.4f)) * dimG;
const float bb = (block * ((block * block) * 0.6f + 0.4f)) * dimB;
float _r = (rs + rb);
float _g = (gs + gb);
@@ -1013,28 +1027,15 @@ void GameRenderer::updateLightTexture(float a)
if (player->hasEffect(MobEffect::nightVision))
{
const float scale = getNightVisionScale(player, a);
float dist = 1.0f / _r;
if (dist > (1.0f / _g))
dist = (1.0f / _g);
if (dist > (1.0f / _b))
dist = (1.0f / _b);
float dist = 1.0f / fmax(_r, fmax(_g, _b));
_r = _r * (1.0f - scale) + (_r * dist) * scale;
_g = _g * (1.0f - scale) + (_g * dist) * scale;
_b = _b * (1.0f - scale) + (_b * dist) * scale;
}
if (_r > 1.0f)
_r = 1.0f;
if (_r < 0.0f)
_r = 0.0f;
if (_g > 1.0f)
_g = 1.0f;
if (_g < 0.0f)
_g = 0.0f;
if (_b > 1.0f)
_b = 1.0f;
if (_b < 0.0f)
_b = 0.0f;
_r = fmin(1.0f, fmax(0.0f, _r));
_g = fmin(1.0f, fmax(0.0f, _g));
_b = fmin(1.0f, fmax(0.0f, _b));
constexpr int alpha = 255;
const int r = static_cast<int>(_r * 255);
@@ -2056,12 +2057,12 @@ void GameRenderer::setupClearColor(float a)
float whiteness = 1.0f / (4 - mc->options->viewDistance);
whiteness = 1.0f - static_cast<float>(pow(static_cast<double>(whiteness), 0.25));
Vec3 *skyColor = level->getSkyColor(mc->cameraTargetPlayer, a);
Vec3 *skyColor = level->getSkyColor(player, a);
float sr = static_cast<float>(skyColor->x);
float sg = static_cast<float>(skyColor->y);
float sb = static_cast<float>(skyColor->z);
Vec3 *fogColor = level->getFogColor(a);
Vec3 *fogColor = level->getFogColor(player, a);
fr = static_cast<float>(fogColor->x);
fg = static_cast<float>(fogColor->y);
fb = static_cast<float>(fogColor->z);
@@ -2070,8 +2071,8 @@ void GameRenderer::setupClearColor(float a)
{
Vec3 *sunAngle = Mth::sin(level->getSunAngle(a)) > 0 ? Vec3::newTemp(-1, 0, 0) : Vec3::newTemp(1, 0, 0);
float d = static_cast<float>(player->getViewVector(a)->dot(sunAngle));
if (d < 0) d = 0;
if (d > 0)
d = fmaxf(0.0f, d);
if (d > 0.0f)
{
float *c = level->dimension->getSunriseColor(level->getTimeOfDay(a), a);
if (c != nullptr)
@@ -2152,24 +2153,12 @@ void GameRenderer::setupClearColor(float a)
if (player->hasEffect(MobEffect::blindness))
{
int duration = player->getEffect(MobEffect::blindness)->getDuration();
if (duration < 20)
{
yy = yy * (1.0f - static_cast<float>(duration) / 20.0f);
}
else
{
yy = 0.0;
}
yy *= (duration < 20) ? (1.0f - static_cast<float>(duration) / 20.0f) : 0.0;
}
if (yy < 1.0)
{
if (yy < 0.0) yy = 0.0;
yy = yy * yy;
fr *= yy;
fg *= yy;
fb *= yy;
}
yy = fmax(0.0, fmin(1.0, yy));
double yy2 = yy * yy;
fr *= yy2; fg *= yy2; fb *= yy2;
if (darkenWorldAmount > 0)
{
@@ -2183,19 +2172,9 @@ void GameRenderer::setupClearColor(float a)
{
float scale = getNightVisionScale(mc->player, a);
{
float dist = FLT_MAX; // MGH - changed this to avoid divide by zero
if ( (fr > 0) && (dist > (1.0f / fr)) )
{
dist = (1.0f / fr);
}
if ( (fg > 0) && (dist > (1.0f / fg)) )
{
dist = (1.0f / fg);
}
if ( (fb > 0) && (dist > (1.0f / fb)) )
{
dist = (1.0f / fb);
}
float maxCol = fmaxf(fr, fmaxf(fg, fb));
float dist = (maxCol > 0.0f) ? (1.0f / maxCol) : 1.0f;
fr = fr * (1.0f - scale) + (fr * dist) * scale;
fg = fg * (1.0f - scale) + (fg * dist) * scale;
fb = fb * (1.0f - scale) + (fb * dist) * scale;