wip: new nebula type start

This commit is contained in:
ZtereoHYPE 2022-10-13 12:00:09 +02:00
parent 49386dd851
commit c3ec766412
2 changed files with 59 additions and 1 deletions

View file

@ -3,6 +3,7 @@ package codes.ztereohype.example.sky;
import codes.ztereohype.example.Gradient;
import codes.ztereohype.example.sky.nebula.NebulaSkyboxPainter;
import codes.ztereohype.example.sky.nebula.Skybox;
import codes.ztereohype.example.sky.nebula.StarSkyboxPainter;
import codes.ztereohype.example.sky.star.Starbox;
import com.mojang.blaze3d.vertex.VertexBuffer;
import lombok.Getter;
@ -17,6 +18,7 @@ public class SkyManager {
private final Gradient starGradient = new Gradient();
private final Gradient nebulaGradient = new Gradient();
private final Gradient starryGradient = new Gradient();
public void generateSky(long seed) {
nebulaGradient.clear();
@ -29,6 +31,8 @@ public class SkyManager {
PerlinNoise perlinNoise = PerlinNoise.create(randomSource, IntStream.of(1, 2, 3, 4, 5));
NebulaSkyboxPainter painter = new NebulaSkyboxPainter(perlinNoise, nebulaGradient);
// StarSkyboxPainter painter = new StarSkyboxPainter(perlinNoise, starryGradient);
this.starbox = new Starbox(randomSource, starGradient);
this.skybox = new Skybox(painter);
}
@ -48,7 +52,7 @@ public class SkyManager {
nebulaGradient.add(0.8f, 255, 200, 123);
nebulaGradient.add(1.0f, 253, 243, 220);
// nebula_gradient.add(0.0f, 128, 0, 0);
// starryGradient.add(0.0f, 128, 128, 200);
// nebula_gradient.add(0.4f, 128, 0, 0);
// nebula_gradient.add(0.5f, 128, 0, 0);
// nebula_gradient.add(0.7f, 128, 0, 0);

View file

@ -0,0 +1,54 @@
package codes.ztereohype.example.sky.nebula;
import codes.ztereohype.example.Gradient;
import net.minecraft.util.FastColor;
import net.minecraft.util.Mth;
import net.minecraft.world.level.levelgen.synth.PerlinNoise;
import java.awt.*;
public class StarSkyboxPainter extends SkyboxPainter {
private static final float SCALING_FACTOR = 1.5f;
private static final float BASE_NOISE_AMOUNT = 0.45f; // the amount of base noise to keep
private final Gradient starryGradient;
public StarSkyboxPainter(PerlinNoise noise, Gradient starryGradient) {
super(noise);
this.starryGradient = starryGradient;
}
@Override
int getColour(float x, float y, float z) {
float[] projCoords = this.projectOnSphere(x, y, z);
x = projCoords[0];
y = projCoords[1];
z = projCoords[2];
// float offset = (float) noise.getValue(x * SCALING_FACTOR * 3, y * SCALING_FACTOR * 3, z * SCALING_FACTOR * 3);
//
// x += offset/10f;
// y += offset/10f;
// z += offset/10f;
// 0..1
double noiseValue = Mth.clamp(noise.getValue(x * SCALING_FACTOR, y * SCALING_FACTOR, z * SCALING_FACTOR) + 0.5, 0D, 1D);
// 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)) * 35D, 1D, 255.99D)); // otherwise death occurs
// alpha = (int) Mth.clamp(alpha - subtractionValue * 128, 0, 255); //todo subtract colour channels separately
double colourValue = Mth.clamp((alpha / 255D), 0D, 1D);
Color color = starryGradient.getAt(colourValue);
return FastColor.ARGB32.color(alpha, color.getBlue(), color.getGreen(), color.getRed());
}
}