Thick fog rendering fixes

This commit is contained in:
paulevsGitch 2021-10-22 13:50:07 +03:00
parent da0d122166
commit 52146286fe
2 changed files with 50 additions and 32 deletions

View file

@ -3,6 +3,7 @@ package ru.bclib.client.render;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.Camera; import net.minecraft.client.Camera;
import net.minecraft.client.renderer.FogRenderer; import net.minecraft.client.renderer.FogRenderer;
import net.minecraft.client.renderer.FogRenderer.FogMode;
import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.effect.MobEffectInstance;
@ -22,18 +23,35 @@ public class CustomBackgroundRenderer {
private static final MutableBlockPos MUT_POS = new MutableBlockPos(); private static final MutableBlockPos MUT_POS = new MutableBlockPos();
private static final float[] FOG_DENSITY = new float[8]; private static final float[] FOG_DENSITY = new float[8];
private static final int GRID_SIZE = 32; private static final int GRID_SIZE = 32;
private static float fogStart = 0;
private static float fogEnd = 192;
public static boolean applyFogDensity(Camera camera, FogRenderer.FogMode fogMode, float viewDistance, boolean thickFog) { public static boolean applyFogDensity(Camera camera, FogRenderer.FogMode fogMode, float viewDistance, boolean thickFog) {
Entity entity = camera.getEntity();
FogType fogType = camera.getFluidInCamera(); FogType fogType = camera.getFluidInCamera();
if (fogType != FogType.WATER) {
if (fogType == FogType.WATER || fogType == FogType.LAVA || fogMode != FogMode.FOG_SKY) {
return false;
}
Entity entity = camera.getEntity();
if (shouldIgnore(entity.level, (int) entity.getX(), (int) entity.getEyeY(), (int) entity.getZ())) { if (shouldIgnore(entity.level, (int) entity.getX(), (int) entity.getEyeY(), (int) entity.getZ())) {
return false; return false;
} }
float fog = getFogDensity(entity.level, entity.getX(), entity.getEyeY(), entity.getZ()); float fog = getFogDensity(entity.level, entity.getX(), entity.getEyeY(), entity.getZ());
BackgroundInfo.fogDensity = fog; BackgroundInfo.fogDensity = fog;
float start = viewDistance * 0.75F / fog;
float end = viewDistance / fog; System.out.println(thickFog);
if (thickFog) {
fogStart = viewDistance * 0.05F / fog;
fogEnd = Math.min(viewDistance, 192.0F) * 0.5F / fog;
}
else {
fogStart = viewDistance * 0.75F / fog;
fogEnd = viewDistance / fog;
}
if (entity instanceof LivingEntity) { if (entity instanceof LivingEntity) {
LivingEntity livingEntity = (LivingEntity) entity; LivingEntity livingEntity = (LivingEntity) entity;
@ -41,15 +59,15 @@ public class CustomBackgroundRenderer {
if (effect != null) { if (effect != null) {
int duration = effect.getDuration(); int duration = effect.getDuration();
if (duration > 20) { if (duration > 20) {
start = 0; fogStart = 0;
end *= 0.03F; fogEnd *= 0.03F;
BackgroundInfo.blindness = 1; BackgroundInfo.blindness = 1;
} }
else { else {
float delta = (float) duration / 20F; float delta = (float) duration / 20F;
BackgroundInfo.blindness = delta; BackgroundInfo.blindness = delta;
start = Mth.lerp(delta, start, 0); fogStart = Mth.lerp(delta, fogStart, 0);
end = Mth.lerp(delta, end, end * 0.03F); fogEnd = Mth.lerp(delta, fogEnd, fogEnd * 0.03F);
} }
} }
else { else {
@ -57,12 +75,11 @@ public class CustomBackgroundRenderer {
} }
} }
RenderSystem.setShaderFogStart(start); RenderSystem.setShaderFogStart(fogStart);
RenderSystem.setShaderFogEnd(end); RenderSystem.setShaderFogEnd(fogEnd);
return true; return true;
} }
return false;
}
private static boolean shouldIgnore(Level level, int x, int y, int z) { private static boolean shouldIgnore(Level level, int x, int y, int z) {
Biome biome = level.getBiome(MUT_POS.set(x, y, z)); Biome biome = level.getBiome(MUT_POS.set(x, y, z));

View file

@ -23,6 +23,7 @@ public class BackgroundRendererMixin {
private static final MutableBlockPos BCLIB_LAST_POS = new MutableBlockPos(0, -100, 0); private static final MutableBlockPos BCLIB_LAST_POS = new MutableBlockPos(0, -100, 0);
private static final MutableBlockPos BCLIB_MUT_POS = new MutableBlockPos(); private static final MutableBlockPos BCLIB_MUT_POS = new MutableBlockPos();
private static final float[] BCLIB_FOG_DENSITY = new float[8]; private static final float[] BCLIB_FOG_DENSITY = new float[8];
//private static boolean isEnd;
@Shadow @Shadow
private static float fogRed; private static float fogRed;