Thick fog rendering fixes
This commit is contained in:
parent
da0d122166
commit
52146286fe
2 changed files with 50 additions and 32 deletions
|
@ -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,46 +23,62 @@ 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 (shouldIgnore(entity.level, (int) entity.getX(), (int) entity.getEyeY(), (int) entity.getZ())) {
|
if (fogType == FogType.WATER || fogType == FogType.LAVA || fogMode != FogMode.FOG_SKY) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
float fog = getFogDensity(entity.level, entity.getX(), entity.getEyeY(), entity.getZ());
|
|
||||||
BackgroundInfo.fogDensity = fog;
|
Entity entity = camera.getEntity();
|
||||||
float start = viewDistance * 0.75F / fog;
|
|
||||||
float end = viewDistance / fog;
|
if (shouldIgnore(entity.level, (int) entity.getX(), (int) entity.getEyeY(), (int) entity.getZ())) {
|
||||||
|
return false;
|
||||||
if (entity instanceof LivingEntity) {
|
}
|
||||||
LivingEntity livingEntity = (LivingEntity) entity;
|
|
||||||
MobEffectInstance effect = livingEntity.getEffect(MobEffects.BLINDNESS);
|
float fog = getFogDensity(entity.level, entity.getX(), entity.getEyeY(), entity.getZ());
|
||||||
if (effect != null) {
|
BackgroundInfo.fogDensity = fog;
|
||||||
int duration = effect.getDuration();
|
|
||||||
if (duration > 20) {
|
System.out.println(thickFog);
|
||||||
start = 0;
|
|
||||||
end *= 0.03F;
|
if (thickFog) {
|
||||||
BackgroundInfo.blindness = 1;
|
fogStart = viewDistance * 0.05F / fog;
|
||||||
}
|
fogEnd = Math.min(viewDistance, 192.0F) * 0.5F / fog;
|
||||||
else {
|
}
|
||||||
float delta = (float) duration / 20F;
|
else {
|
||||||
BackgroundInfo.blindness = delta;
|
fogStart = viewDistance * 0.75F / fog;
|
||||||
start = Mth.lerp(delta, start, 0);
|
fogEnd = viewDistance / fog;
|
||||||
end = Mth.lerp(delta, end, end * 0.03F);
|
}
|
||||||
}
|
|
||||||
|
if (entity instanceof LivingEntity) {
|
||||||
|
LivingEntity livingEntity = (LivingEntity) entity;
|
||||||
|
MobEffectInstance effect = livingEntity.getEffect(MobEffects.BLINDNESS);
|
||||||
|
if (effect != null) {
|
||||||
|
int duration = effect.getDuration();
|
||||||
|
if (duration > 20) {
|
||||||
|
fogStart = 0;
|
||||||
|
fogEnd *= 0.03F;
|
||||||
|
BackgroundInfo.blindness = 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
BackgroundInfo.blindness = 0;
|
float delta = (float) duration / 20F;
|
||||||
|
BackgroundInfo.blindness = delta;
|
||||||
|
fogStart = Mth.lerp(delta, fogStart, 0);
|
||||||
|
fogEnd = Mth.lerp(delta, fogEnd, fogEnd * 0.03F);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
RenderSystem.setShaderFogStart(start);
|
BackgroundInfo.blindness = 0;
|
||||||
RenderSystem.setShaderFogEnd(end);
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
RenderSystem.setShaderFogStart(fogStart);
|
||||||
|
RenderSystem.setShaderFogEnd(fogEnd);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean shouldIgnore(Level level, int x, int y, int z) {
|
private static boolean shouldIgnore(Level level, int x, int y, int z) {
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue