mirror of
https://github.com/JonasunderscoreJones/nicer-skies.git
synced 2025-10-22 19:29:18 +02:00
change: clean up starbox logic
This commit is contained in:
parent
da1633bb92
commit
c47e39b05c
4 changed files with 43 additions and 48 deletions
|
@ -19,29 +19,25 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
|
||||
@Mixin(LevelRenderer.class)
|
||||
public abstract class MixinStarRendering {
|
||||
public abstract class LevelRendererMixin {
|
||||
@Shadow private VertexBuffer starBuffer;
|
||||
@Shadow private int ticks;
|
||||
@Shadow private ClientLevel level;
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "createStars", cancellable = true)
|
||||
private void generateStars(CallbackInfo ci) {
|
||||
if (!NicerSkies.config.getTwinklingStars()) return;
|
||||
|
||||
starBuffer = new VertexBuffer();
|
||||
|
||||
BufferBuilder builder = Tesselator.getInstance().getBuilder();
|
||||
builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
||||
|
||||
starBuffer.bind();
|
||||
starBuffer.upload(builder.end());
|
||||
|
||||
ci.cancel();
|
||||
}
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "tick")
|
||||
private void tickStars(CallbackInfo ci) {
|
||||
if (!NicerSkies.config.getTwinklingStars() && NicerSkies.skyManager.isInitialized()) return;
|
||||
if (!NicerSkies.config.getTwinklingStars()) return;
|
||||
if (this.level.getStarBrightness(0) < 0.0F) return;
|
||||
NicerSkies.skyManager.tick(ticks, starBuffer);
|
||||
|
||||
NicerSkies.skyManager.tick(ticks);
|
||||
}
|
||||
|
||||
@ModifyArg(
|
||||
|
@ -50,6 +46,8 @@ public abstract class MixinStarRendering {
|
|||
index = 2
|
||||
)
|
||||
private ShaderInstance injectStarColour(ShaderInstance shaderInstance) {
|
||||
if (!NicerSkies.config.getTwinklingStars()) return shaderInstance;
|
||||
|
||||
return GameRenderer.getPositionColorShader();
|
||||
}
|
||||
|
||||
|
@ -59,7 +57,8 @@ public abstract class MixinStarRendering {
|
|||
locals = LocalCapture.CAPTURE_FAILHARD
|
||||
)
|
||||
private void drawSkybox(PoseStack poseStack, Matrix4f matrix4f, float f, Camera camera, boolean bl, Runnable runnable, CallbackInfo ci, FogType fogType, Vec3 vec3, float g, float h, float i, BufferBuilder bufferBuilder, ShaderInstance shaderInstance, float[] fs, float j, Matrix4f matrix4f3, float l, int s, int t, int n, float u, float p, float q, float r) {
|
||||
if (!NicerSkies.config.getNebulas() || !NicerSkies.skyManager.isInitialized()) return;
|
||||
if (!NicerSkies.config.getNebulas() || NicerSkies.skyManager.getSkybox() == null) return;
|
||||
|
||||
NicerSkies.skyManager.getSkybox().render(poseStack, matrix4f);
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@ public class StarSkyboxPainter extends SkyboxPainter {
|
|||
}
|
||||
|
||||
@Override
|
||||
int getColour(float x, float y, float z) {
|
||||
int getTexelColour(float x, float y, float z) {
|
||||
float[] projCoords = this.projectOnSphere(x, y, z);
|
||||
x = projCoords[0];
|
||||
y = projCoords[1];
|
||||
|
|
|
@ -60,31 +60,31 @@ public class Star {
|
|||
currentRadius = Mth.lerp(Mth.sin(ticks * resizeSpeed), minRadius, maxRadius);
|
||||
}
|
||||
|
||||
//return 4*3 coords for 4 vertices
|
||||
// public void setVertices(BufferBuilder bufferBuilder) {
|
||||
// float cosRot = Mth.cos(currentAngle);
|
||||
// float sinRot = Mth.sin(currentAngle);
|
||||
//
|
||||
// for (int v = 0; v < 4; ++v) {
|
||||
// // shift the vector to the 4 corners:
|
||||
// // vec 0, 1 --> -rad; vec 2, 3 --> +rad
|
||||
// float xShift = ((v & 2) - 1) * currentRadius;
|
||||
// // vec 1, 2 --> +rad; vec 3, 0 --> -rad
|
||||
// float yShift = (((v + 1) & 2) - 1) * currentRadius;
|
||||
//
|
||||
// float unprojectedVerticalOffset = xShift * cosRot - yShift * sinRot;
|
||||
// float unprojectedHorizontalOffset = yShift * cosRot + xShift * sinRot;
|
||||
// float latitudeCorrectedUnprojectedVerticalOffset = -unprojectedVerticalOffset * latitudeCos; // max negative +2pi, max positive -2pi
|
||||
//
|
||||
// float yOffset = unprojectedVerticalOffset * latitudeSin; // at ±pi should be max, squished at poles
|
||||
// float xOffset = latitudeCorrectedUnprojectedVerticalOffset * longitudeSin - unprojectedHorizontalOffset * longitudeCos;
|
||||
// float zOffset = unprojectedHorizontalOffset * longitudeSin + latitudeCorrectedUnprojectedVerticalOffset * longitudeCos;
|
||||
//
|
||||
// bufferBuilder.vertex(xCoord + xOffset, yCoord + yOffset, zCoord + zOffset)
|
||||
// .color(r, g, b, 255)
|
||||
// .endVertex();
|
||||
// }
|
||||
// }
|
||||
// Code left for readability
|
||||
/* public void setVertices(BufferBuilder bufferBuilder) {
|
||||
float cosRot = Mth.cos(currentAngle);
|
||||
float sinRot = Mth.sin(currentAngle);
|
||||
|
||||
for (int v = 0; v < 4; ++v) {
|
||||
// shift the vector to the 4 corners:
|
||||
// vec 0, 1 --> -rad; vec 2, 3 --> +rad
|
||||
float xShift = ((v & 2) - 1) * currentRadius;
|
||||
// vec 1, 2 --> +rad; vec 3, 0 --> -rad
|
||||
float yShift = (((v + 1) & 2) - 1) * currentRadius;
|
||||
|
||||
float unprojectedVerticalOffset = xShift * cosRot - yShift * sinRot;
|
||||
float unprojectedHorizontalOffset = yShift * cosRot + xShift * sinRot;
|
||||
float latitudeCorrectedUnprojectedVerticalOffset = -unprojectedVerticalOffset * latitudeCos; // max negative +2pi, max positive -2pi
|
||||
|
||||
float yOffset = unprojectedVerticalOffset * latitudeSin; // at ±pi should be max, squished at poles
|
||||
float xOffset = latitudeCorrectedUnprojectedVerticalOffset * longitudeSin - unprojectedHorizontalOffset * longitudeCos;
|
||||
float zOffset = unprojectedHorizontalOffset * longitudeSin + latitudeCorrectedUnprojectedVerticalOffset * longitudeCos;
|
||||
|
||||
bufferBuilder.vertex(xCoord + xOffset, yCoord + yOffset, zCoord + zOffset)
|
||||
.color(r, g, b, 255)
|
||||
.endVertex();
|
||||
}
|
||||
} */
|
||||
|
||||
public void setVertices(BufferBuilder bufferBuilder) {
|
||||
float horizontalVertexDistance = currentRadius * Mth.cos(currentAngle);
|
||||
|
|
|
@ -11,22 +11,18 @@ public class Starbox {
|
|||
private static final BufferBuilder STAR_BUFFER_BUILDER = Tesselator.getInstance().getBuilder();
|
||||
|
||||
private final int stars = 1500;
|
||||
private Gradient starGradient;
|
||||
|
||||
private ArrayList<Star> starList = new ArrayList<>();
|
||||
private final ArrayList<Star> starList = new ArrayList<>();
|
||||
private final VertexBuffer starBuffer;
|
||||
|
||||
public Starbox(RandomSource randomSource, Gradient starGradient) {
|
||||
this.generate(randomSource, starGradient);
|
||||
public Starbox(RandomSource randomSource, Gradient starGradient, VertexBuffer starBuffer) {
|
||||
this.starBuffer = starBuffer;
|
||||
this.generateStars(randomSource, starGradient);
|
||||
}
|
||||
|
||||
public void generate(RandomSource randomSource, Gradient starGradient) {
|
||||
private void generateStars(RandomSource randomSource, Gradient starGradient) {
|
||||
starList.clear();
|
||||
this.starGradient = starGradient;
|
||||
generateStars(randomSource);
|
||||
}
|
||||
|
||||
// not good practice: decrementing iteration variable
|
||||
private void generateStars(RandomSource randomSource) {
|
||||
ImprovedNoise noise = new ImprovedNoise(randomSource);
|
||||
|
||||
for (int i = 0; i < this.stars; ++i) {
|
||||
|
@ -49,7 +45,7 @@ public class Starbox {
|
|||
}
|
||||
}
|
||||
|
||||
public void updateStars(int ticks, VertexBuffer starBuffer) {
|
||||
public void updateStars(int ticks) {
|
||||
STAR_BUFFER_BUILDER.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
||||
|
||||
for (Star star : starList) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue