change: tweak nebulas and unhardcode variables

This commit is contained in:
ZtereoHYPE 2022-12-10 04:13:21 +01:00
parent e377193e0e
commit 21b6b4d4c8

View file

@ -5,11 +5,10 @@ import net.minecraft.util.FastColor;
import net.minecraft.util.Mth;
import net.minecraft.world.level.levelgen.synth.PerlinNoise;
import java.awt.Color;
public class NebulaSkyboxPainter extends SkyboxPainter {
private static final float SCALING_FACTOR = 1f;
private static final float BASE_NOISE_AMOUNT = 0.56f; // the amount of base noise to keep
private static final float NOISE_AMOUNT = 0.51f; // the amount of base noise to keep
private static final int BASE_COLOUR_STRENGTH = 128;
private final Gradient nebulaGradient;
@ -28,9 +27,9 @@ public class NebulaSkyboxPainter extends SkyboxPainter {
// Get offset
float offset = (float) noise.getValue(x * SCALING_FACTOR * 3, y * SCALING_FACTOR * 3, z * SCALING_FACTOR * 3);
x = Mth.clamp(x + offset/5f, -1f, 1f);
y = Mth.clamp(y + offset/5f, -1f, 1f);
z = Mth.clamp(z + offset/5f, -1f, 1f);
x = Mth.clamp(x + offset / 5f, -1f, 1f);
y = Mth.clamp(y + offset / 5f, -1f, 1f);
z = Mth.clamp(z + offset / 5f, -1f, 1f);
// Value of noise at coord, 0..1
double noiseValue = Mth.clamp(noise.getValue(x * SCALING_FACTOR, y * SCALING_FACTOR, z * SCALING_FACTOR) + 0.5, 0, 1);
@ -42,27 +41,21 @@ public class NebulaSkyboxPainter extends SkyboxPainter {
noise.getOctaveNoise(0).noiseWithDerivative(x * SCALING_FACTOR, y * SCALING_FACTOR, z * SCALING_FACTOR, ds);
// Find a base background colour to use (xyz interpoaltion across sky, gamer mode)
int baseB = (int) ((x/2 + 0.5) * 127);
int baseG = (int) ((y/2 + 0.5) * 127);
int baseR = (int) ((z/2 + 0.5) * 127);
int baseB = (int) ((x / 2 + 0.5) * BASE_COLOUR_STRENGTH);
int baseG = (int) ((y / 2 + 0.5) * BASE_COLOUR_STRENGTH);
int baseR = (int) ((z / 2 + 0.5) * BASE_COLOUR_STRENGTH);
// double noiseAmount = (Mth.clamp((noiseValue * (1 / BASE_NOISE_AMOUNT) - (1 / BASE_NOISE_AMOUNT - 1)) * 255, 0, 255)); // otherwise death occurs
//
// int alpha = (int) Mth.clamp((int)noiseAmount - subtractionValue * 128, 50, 255);
double nebulaFactor = (Mth.clamp((noiseValue * (1D / BASE_NOISE_AMOUNT) - (1D / BASE_NOISE_AMOUNT - 1)), 0, 0.99));
Color nebula = nebulaGradient.getAt(nebulaFactor);
double nebulaFactor = (Mth.clamp((noiseValue * (1D / NOISE_AMOUNT) - (1D / NOISE_AMOUNT - 1)), 0, 0.99));
int[] nebula = nebulaGradient.getAt(nebulaFactor);
double bgFactor = Mth.clamp(Math.log10(-nebulaFactor + 1) + 1, 0, 1);
int r = Mth.clamp((int) ((nebulaFactor * nebula.getRed()) + baseR * bgFactor) - (int)(ds[0] * nebulaFactor * 127), 0, 255);
int g = Mth.clamp((int) ((nebulaFactor * nebula.getGreen()) + baseG * bgFactor) - (int)(ds[1] * nebulaFactor * 63), 0, 255);
int b = Mth.clamp((int) ((nebulaFactor * nebula.getBlue()) + baseB * bgFactor) - (int)(ds[2] * nebulaFactor * 127), 0, 255);
// todo: try and reduce brownish colours by reducing the green channel smoothly [failed attempt]
// int r = Mth.clamp((int) (baseR * bgFactor), 0, 255);
// int g = Mth.clamp((int) (baseG * bgFactor), 0, 255);
// int b = Mth.clamp((int) (baseB * bgFactor), 0, 255);
int r = Mth.clamp((int) ((nebulaFactor * nebula[0]) + baseR * bgFactor) - (int) (ds[0] * nebulaFactor * 128), 0, 255);
int g = Mth.clamp((int) ((nebulaFactor * nebula[1]) + baseG * bgFactor) - (int) (ds[1] * nebulaFactor * 64 * subtractionValue), 0, 255);
int b = Mth.clamp((int) ((nebulaFactor * nebula[2]) + baseB * bgFactor) - (int) (ds[2] * nebulaFactor * 128), 0, 255);
int alpha = Mth.clamp((int)((1 - bgFactor) * 255), 50, 255);
int alpha = Mth.clamp((int) ((1 - bgFactor) * 255), 50, 255);
return FastColor.ARGB32.color(alpha, b, g, r);
}