Fixed sky rendering

This commit is contained in:
paulevsGitch 2021-07-08 11:12:00 +03:00
parent c623da26ed
commit 93ca944472
2 changed files with 440 additions and 441 deletions

View file

@ -1,440 +1,439 @@
package ru.betterend.mixin.client; package ru.betterend.mixin.client;
import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.BufferBuilder; import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.DefaultVertexFormat; import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.Tesselator; import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.vertex.VertexBuffer; import com.mojang.blaze3d.vertex.VertexBuffer;
import com.mojang.blaze3d.vertex.VertexFormat; import com.mojang.blaze3d.vertex.VertexFormat;
import com.mojang.math.Matrix4f; import com.mojang.math.Matrix4f;
import com.mojang.math.Quaternion; import com.mojang.math.Quaternion;
import com.mojang.math.Vector3f; import com.mojang.math.Vector3f;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.DimensionSpecialEffects; import net.minecraft.client.renderer.DimensionSpecialEffects;
import net.minecraft.client.renderer.FogRenderer; import net.minecraft.client.renderer.FogRenderer;
import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.LevelRenderer; import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.RenderBuffers; import net.minecraft.client.renderer.RenderBuffers;
import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import ru.bclib.util.BackgroundInfo; import ru.bclib.util.BackgroundInfo;
import ru.bclib.util.MHelper; import ru.bclib.util.MHelper;
import ru.betterend.BetterEnd; import ru.betterend.BetterEnd;
import ru.betterend.client.ClientOptions; import ru.betterend.client.ClientOptions;
import java.util.Random; import java.util.Random;
@Mixin(LevelRenderer.class) @Mixin(LevelRenderer.class)
public class WorldRendererMixin { public class LevelRendererMixin {
private static final ResourceLocation NEBULA_1 = BetterEnd.makeID("textures/sky/nebula_2.png"); private static final ResourceLocation NEBULA_1 = BetterEnd.makeID("textures/sky/nebula_2.png");
private static final ResourceLocation NEBULA_2 = BetterEnd.makeID("textures/sky/nebula_3.png"); private static final ResourceLocation NEBULA_2 = BetterEnd.makeID("textures/sky/nebula_3.png");
private static final ResourceLocation HORIZON = BetterEnd.makeID("textures/sky/nebula_1.png"); private static final ResourceLocation HORIZON = BetterEnd.makeID("textures/sky/nebula_1.png");
private static final ResourceLocation STARS = BetterEnd.makeID("textures/sky/stars.png"); private static final ResourceLocation STARS = BetterEnd.makeID("textures/sky/stars.png");
private static final ResourceLocation FOG = BetterEnd.makeID("textures/sky/fog.png"); private static final ResourceLocation FOG = BetterEnd.makeID("textures/sky/fog.png");
private static VertexBuffer stars1; private static VertexBuffer stars1;
private static VertexBuffer stars2; private static VertexBuffer stars2;
private static VertexBuffer stars3; private static VertexBuffer stars3;
private static VertexBuffer stars4; private static VertexBuffer stars4;
private static VertexBuffer nebulas1; private static VertexBuffer nebulas1;
private static VertexBuffer nebulas2; private static VertexBuffer nebulas2;
private static VertexBuffer horizon; private static VertexBuffer horizon;
private static VertexBuffer fog; private static VertexBuffer fog;
private static Vector3f axis1; private static Vector3f axis1;
private static Vector3f axis2; private static Vector3f axis2;
private static Vector3f axis3; private static Vector3f axis3;
private static Vector3f axis4; private static Vector3f axis4;
private static float time; private static float time;
private static float time2; private static float time2;
private static float time3; private static float time3;
private static float blind02; private static float blind02;
private static float blind06; private static float blind06;
private static boolean directOpenGL = false; private static boolean directOpenGL = false;
@Shadow @Shadow
@Final @Final
private Minecraft minecraft; private Minecraft minecraft;
@Shadow @Shadow
@Final @Final
private TextureManager textureManager; private TextureManager textureManager;
@Shadow @Shadow
private ClientLevel level; private ClientLevel level;
@Shadow @Shadow
private int ticks; private int ticks;
@Inject(method = "<init>*", at = @At("TAIL")) @Inject(method = "<init>*", at = @At("TAIL"))
private void be_onInit(Minecraft client, RenderBuffers bufferBuilders, CallbackInfo info) { private void be_onInit(Minecraft client, RenderBuffers bufferBuilders, CallbackInfo info) {
be_initStars(); be_initStars();
Random random = new Random(131); Random random = new Random(131);
axis1 = new Vector3f(random.nextFloat(), random.nextFloat(), random.nextFloat()); axis1 = new Vector3f(random.nextFloat(), random.nextFloat(), random.nextFloat());
axis2 = new Vector3f(random.nextFloat(), random.nextFloat(), random.nextFloat()); axis2 = new Vector3f(random.nextFloat(), random.nextFloat(), random.nextFloat());
axis3 = new Vector3f(random.nextFloat(), random.nextFloat(), random.nextFloat()); axis3 = new Vector3f(random.nextFloat(), random.nextFloat(), random.nextFloat());
axis4 = new Vector3f(random.nextFloat(), random.nextFloat(), random.nextFloat()); axis4 = new Vector3f(random.nextFloat(), random.nextFloat(), random.nextFloat());
axis1.normalize(); axis1.normalize();
axis2.normalize(); axis2.normalize();
axis3.normalize(); axis3.normalize();
axis4.normalize(); axis4.normalize();
directOpenGL = FabricLoader.getInstance().isModLoaded("optifabric") || FabricLoader.getInstance().isModLoaded("immersive_portals"); directOpenGL = FabricLoader.getInstance().isModLoaded("optifabric") || FabricLoader.getInstance().isModLoaded("immersive_portals");
} }
@Inject(method = "renderSky", at = @At("HEAD"), cancellable = true) @Inject(method = "renderSky", at = @At("HEAD"), cancellable = true)
private void be_renderBetterEndSky(PoseStack matrices, Matrix4f matrix4f, float tickDelta, Runnable runnable, CallbackInfo info) { private void be_renderBetterEndSky(PoseStack matrices, Matrix4f matrix4f, float tickDelta, Runnable runnable, CallbackInfo info) {
if (ClientOptions.isCustomSky() && minecraft.level.effects().skyType() == DimensionSpecialEffects.SkyType.END) { if (ClientOptions.isCustomSky() && minecraft.level.effects().skyType() == DimensionSpecialEffects.SkyType.END) {
time = (ticks % 360000) * 0.000017453292F; runnable.run();
time2 = time * 2;
time3 = time * 3; time = (ticks % 360000) * 0.000017453292F;
time2 = time * 2;
FogRenderer.levelFogColor(); time3 = time * 3;
RenderSystem.enableTexture();
FogRenderer.levelFogColor();
if (directOpenGL) { RenderSystem.enableTexture();
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glAlphaFunc(516, 0.0F); if (directOpenGL) {
GL11.glEnable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_ALPHA_TEST);
RenderSystem.depthMask(false); GL11.glAlphaFunc(516, 0.0F);
} GL11.glEnable(GL11.GL_BLEND);
else { RenderSystem.depthMask(false);
//TODO: Removed in 1.17 }
//RenderSystem.enableAlphaTest(); else {
//RenderSystem.alphaFunc(516, 0.0F); RenderSystem.enableBlend();
RenderSystem.enableBlend(); RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); }
}
float blindA = 1F - BackgroundInfo.blindness;
float blindA = 1F - BackgroundInfo.blindness; blind02 = blindA * 0.2F;
blind02 = blindA * 0.2F; blind06 = blindA * 0.6F;
blind06 = blindA * 0.6F;
if (blindA > 0) {
if (blindA > 0) { matrices.pushPose();
matrices.pushPose(); matrices.mulPose(new Quaternion(0, time, 0, false));
matrices.mulPose(new Quaternion(0, time, 0, false)); RenderSystem.setShaderTexture(0, HORIZON);
RenderSystem.setShaderTexture(0, HORIZON); be_renderBuffer(matrices, matrix4f, horizon, DefaultVertexFormat.POSITION_TEX, 0.77F, 0.31F, 0.73F, 0.7F * blindA);
be_renderBuffer(matrices, matrix4f, horizon, DefaultVertexFormat.POSITION_TEX, 0.77F, 0.31F, 0.73F, 0.7F * blindA); matrices.popPose();
matrices.popPose();
matrices.pushPose();
matrices.pushPose(); matrices.mulPose(new Quaternion(0, -time, 0, false));
matrices.mulPose(new Quaternion(0, -time, 0, false)); RenderSystem.setShaderTexture(0, NEBULA_1);
RenderSystem.setShaderTexture(0, NEBULA_1); be_renderBuffer(matrices, matrix4f, nebulas1, DefaultVertexFormat.POSITION_TEX, 0.77F, 0.31F, 0.73F, blind02);
be_renderBuffer(matrices, matrix4f, nebulas1, DefaultVertexFormat.POSITION_TEX, 0.77F, 0.31F, 0.73F, blind02); matrices.popPose();
matrices.popPose();
matrices.pushPose();
matrices.pushPose(); matrices.mulPose(new Quaternion(0, time2, 0, false));
matrices.mulPose(new Quaternion(0, time2, 0, false)); RenderSystem.setShaderTexture(0, NEBULA_2);
RenderSystem.setShaderTexture(0, NEBULA_2); be_renderBuffer(matrices, matrix4f, nebulas2, DefaultVertexFormat.POSITION_TEX, 0.77F, 0.31F, 0.73F, blind02);
be_renderBuffer(matrices, matrix4f, nebulas2, DefaultVertexFormat.POSITION_TEX, 0.77F, 0.31F, 0.73F, blind02); matrices.popPose();
matrices.popPose();
RenderSystem.setShaderTexture(0, STARS);
RenderSystem.setShaderTexture(0, STARS);
matrices.pushPose();
matrices.pushPose(); matrices.mulPose(axis3.rotation(time));
matrices.mulPose(axis3.rotation(time)); be_renderBuffer(matrices, matrix4f, stars3, DefaultVertexFormat.POSITION_TEX, 0.77F, 0.31F, 0.73F, blind06);
be_renderBuffer(matrices, matrix4f, stars3, DefaultVertexFormat.POSITION_TEX, 0.77F, 0.31F, 0.73F, blind06); matrices.popPose();
matrices.popPose();
matrices.pushPose();
matrices.pushPose(); matrices.mulPose(axis4.rotation(time2));
matrices.mulPose(axis4.rotation(time2)); be_renderBuffer(matrices, matrix4f, stars4, DefaultVertexFormat.POSITION_TEX, 1F, 1F, 1F, blind06);
be_renderBuffer(matrices, matrix4f, stars4, DefaultVertexFormat.POSITION_TEX, 1F, 1F, 1F, blind06); matrices.popPose();
matrices.popPose(); }
}
float a = (BackgroundInfo.fogDensity - 1F);
float a = (BackgroundInfo.fogDensity - 1F); if (a > 0) {
if (a > 0) { if (a > 1) a = 1;
if (a > 1) a = 1; RenderSystem.setShaderTexture(0, FOG);
RenderSystem.setShaderTexture(0, FOG); be_renderBuffer(matrices, matrix4f, fog, DefaultVertexFormat.POSITION_TEX, BackgroundInfo.fogColorRed, BackgroundInfo.fogColorGreen, BackgroundInfo.fogColorBlue, a);
be_renderBuffer(matrices, matrix4f, fog, DefaultVertexFormat.POSITION_TEX, BackgroundInfo.fogColorRed, BackgroundInfo.fogColorGreen, BackgroundInfo.fogColorBlue, a); }
}
RenderSystem.disableTexture();
RenderSystem.disableTexture();
if (blindA > 0) {
if (blindA > 0) { matrices.pushPose();
matrices.pushPose(); matrices.mulPose(axis1.rotation(time3));
matrices.mulPose(axis1.rotation(time3)); be_renderBuffer(matrices, matrix4f, stars1, DefaultVertexFormat.POSITION, 1, 1, 1, blind06);
be_renderBuffer(matrices, matrix4f, stars1, DefaultVertexFormat.POSITION, 1, 1, 1, blind06); matrices.popPose();
matrices.popPose();
matrices.pushPose();
matrices.pushPose(); matrices.mulPose(axis2.rotation(time2));
matrices.mulPose(axis2.rotation(time2)); be_renderBuffer(matrices, matrix4f, stars2, DefaultVertexFormat.POSITION, 0.95F, 0.64F, 0.93F, blind06);
be_renderBuffer(matrices, matrix4f, stars2, DefaultVertexFormat.POSITION, 0.95F, 0.64F, 0.93F, blind06); matrices.popPose();
matrices.popPose(); }
}
RenderSystem.enableTexture();
RenderSystem.enableTexture(); RenderSystem.depthMask(true);
RenderSystem.depthMask(true); RenderSystem.defaultBlendFunc();
RenderSystem.defaultBlendFunc(); RenderSystem.disableBlend();
RenderSystem.disableBlend();
info.cancel();
info.cancel(); }
} }
}
private void be_renderBuffer(PoseStack matrices, Matrix4f matrix4f, VertexBuffer buffer, VertexFormat format, float r, float g, float b, float a) {
private void be_renderBuffer(PoseStack matrices, Matrix4f matrix4f, VertexBuffer buffer, VertexFormat format, float r, float g, float b, float a) { RenderSystem.setShaderColor(r, g, b, a);
RenderSystem.setShaderColor(r, g, b, a); if (format == DefaultVertexFormat.POSITION) {
buffer.bind(); buffer.drawWithShader(matrices.last().pose(), matrix4f, GameRenderer.getPositionShader());
format.setupBufferState(); }
buffer.drawWithShader(matrices.last().pose(), matrix4f, GameRenderer.getPositionTexShader()); else {
buffer.drawWithShader(matrices.last().pose(), matrix4f, GameRenderer.getPositionTexShader());
VertexBuffer.unbind(); }
format.clearBufferState(); }
}
private void be_initStars() {
private void be_initStars() { BufferBuilder buffer = Tesselator.getInstance().getBuilder();
BufferBuilder buffer = Tesselator.getInstance().getBuilder(); stars1 = be_buildBufferStars(buffer, stars1, 0.1, 0.30, 3500, 41315);
stars1 = be_buildBufferStars(buffer, stars1, 0.1, 0.30, 3500, 41315); stars2 = be_buildBufferStars(buffer, stars2, 0.1, 0.35, 2000, 35151);
stars2 = be_buildBufferStars(buffer, stars2, 0.1, 0.35, 2000, 35151); stars3 = be_buildBufferUVStars(buffer, stars3, 0.4, 1.2, 1000, 61354);
stars3 = be_buildBufferUVStars(buffer, stars3, 0.4, 1.2, 1000, 61354); stars4 = be_buildBufferUVStars(buffer, stars4, 0.4, 1.2, 1000, 61355);
stars4 = be_buildBufferUVStars(buffer, stars4, 0.4, 1.2, 1000, 61355); nebulas1 = be_buildBufferFarFog(buffer, nebulas1, 40, 60, 30, 11515);
nebulas1 = be_buildBufferFarFog(buffer, nebulas1, 40, 60, 30, 11515); nebulas2 = be_buildBufferFarFog(buffer, nebulas2, 40, 60, 10, 14151);
nebulas2 = be_buildBufferFarFog(buffer, nebulas2, 40, 60, 10, 14151); horizon = be_buildBufferHorizon(buffer, horizon);
horizon = be_buildBufferHorizon(buffer, horizon); fog = be_buildBufferFog(buffer, fog);
fog = be_buildBufferFog(buffer, fog); }
}
private VertexBuffer be_buildBufferStars(BufferBuilder bufferBuilder, VertexBuffer buffer, double minSize, double maxSize, int count, long seed) {
private VertexBuffer be_buildBufferStars(BufferBuilder bufferBuilder, VertexBuffer buffer, double minSize, double maxSize, int count, long seed) { if (buffer != null) {
if (buffer != null) { buffer.close();
buffer.close(); }
}
//TODO: Test if this is working correct
//TODO: Test if this is working correct //Format is set in the DrawState
//Format is set in the DrawState //buffer = new VertexBuffer(DefaultVertexFormat.POSITION);
//buffer = new VertexBuffer(DefaultVertexFormat.POSITION); buffer = new VertexBuffer();
buffer = new VertexBuffer(); be_makeStars(bufferBuilder, minSize, maxSize, count, seed);
be_makeStars(bufferBuilder, minSize, maxSize, count, seed); bufferBuilder.end();
bufferBuilder.end(); buffer.upload(bufferBuilder);
buffer.upload(bufferBuilder);
return buffer;
return buffer; }
}
private VertexBuffer be_buildBufferUVStars(BufferBuilder bufferBuilder, VertexBuffer buffer, double minSize, double maxSize, int count, long seed) {
private VertexBuffer be_buildBufferUVStars(BufferBuilder bufferBuilder, VertexBuffer buffer, double minSize, double maxSize, int count, long seed) { if (buffer != null) {
if (buffer != null) { buffer.close();
buffer.close(); }
}
// buffer = new VertexBuffer(DefaultVertexFormat.POSITION_TEX);
// buffer = new VertexBuffer(DefaultVertexFormat.POSITION_TEX); buffer = new VertexBuffer();
buffer = new VertexBuffer(); be_makeUVStars(bufferBuilder, minSize, maxSize, count, seed);
be_makeUVStars(bufferBuilder, minSize, maxSize, count, seed); bufferBuilder.end();
bufferBuilder.end(); buffer.upload(bufferBuilder);
buffer.upload(bufferBuilder);
return buffer;
return buffer; }
}
private VertexBuffer be_buildBufferFarFog(BufferBuilder bufferBuilder, VertexBuffer buffer, double minSize, double maxSize, int count, long seed) {
private VertexBuffer be_buildBufferFarFog(BufferBuilder bufferBuilder, VertexBuffer buffer, double minSize, double maxSize, int count, long seed) { if (buffer != null) {
if (buffer != null) { buffer.close();
buffer.close(); }
}
// buffer = new VertexBuffer(DefaultVertexFormat.POSITION_TEX);
// buffer = new VertexBuffer(DefaultVertexFormat.POSITION_TEX); buffer = new VertexBuffer();
buffer = new VertexBuffer(); be_makeFarFog(bufferBuilder, minSize, maxSize, count, seed);
be_makeFarFog(bufferBuilder, minSize, maxSize, count, seed); bufferBuilder.end();
bufferBuilder.end(); buffer.upload(bufferBuilder);
buffer.upload(bufferBuilder);
return buffer;
return buffer; }
}
private VertexBuffer be_buildBufferHorizon(BufferBuilder bufferBuilder, VertexBuffer buffer) {
private VertexBuffer be_buildBufferHorizon(BufferBuilder bufferBuilder, VertexBuffer buffer) { if (buffer != null) {
if (buffer != null) { buffer.close();
buffer.close(); }
}
// buffer = new VertexBuffer(DefaultVertexFormat.POSITION_TEX);
// buffer = new VertexBuffer(DefaultVertexFormat.POSITION_TEX); buffer = new VertexBuffer();
buffer = new VertexBuffer(); be_makeCylinder(bufferBuilder, 16, 50, 100);
be_makeCylinder(bufferBuilder, 16, 50, 100); bufferBuilder.end();
bufferBuilder.end(); buffer.upload(bufferBuilder);
buffer.upload(bufferBuilder);
return buffer;
return buffer; }
}
private VertexBuffer be_buildBufferFog(BufferBuilder bufferBuilder, VertexBuffer buffer) {
private VertexBuffer be_buildBufferFog(BufferBuilder bufferBuilder, VertexBuffer buffer) { if (buffer != null) {
if (buffer != null) { buffer.close();
buffer.close(); }
}
// buffer = new VertexBuffer(DefaultVertexFormat.POSITION_TEX);
// buffer = new VertexBuffer(DefaultVertexFormat.POSITION_TEX); buffer = new VertexBuffer();
buffer = new VertexBuffer(); be_makeCylinder(bufferBuilder, 16, 50, 70);
be_makeCylinder(bufferBuilder, 16, 50, 70); bufferBuilder.end();
bufferBuilder.end(); buffer.upload(bufferBuilder);
buffer.upload(bufferBuilder);
return buffer;
return buffer; }
}
private void be_makeStars(BufferBuilder buffer, double minSize, double maxSize, int count, long seed) {
private void be_makeStars(BufferBuilder buffer, double minSize, double maxSize, int count, long seed) { Random random = new Random(seed);
Random random = new Random(seed); buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION);
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION);
for (int i = 0; i < count; ++i) {
for (int i = 0; i < count; ++i) { double posX = random.nextDouble() * 2.0 - 1.0;
double posX = random.nextDouble() * 2.0 - 1.0; double posY = random.nextDouble() * 2.0 - 1.0;
double posY = random.nextDouble() * 2.0 - 1.0; double posZ = random.nextDouble() * 2.0 - 1.0;
double posZ = random.nextDouble() * 2.0 - 1.0; double size = MHelper.randRange(minSize, maxSize, random);
double size = MHelper.randRange(minSize, maxSize, random); double length = posX * posX + posY * posY + posZ * posZ;
double length = posX * posX + posY * posY + posZ * posZ; if (length < 1.0 && length > 0.001) {
if (length < 1.0 && length > 0.001) { length = 1.0 / Math.sqrt(length);
length = 1.0 / Math.sqrt(length); posX *= length;
posX *= length; posY *= length;
posY *= length; posZ *= length;
posZ *= length; double j = posX * 100.0;
double j = posX * 100.0; double k = posY * 100.0;
double k = posY * 100.0; double l = posZ * 100.0;
double l = posZ * 100.0; double m = Math.atan2(posX, posZ);
double m = Math.atan2(posX, posZ); double n = Math.sin(m);
double n = Math.sin(m); double o = Math.cos(m);
double o = Math.cos(m); double p = Math.atan2(Math.sqrt(posX * posX + posZ * posZ), posY);
double p = Math.atan2(Math.sqrt(posX * posX + posZ * posZ), posY); double q = Math.sin(p);
double q = Math.sin(p); double r = Math.cos(p);
double r = Math.cos(p); double s = random.nextDouble() * Math.PI * 2.0;
double s = random.nextDouble() * Math.PI * 2.0; double t = Math.sin(s);
double t = Math.sin(s); double u = Math.cos(s);
double u = Math.cos(s);
for (int v = 0; v < 4; ++v) {
for (int v = 0; v < 4; ++v) { double x = (double) ((v & 2) - 1) * size;
double x = (double) ((v & 2) - 1) * size; double y = (double) ((v + 1 & 2) - 1) * size;
double y = (double) ((v + 1 & 2) - 1) * size; double aa = x * u - y * t;
double aa = x * u - y * t; double ab = y * u + x * t;
double ab = y * u + x * t; double ad = aa * q + 0.0 * r;
double ad = aa * q + 0.0 * r; double ae = 0.0 * q - aa * r;
double ae = 0.0 * q - aa * r; double af = ae * n - ab * o;
double af = ae * n - ab * o; double ah = ab * n + ae * o;
double ah = ab * n + ae * o; buffer.vertex(j + af, k + ad, l + ah).endVertex();
buffer.vertex(j + af, k + ad, l + ah).endVertex(); }
} }
} }
} }
}
private void be_makeUVStars(BufferBuilder buffer, double minSize, double maxSize, int count, long seed) {
private void be_makeUVStars(BufferBuilder buffer, double minSize, double maxSize, int count, long seed) { Random random = new Random(seed);
Random random = new Random(seed); buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX);
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX);
for (int i = 0; i < count; ++i) {
for (int i = 0; i < count; ++i) { double posX = random.nextDouble() * 2.0 - 1.0;
double posX = random.nextDouble() * 2.0 - 1.0; double posY = random.nextDouble() * 2.0 - 1.0;
double posY = random.nextDouble() * 2.0 - 1.0; double posZ = random.nextDouble() * 2.0 - 1.0;
double posZ = random.nextDouble() * 2.0 - 1.0; double size = MHelper.randRange(minSize, maxSize, random);
double size = MHelper.randRange(minSize, maxSize, random); double length = posX * posX + posY * posY + posZ * posZ;
double length = posX * posX + posY * posY + posZ * posZ; if (length < 1.0 && length > 0.001) {
if (length < 1.0 && length > 0.001) { length = 1.0 / Math.sqrt(length);
length = 1.0 / Math.sqrt(length); posX *= length;
posX *= length; posY *= length;
posY *= length; posZ *= length;
posZ *= length; double j = posX * 100.0;
double j = posX * 100.0; double k = posY * 100.0;
double k = posY * 100.0; double l = posZ * 100.0;
double l = posZ * 100.0; double m = Math.atan2(posX, posZ);
double m = Math.atan2(posX, posZ); double n = Math.sin(m);
double n = Math.sin(m); double o = Math.cos(m);
double o = Math.cos(m); double p = Math.atan2(Math.sqrt(posX * posX + posZ * posZ), posY);
double p = Math.atan2(Math.sqrt(posX * posX + posZ * posZ), posY); double q = Math.sin(p);
double q = Math.sin(p); double r = Math.cos(p);
double r = Math.cos(p); double s = random.nextDouble() * Math.PI * 2.0;
double s = random.nextDouble() * Math.PI * 2.0; double t = Math.sin(s);
double t = Math.sin(s); double u = Math.cos(s);
double u = Math.cos(s);
int pos = 0;
int pos = 0; float minV = random.nextInt(4) / 4F;
float minV = random.nextInt(4) / 4F; for (int v = 0; v < 4; ++v) {
for (int v = 0; v < 4; ++v) { double x = (double) ((v & 2) - 1) * size;
double x = (double) ((v & 2) - 1) * size; double y = (double) ((v + 1 & 2) - 1) * size;
double y = (double) ((v + 1 & 2) - 1) * size; double aa = x * u - y * t;
double aa = x * u - y * t; double ab = y * u + x * t;
double ab = y * u + x * t; double ad = aa * q + 0.0 * r;
double ad = aa * q + 0.0 * r; double ae = 0.0 * q - aa * r;
double ae = 0.0 * q - aa * r; double af = ae * n - ab * o;
double af = ae * n - ab * o; double ah = ab * n + ae * o;
double ah = ab * n + ae * o; float texU = (pos >> 1) & 1;
float texU = (pos >> 1) & 1; float texV = (((pos + 1) >> 1) & 1) / 4F + minV;
float texV = (((pos + 1) >> 1) & 1) / 4F + minV; pos++;
pos++; buffer.vertex(j + af, k + ad, l + ah).uv(texU, texV).endVertex();
buffer.vertex(j + af, k + ad, l + ah).uv(texU, texV).endVertex(); }
} }
} }
} }
}
private void be_makeFarFog(BufferBuilder buffer, double minSize, double maxSize, int count, long seed) {
private void be_makeFarFog(BufferBuilder buffer, double minSize, double maxSize, int count, long seed) { Random random = new Random(seed);
Random random = new Random(seed); buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX);
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX);
for (int i = 0; i < count; ++i) {
for (int i = 0; i < count; ++i) { double posX = random.nextDouble() * 2.0 - 1.0;
double posX = random.nextDouble() * 2.0 - 1.0; double posY = random.nextDouble() - 0.5;
double posY = random.nextDouble() - 0.5; double posZ = random.nextDouble() * 2.0 - 1.0;
double posZ = random.nextDouble() * 2.0 - 1.0; double size = MHelper.randRange(minSize, maxSize, random);
double size = MHelper.randRange(minSize, maxSize, random); double length = posX * posX + posY * posY + posZ * posZ;
double length = posX * posX + posY * posY + posZ * posZ; double distance = 2.0;
double distance = 2.0; double delta = 1.0 / count;
double delta = 1.0 / count; if (length < 1.0 && length > 0.001) {
if (length < 1.0 && length > 0.001) { length = distance / Math.sqrt(length);
length = distance / Math.sqrt(length); size *= distance;
size *= distance; distance -= delta;
distance -= delta; posX *= length;
posX *= length; posY *= length;
posY *= length; posZ *= length;
posZ *= length; double j = posX * 100.0;
double j = posX * 100.0; double k = posY * 100.0;
double k = posY * 100.0; double l = posZ * 100.0;
double l = posZ * 100.0; double m = Math.atan2(posX, posZ);
double m = Math.atan2(posX, posZ); double n = Math.sin(m);
double n = Math.sin(m); double o = Math.cos(m);
double o = Math.cos(m); double p = Math.atan2(Math.sqrt(posX * posX + posZ * posZ), posY);
double p = Math.atan2(Math.sqrt(posX * posX + posZ * posZ), posY); double q = Math.sin(p);
double q = Math.sin(p); double r = Math.cos(p);
double r = Math.cos(p); double s = random.nextDouble() * Math.PI * 2.0;
double s = random.nextDouble() * Math.PI * 2.0; double t = Math.sin(s);
double t = Math.sin(s); double u = Math.cos(s);
double u = Math.cos(s);
int pos = 0;
int pos = 0; for (int v = 0; v < 4; ++v) {
for (int v = 0; v < 4; ++v) { double x = (double) ((v & 2) - 1) * size;
double x = (double) ((v & 2) - 1) * size; double y = (double) ((v + 1 & 2) - 1) * size;
double y = (double) ((v + 1 & 2) - 1) * size; double aa = x * u - y * t;
double aa = x * u - y * t; double ab = y * u + x * t;
double ab = y * u + x * t; double ad = aa * q + 0.0 * r;
double ad = aa * q + 0.0 * r; double ae = 0.0 * q - aa * r;
double ae = 0.0 * q - aa * r; double af = ae * n - ab * o;
double af = ae * n - ab * o; double ah = ab * n + ae * o;
double ah = ab * n + ae * o; float texU = (pos >> 1) & 1;
float texU = (pos >> 1) & 1; float texV = ((pos + 1) >> 1) & 1;
float texV = ((pos + 1) >> 1) & 1; pos++;
pos++; buffer.vertex(j + af, k + ad, l + ah).uv(texU, texV).endVertex();
buffer.vertex(j + af, k + ad, l + ah).uv(texU, texV).endVertex(); }
} }
} }
} }
}
private void be_makeCylinder(BufferBuilder buffer, int segments, double height, double radius) {
private void be_makeCylinder(BufferBuilder buffer, int segments, double height, double radius) { buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX);
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX); for (int i = 0; i < segments; i++) {
for (int i = 0; i < segments; i++) { double a1 = (double) i * Math.PI * 2.0 / (double) segments;
double a1 = (double) i * Math.PI * 2.0 / (double) segments; double a2 = (double) (i + 1) * Math.PI * 2.0 / (double) segments;
double a2 = (double) (i + 1) * Math.PI * 2.0 / (double) segments; double px1 = Math.sin(a1) * radius;
double px1 = Math.sin(a1) * radius; double pz1 = Math.cos(a1) * radius;
double pz1 = Math.cos(a1) * radius; double px2 = Math.sin(a2) * radius;
double px2 = Math.sin(a2) * radius; double pz2 = Math.cos(a2) * radius;
double pz2 = Math.cos(a2) * radius;
float u0 = (float) i / (float) segments;
float u0 = (float) i / (float) segments; float u1 = (float) (i + 1) / (float) segments;
float u1 = (float) (i + 1) / (float) segments;
buffer.vertex(px1, -height, pz1).uv(u0, 0).endVertex();
buffer.vertex(px1, -height, pz1).uv(u0, 0).endVertex(); buffer.vertex(px1, height, pz1).uv(u0, 1).endVertex();
buffer.vertex(px1, height, pz1).uv(u0, 1).endVertex(); buffer.vertex(px2, height, pz2).uv(u1, 1).endVertex();
buffer.vertex(px2, height, pz2).uv(u1, 1).endVertex(); buffer.vertex(px2, -height, pz2).uv(u1, 0).endVertex();
buffer.vertex(px2, -height, pz2).uv(u1, 0).endVertex(); }
} }
} }
}

View file

@ -11,7 +11,7 @@
"ClientRecipeBookMixin", "ClientRecipeBookMixin",
"MinecraftClientMixin", "MinecraftClientMixin",
"PlayerRendererMixin", "PlayerRendererMixin",
"WorldRendererMixin", "LevelRendererMixin",
"MusicTrackerMixin", "MusicTrackerMixin",
"AnvilScreenMixin", "AnvilScreenMixin",
"BiomeColorsMixin", "BiomeColorsMixin",