change: gamer rgb nebulas wip

This commit is contained in:
ZtereoHYPE 2022-11-06 22:46:19 +01:00
parent 334235761b
commit 783a71c0e2
2 changed files with 26 additions and 11 deletions

View file

@ -15,7 +15,7 @@ public class Gradient {
if (index < 0 || index > 1) {
throw new IllegalArgumentException("Index must be between 0 and 1");
}
Color color = new Color(red,green,blue);
gradient.put(index, color);
}

View file

@ -20,35 +20,50 @@ public class NebulaSkyboxPainter extends SkyboxPainter {
@Override
int getColour(float x, float y, float z) {
// Get projection
float[] projCoords = this.projectOnSphere(x, y, z);
x = projCoords[0];
y = projCoords[1];
z = projCoords[2];
// 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 += offset/5f;
y += offset/5f;
z += offset/5f;
// 0..1
// Value of noise at coord, 0..1
double noiseValue = Mth.clamp(noise.getValue(x * SCALING_FACTOR, y * SCALING_FACTOR, z * SCALING_FACTOR) + 0.5, 0D, 1D);
// 0..1
// Value to be subtracted from noise at coord, 0..1
double subtractionValue = Mth.clamp(noise.getOctaveNoise(1).noise(x * SCALING_FACTOR, y * SCALING_FACTOR, z * SCALING_FACTOR) + 0.5, 0D, 1D);
// double[] derivates = new double[3];
// noise.getOctaveNoise(0).noiseWithDerivative(x * SCALING_FACTOR, y * SCALING_FACTOR, z * SCALING_FACTOR, derivates);
// double maxDerivative = Mth.clamp(Math.max(Math.max(derivates[0], derivates[1]), derivates[2]) * 0.5 + 0.5, 0, 0);
int alpha = (int)(Mth.clamp((noiseValue * (1D / BASE_NOISE_AMOUNT) - (1D / BASE_NOISE_AMOUNT - 1)) * 255D, 1D, 254.99D)); // otherwise death occurs
// Find a base background colour to use (xyz interpoaltion across sky, gamer mode)
int blueness, greenness, redness;
blueness = (int) ((x/2 + 0.5) * 127);
greenness = (int) ((y/2 + 0.5) * 127);
redness = (int) ((z/2 + 0.5) * 127);
alpha = (int) Mth.clamp(alpha - subtractionValue * 128, 0, 255); //todo subtract colour channels separately
int alpha = (int)(Mth.clamp((noiseValue * (1D / BASE_NOISE_AMOUNT) - (1D / BASE_NOISE_AMOUNT - 1)) * 255D, 20D, 254.99D)); // otherwise death occurs
double colourValue = Mth.clamp((alpha / 255D), 0D, 1D);
alpha = (int) Mth.clamp(alpha - subtractionValue * 128, 50, 255);
//todo: make nebulas be -1..+1 and they can also subtract a little from the main colour, but they can also add some yellow or red or idk
double colourValue = (Mth.clamp((noiseValue * (1D / BASE_NOISE_AMOUNT) - (1D / BASE_NOISE_AMOUNT - 1)), 0.01D, 0.9999D));
Color color = nebulaGradient.getAt(colourValue);
double bgPresence = Mth.clamp(Math.log10(-colourValue + 1) + 1, 0D, 1D);
return FastColor.ARGB32.color(alpha, color.getBlue(), color.getGreen(), color.getRed());
int red, green, blue;
red = (int) ((colourValue * color.getRed()) + redness * bgPresence);
green = (int) ((colourValue * color.getGreen()) + greenness * bgPresence);
blue = (int) ((colourValue * color.getBlue()) + blueness * bgPresence);
return FastColor.ARGB32.color(alpha, blue, green, red);
// return FastColor.ARGB32.color(alpha, color.getBlue(), color.getGreen(), color.getRed());
}
}