mirror of
https://github.com/JonasunderscoreJones/nicer-skies.git
synced 2025-10-23 11:49:17 +02:00
fix: render properly when rain and smoothen night transition
This commit is contained in:
parent
21558faad2
commit
e377193e0e
2 changed files with 23 additions and 12 deletions
|
@ -1,11 +1,8 @@
|
|||
package codes.ztereohype.example.mixin;
|
||||
|
||||
import codes.ztereohype.example.NicerSkies;
|
||||
import codes.ztereohype.example.core.NebulaSeedManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.*;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
|
@ -42,7 +39,7 @@ public abstract class MixinStarRendering {
|
|||
|
||||
@Inject(at = @At("HEAD"), method = "tick")
|
||||
private void tickStars(CallbackInfo ci) {
|
||||
if (!NicerSkies.config.getTwinklingStars()) return;
|
||||
if (!NicerSkies.config.getTwinklingStars() && NicerSkies.skyManager.isInitialized()) return;
|
||||
if (this.level.getStarBrightness(0) < 0.0F) return;
|
||||
NicerSkies.skyManager.tick(ticks, starBuffer);
|
||||
}
|
||||
|
@ -63,12 +60,6 @@ public abstract class MixinStarRendering {
|
|||
)
|
||||
private void drawSkybox(PoseStack poseStack, Matrix4f projectionMatrix, float partialTick, Camera camera, boolean bl, Runnable skyFogSetup, CallbackInfo ci, FogType fogType, Vec3 vec3, float f, float g, float h, BufferBuilder bufferBuilder, ShaderInstance shaderInstance, float[] fs, float i, Matrix4f matrix4f2, float k, int r, int s, int m, float t, float o, float p, float q) {
|
||||
if (!NicerSkies.config.getNebulas() || !NicerSkies.skyManager.isInitialized()) return;
|
||||
float alpha = 2 * level.getStarBrightness(partialTick) * (1.0F - this.level.getRainLevel(partialTick));
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, alpha);
|
||||
NicerSkies.skyManager.getSkybox().render(poseStack, projectionMatrix);
|
||||
}
|
||||
|
||||
// public void setStarBuffer(VertexBuffer starBuffer) {
|
||||
// this.starBuffer = starBuffer;
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -6,8 +6,11 @@ import com.mojang.blaze3d.systems.RenderSystem;
|
|||
import com.mojang.blaze3d.vertex.*;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.client.renderer.texture.DynamicTexture;
|
||||
import net.minecraft.util.Mth;
|
||||
|
||||
public class Skybox {
|
||||
public static final int RESOLUTION = 512;
|
||||
|
@ -25,12 +28,17 @@ public class Skybox {
|
|||
public void render(PoseStack poseStack, Matrix4f projectionMatrix) {
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.setShaderTexture(0, skyTexture.getId());
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, NicerSkies.config.getNebulaStrength());
|
||||
|
||||
float alpha = getSkyboxBrightness(Minecraft.getInstance().level);
|
||||
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, alpha);
|
||||
|
||||
this.skyboxBuffer.bind();
|
||||
this.skyboxBuffer.drawWithShader(poseStack.last().pose(), projectionMatrix, GameRenderer.getPositionTexShader());
|
||||
this.skyboxBuffer.drawWithShader(poseStack.last()
|
||||
.pose(), projectionMatrix, GameRenderer.getPositionTexShader());
|
||||
}
|
||||
|
||||
// todo: maybe multithread the hecc out of the generation to sped up the loading time
|
||||
public void paint(SkyboxPainter painter) {
|
||||
NativeImage skyNativeTex = this.skyTexture.getPixels();
|
||||
|
||||
|
@ -151,4 +159,16 @@ public class Skybox {
|
|||
skyboxBuffer.bind();
|
||||
skyboxBuffer.upload(skyboxBuilder.end());
|
||||
}
|
||||
|
||||
private float getSkyboxBrightness(ClientLevel level) {
|
||||
float config = NicerSkies.config.getNebulaStrength();
|
||||
|
||||
float timeOfDay = level.getTimeOfDay(0);
|
||||
float nightness = 1.0F - (Mth.cos(timeOfDay * (float) (Math.PI * 2)) * 4.0F + 0.5F);
|
||||
nightness = Mth.clamp(nightness, 0.0F, 1.0F);
|
||||
|
||||
float rain = level.getRainLevel(0);
|
||||
|
||||
return nightness * (1f - rain) * config;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue