mirror of
https://github.com/JonasunderscoreJones/nicer-skies.git
synced 2025-10-22 19:29:18 +02:00
change: tweak nebulas to be more detailed, higher res, more performant
This commit is contained in:
parent
ae12b15da1
commit
da1633bb92
3 changed files with 19 additions and 15 deletions
|
@ -22,7 +22,7 @@ public class NebulaSkyboxPainter extends SkyboxPainter {
|
|||
}
|
||||
|
||||
@Override
|
||||
int getColour(float x, float y, float z) {
|
||||
int getTexelColour(float x, float y, float z) {
|
||||
// Get projection
|
||||
float[] projCoords = this.projectOnSphere(x, y, z);
|
||||
x = projCoords[0];
|
||||
|
@ -38,10 +38,7 @@ public class NebulaSkyboxPainter extends SkyboxPainter {
|
|||
// Value of noise at coord, 0..1
|
||||
double noiseValue = Mth.clamp(noise.getValue(x * scalingFactor, y * scalingFactor, z * scalingFactor) + 0.5, 0, 1);
|
||||
|
||||
// Value to be subtracted from noise at coord, 0..1
|
||||
double subtractionValue = Mth.clamp(noise.getOctaveNoise(1)
|
||||
.noise(x * scalingFactor, y * scalingFactor, z * scalingFactor) + 0.5, 0D, 1D);
|
||||
|
||||
// Get the derivatives of the first (largest) octave of noise to shift the colour around with.
|
||||
double[] ds = new double[3];
|
||||
noise.getOctaveNoise(0).noiseWithDerivative(x * scalingFactor, y * scalingFactor, z * scalingFactor, ds);
|
||||
|
||||
|
@ -58,15 +55,17 @@ public class NebulaSkyboxPainter extends SkyboxPainter {
|
|||
nebulaFactor = 0;
|
||||
}
|
||||
|
||||
// Get the colour of the nebula and the amount of background colour to show at the current factor.
|
||||
int[] nebula = nebulaGradient.getAt(nebulaFactor);
|
||||
double bgFactor = Mth.clamp(Math.log10(-nebulaFactor + 1) + 1, 0, 1);
|
||||
|
||||
// todo: try and reduce brownish colours by reducing the green channel smoothly [failed attempt]
|
||||
|
||||
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);
|
||||
// Merge everything:
|
||||
// colour = nebulaFactor * [colour of nebula in that pixel] - [noise derivative in that pixel] * nebulaFactor + background colour * bgFactor
|
||||
int r = Mth.clamp((int) (nebulaFactor * nebula[0] - ds[0] * nebulaFactor * 128 + baseR * bgFactor), 0, 255);
|
||||
int g = Mth.clamp((int) (nebulaFactor * nebula[1] - ds[1] * nebulaFactor * 64 + baseG * bgFactor), 0, 255);
|
||||
int b = Mth.clamp((int) (nebulaFactor * nebula[2] - ds[2] * nebulaFactor * 128 + baseB * bgFactor), 0, 255);
|
||||
|
||||
// Get the alpha depending on the background factor
|
||||
int alpha = Mth.clamp((int) ((1 - bgFactor) * 255), 50, 255);
|
||||
|
||||
return FastColor.ARGB32.color(alpha, b, g, r);
|
||||
|
|
|
@ -3,7 +3,12 @@ package codes.ztereohype.nicerskies.sky.nebula;
|
|||
import codes.ztereohype.nicerskies.NicerSkies;
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.*;
|
||||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.Tesselator;
|
||||
import com.mojang.blaze3d.vertex.VertexBuffer;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -21,7 +26,7 @@ import java.util.function.BiFunction;
|
|||
|
||||
|
||||
public class Skybox {
|
||||
public static final int RESOLUTION = 512;
|
||||
public static final int RESOLUTION = 768;
|
||||
|
||||
private final DynamicTexture skyTexture = new DynamicTexture(RESOLUTION * 4, RESOLUTION * 4, false);
|
||||
|
||||
|
@ -79,7 +84,7 @@ public class Skybox {
|
|||
float y = location.getYFunc().apply(texX, texY);
|
||||
float z = location.getZFunc().apply(texX, texY);
|
||||
|
||||
skyNativeTex.setPixelRGBA(location.getXLocation(texX), location.getYLocation(texY), painter.getColour(x, y, z));
|
||||
skyNativeTex.setPixelRGBA(location.getXLocation(texX), location.getYLocation(texY), painter.getTexelColour(x, y, z));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,7 +99,7 @@ public class Skybox {
|
|||
NEG_ONE((texX, texY) -> -1F);
|
||||
|
||||
@Getter
|
||||
private BiFunction<Integer, Integer, Float> map;
|
||||
private final BiFunction<Integer, Integer, Float> map;
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
|
|
|
@ -10,7 +10,7 @@ public abstract class SkyboxPainter {
|
|||
this.noise = noise;
|
||||
}
|
||||
|
||||
abstract int getColour(float x, float y, float z);
|
||||
abstract int getTexelColour(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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue