nicer-skies/src/main/java/codes/ztereohype/example/nebula/SkyboxPainter.java

25 lines
679 B
Java

package codes.ztereohype.example.nebula;
import net.minecraft.util.Mth;
import net.minecraft.world.level.levelgen.synth.PerlinNoise;
public abstract class SkyboxPainter {
protected final PerlinNoise noise;
SkyboxPainter(PerlinNoise noise) {
this.noise = noise;
}
abstract int getColour(float x, float y, float z);
public float[] projectOnSphere(float x, float y, float z) {
float invDistance = Mth.fastInvSqrt(x * x + y * y + z * z);
//divide by distance to get projection on sphere (shorten the vector)
x *= invDistance;
y *= invDistance;
z *= invDistance;
return new float[] {x, y, z};
}
}