Dense fog
This commit is contained in:
parent
b383c9f92e
commit
ce4405f3ea
4 changed files with 70 additions and 36 deletions
|
@ -22,14 +22,14 @@ import net.minecraft.util.math.MathHelper;
|
|||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.Biome.Category;
|
||||
import ru.betterend.registry.BiomeRegistry;
|
||||
import ru.betterend.util.BackgroundInfo;
|
||||
import ru.betterend.util.MHelper;
|
||||
import ru.betterend.world.biome.EndBiome;
|
||||
|
||||
@Mixin(BackgroundRenderer.class)
|
||||
public class BackgroundRendererMixin {
|
||||
private static float lastFogStart;
|
||||
private static float lastFogEnd;
|
||||
private static float fogStart;
|
||||
private static float fogEnd;
|
||||
private static float lastFogDensity;
|
||||
private static float fogDensity;
|
||||
private static float lerp;
|
||||
|
||||
//private static final float SKY_RED = 21F / 255F;
|
||||
|
@ -63,6 +63,10 @@ public class BackgroundRendererMixin {
|
|||
blue *= 4;
|
||||
}
|
||||
}
|
||||
|
||||
BackgroundInfo.red = red;
|
||||
BackgroundInfo.green = green;
|
||||
BackgroundInfo.blue = blue;
|
||||
}
|
||||
|
||||
@Inject(method = "applyFog", at = @At("HEAD"), cancellable = true)
|
||||
|
@ -73,22 +77,20 @@ public class BackgroundRendererMixin {
|
|||
if (biome.getCategory() == Category.THEEND && fluidState.isEmpty()) {
|
||||
EndBiome endBiome = BiomeRegistry.getFromBiome(biome);
|
||||
|
||||
if (fogEnd == 0) {
|
||||
fogStart = viewDistance * 0.75F / endBiome.getFogDensity();
|
||||
fogEnd = viewDistance / endBiome.getFogDensity();
|
||||
lastFogStart = fogStart;
|
||||
lastFogEnd = fogEnd;
|
||||
if (fogDensity == 0) {
|
||||
fogDensity = endBiome.getFogDensity();
|
||||
lastFogDensity = fogDensity;
|
||||
}
|
||||
if (lerp == 1) {
|
||||
lastFogStart = fogStart;
|
||||
lastFogEnd = fogEnd;
|
||||
fogStart = viewDistance * 0.75F / endBiome.getFogDensity();
|
||||
fogEnd = viewDistance / endBiome.getFogDensity();
|
||||
lastFogDensity = fogDensity;
|
||||
fogDensity = endBiome.getFogDensity();
|
||||
lerp = 0;
|
||||
}
|
||||
|
||||
RenderSystem.fogStart(MathHelper.lerp(lerp, lastFogStart, fogStart));
|
||||
RenderSystem.fogEnd(MathHelper.lerp(lerp, lastFogEnd, fogEnd));
|
||||
float fog = MathHelper.lerp(lerp, lastFogDensity, fogDensity);
|
||||
BackgroundInfo.fog = fog;
|
||||
RenderSystem.fogStart(viewDistance * 0.75F / fog);
|
||||
RenderSystem.fogEnd(viewDistance / fog);
|
||||
RenderSystem.fogMode(GlStateManager.FogMode.LINEAR);
|
||||
RenderSystem.setupNvFogDistance();
|
||||
info.cancel();
|
||||
|
|
|
@ -28,6 +28,7 @@ import net.minecraft.client.world.ClientWorld;
|
|||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.Quaternion;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.util.BackgroundInfo;
|
||||
import ru.betterend.util.MHelper;
|
||||
|
||||
@Mixin(WorldRenderer.class)
|
||||
|
@ -35,13 +36,15 @@ public class WorldRendererMixin {
|
|||
private static final Identifier NEBULA_1 = new Identifier(BetterEnd.MOD_ID, "textures/sky/nebula_2.png");
|
||||
private static final Identifier NEBULA_2 = new Identifier(BetterEnd.MOD_ID, "textures/sky/nebula_3.png");
|
||||
private static final Identifier HORIZON = new Identifier(BetterEnd.MOD_ID, "textures/sky/nebula_1.png");
|
||||
private static final Identifier FOG = new Identifier(BetterEnd.MOD_ID, "textures/sky/fog.png");
|
||||
|
||||
private static VertexBuffer customStarsBuffer1;
|
||||
private static VertexBuffer customStarsBuffer2;
|
||||
private static VertexBuffer customStarsBuffer3;
|
||||
private static VertexBuffer nebulas_1;
|
||||
private static VertexBuffer nebulas_2;
|
||||
private static VertexBuffer stars1;
|
||||
private static VertexBuffer stars2;
|
||||
private static VertexBuffer stars3;
|
||||
private static VertexBuffer nebulas1;
|
||||
private static VertexBuffer nebulas2;
|
||||
private static VertexBuffer horizon;
|
||||
private static VertexBuffer fog;
|
||||
private static Vector3f axis1;
|
||||
private static Vector3f axis2;
|
||||
private static Vector3f axis3;
|
||||
|
@ -92,30 +95,37 @@ public class WorldRendererMixin {
|
|||
matrices.push();
|
||||
matrices.multiply(new Quaternion(0, -time, 0, true));
|
||||
textureManager.bindTexture(NEBULA_1);
|
||||
renderBuffer(matrices, nebulas_1, VertexFormats.POSITION_TEXTURE, 0.77F, 0.31F, 0.73F, 0.2F);
|
||||
renderBuffer(matrices, nebulas1, VertexFormats.POSITION_TEXTURE, 0.77F, 0.31F, 0.73F, 0.2F);
|
||||
matrices.pop();
|
||||
|
||||
matrices.push();
|
||||
matrices.multiply(new Quaternion(0, time * 2, 0, true));
|
||||
textureManager.bindTexture(NEBULA_2);
|
||||
renderBuffer(matrices, nebulas_2, VertexFormats.POSITION_TEXTURE, 0.77F, 0.31F, 0.73F, 0.2F);
|
||||
renderBuffer(matrices, nebulas2, VertexFormats.POSITION_TEXTURE, 0.77F, 0.31F, 0.73F, 0.2F);
|
||||
matrices.pop();
|
||||
|
||||
float a = (BackgroundInfo.fog - 1F);
|
||||
if (a > 0) {
|
||||
if (a > 1) a = 1;
|
||||
textureManager.bindTexture(FOG);
|
||||
renderBuffer(matrices, fog, VertexFormats.POSITION_TEXTURE, BackgroundInfo.red, BackgroundInfo.green, BackgroundInfo.blue, a);
|
||||
}
|
||||
|
||||
RenderSystem.disableTexture();
|
||||
|
||||
matrices.push();
|
||||
matrices.multiply(new Quaternion(axis1, time * 3, true));
|
||||
renderBuffer(matrices, customStarsBuffer1, VertexFormats.POSITION, 1, 1, 1, 0.6F);
|
||||
renderBuffer(matrices, stars1, VertexFormats.POSITION, 1, 1, 1, 0.6F);
|
||||
matrices.pop();
|
||||
|
||||
matrices.push();
|
||||
matrices.multiply(new Quaternion(axis2, time * 2, true));
|
||||
renderBuffer(matrices, customStarsBuffer2, VertexFormats.POSITION, 0.95F, 0.64F, 0.93F, 0.6F);
|
||||
renderBuffer(matrices, stars2, VertexFormats.POSITION, 0.95F, 0.64F, 0.93F, 0.6F);
|
||||
matrices.pop();
|
||||
|
||||
matrices.push();
|
||||
matrices.multiply(new Quaternion(axis3, time, true));
|
||||
renderBuffer(matrices, customStarsBuffer3, VertexFormats.POSITION, 0.77F, 0.31F, 0.73F, 0.6F);
|
||||
renderBuffer(matrices, stars3, VertexFormats.POSITION, 0.77F, 0.31F, 0.73F, 0.6F);
|
||||
matrices.pop();
|
||||
|
||||
RenderSystem.enableTexture();
|
||||
|
@ -136,12 +146,13 @@ public class WorldRendererMixin {
|
|||
|
||||
private void initStars() {
|
||||
BufferBuilder buffer = Tessellator.getInstance().getBuffer();
|
||||
customStarsBuffer1 = buildBuffer(buffer, customStarsBuffer1, 0.1, 0.30, 3500, 41315);
|
||||
customStarsBuffer2 = buildBuffer(buffer, customStarsBuffer2, 0.1, 0.35, 2000, 35151);
|
||||
customStarsBuffer3 = buildBuffer(buffer, customStarsBuffer3, 0.1, 0.40, 1500, 61354);
|
||||
nebulas_1 = buildBufferFarFog(buffer, nebulas_1, 40, 60, 30, 11515);
|
||||
nebulas_2 = buildBufferFarFog(buffer, nebulas_2, 40, 60, 10, 14151);
|
||||
stars1 = buildBuffer(buffer, stars1, 0.1, 0.30, 3500, 41315);
|
||||
stars2 = buildBuffer(buffer, stars2, 0.1, 0.35, 2000, 35151);
|
||||
stars3 = buildBuffer(buffer, stars3, 0.1, 0.40, 1500, 61354);
|
||||
nebulas1 = buildBufferFarFog(buffer, nebulas1, 40, 60, 30, 11515);
|
||||
nebulas2 = buildBufferFarFog(buffer, nebulas2, 40, 60, 10, 14151);
|
||||
horizon = buildBufferHorizon(buffer, horizon);
|
||||
fog = buildBufferFog(buffer, fog);
|
||||
}
|
||||
|
||||
private VertexBuffer buildBuffer(BufferBuilder bufferBuilder, VertexBuffer buffer, double minSize, double maxSize, int count, long seed) {
|
||||
|
@ -176,7 +187,20 @@ public class WorldRendererMixin {
|
|||
}
|
||||
|
||||
buffer = new VertexBuffer(VertexFormats.POSITION_TEXTURE);
|
||||
makeHorizon(bufferBuilder, 16, 50);
|
||||
makeCylinder(bufferBuilder, 16, 50, 100);
|
||||
bufferBuilder.end();
|
||||
buffer.upload(bufferBuilder);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
private VertexBuffer buildBufferFog(BufferBuilder bufferBuilder, VertexBuffer buffer) {
|
||||
if (buffer != null) {
|
||||
buffer.close();
|
||||
}
|
||||
|
||||
buffer = new VertexBuffer(VertexFormats.POSITION_TEXTURE);
|
||||
makeCylinder(bufferBuilder, 16, 50, 70);
|
||||
bufferBuilder.end();
|
||||
buffer.upload(bufferBuilder);
|
||||
|
||||
|
@ -277,16 +301,16 @@ public class WorldRendererMixin {
|
|||
}
|
||||
}
|
||||
|
||||
private void makeHorizon(BufferBuilder buffer, int segments, double height) {
|
||||
private void makeCylinder(BufferBuilder buffer, int segments, double height, double radius) {
|
||||
buffer.begin(7, VertexFormats.POSITION_TEXTURE);
|
||||
for (int i = 0; i < segments; i ++)
|
||||
{
|
||||
double a1 = (double) i * Math.PI * 2.0 / (double) segments;
|
||||
double a2 = (double) (i + 1) * Math.PI * 2.0 / (double) segments;
|
||||
double px1 = Math.sin(a1) * 100;
|
||||
double pz1 = Math.cos(a1) * 100;
|
||||
double px2 = Math.sin(a2) * 100;
|
||||
double pz2 = Math.cos(a2) * 100;
|
||||
double px1 = Math.sin(a1) * radius;
|
||||
double pz1 = Math.cos(a1) * radius;
|
||||
double px2 = Math.sin(a2) * radius;
|
||||
double pz2 = Math.cos(a2) * radius;
|
||||
|
||||
float u0 = (float) i / (float) segments;
|
||||
float u1 = (float) (i + 1) / (float) segments;
|
||||
|
|
8
src/main/java/ru/betterend/util/BackgroundInfo.java
Normal file
8
src/main/java/ru/betterend/util/BackgroundInfo.java
Normal file
|
@ -0,0 +1,8 @@
|
|||
package ru.betterend.util;
|
||||
|
||||
public class BackgroundInfo {
|
||||
public static float red;
|
||||
public static float green;
|
||||
public static float blue;
|
||||
public static float fog = 1;
|
||||
}
|
BIN
src/main/resources/assets/betterend/textures/sky/fog.png
Normal file
BIN
src/main/resources/assets/betterend/textures/sky/fog.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 139 KiB |
Loading…
Add table
Add a link
Reference in a new issue