Fog rendering fixes

This commit is contained in:
paulevsGitch 2021-12-23 09:23:26 +03:00
parent 3cb78dd5a5
commit c947af1211
3 changed files with 62 additions and 68 deletions

View file

@ -27,9 +27,7 @@ public class CustomBackgroundRenderer {
private static float fogEnd = 192;
public static boolean applyFogDensity(Camera camera, FogRenderer.FogMode fogMode, float viewDistance, boolean thickFog) {
FogType fogType = camera.getFluidInCamera();
if (fogType == FogType.WATER || fogType == FogType.LAVA || fogMode != FogMode.FOG_SKY) {
if (fogMode != FogMode.FOG_SKY && fogMode != FogMode.FOG_TERRAIN) {
BackgroundInfo.fogDensity = 1;
return false;
}
@ -49,7 +47,7 @@ public class CustomBackgroundRenderer {
fogEnd = Math.min(viewDistance, 192.0F) * 0.5F / fog;
}
else {
fogStart = viewDistance * 0.75F / fog;
fogStart = 0;//viewDistance * 0.75F / fog;
fogEnd = viewDistance / fog;
}

View file

@ -1,63 +1,59 @@
package ru.bclib.mixin.client;
import net.minecraft.client.Camera;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.FogRenderer;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.material.FogType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import ru.bclib.client.render.CustomBackgroundRenderer;
import ru.bclib.util.BackgroundInfo;
@Mixin(FogRenderer.class)
public class BackgroundRendererMixin {
private static final MutableBlockPos BCLIB_LAST_POS = new MutableBlockPos(0, -100, 0);
private static final MutableBlockPos BCLIB_MUT_POS = new MutableBlockPos();
private static final float[] BCLIB_FOG_DENSITY = new float[8];
//private static boolean isEnd;
@Shadow
private static float fogRed;
@Shadow
private static float fogGreen;
@Shadow
private static float fogBlue;
@Inject(method = "setupColor", at = @At("RETURN"))
private static void bclib_onRender(Camera camera, float tickDelta, ClientLevel world, int i, float f, CallbackInfo info) {
FogType fogType = camera.getFluidInCamera();
if (fogType != FogType.WATER && world.dimension().equals(Level.END)) {
Entity entity = camera.getEntity();
boolean skip = false;
if (entity instanceof LivingEntity) {
MobEffectInstance effect = ((LivingEntity) entity).getEffect(MobEffects.NIGHT_VISION);
skip = effect != null && effect.getDuration() > 0;
}
if (!skip) {
fogRed *= 4;
fogGreen *= 4;
fogBlue *= 4;
}
}
BackgroundInfo.fogColorRed = fogRed;
BackgroundInfo.fogColorGreen = fogGreen;
BackgroundInfo.fogColorBlue = fogBlue;
}
@Inject(method = "setupFog", at = @At("HEAD"), cancellable = true)
private static void bclib_fogDensity(Camera camera, FogRenderer.FogMode fogMode, float viewDistance, boolean thickFog, CallbackInfo info) {
if (CustomBackgroundRenderer.applyFogDensity(camera, fogMode, viewDistance, thickFog)) {
info.cancel();
}
}
}
package ru.bclib.mixin.client;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.Camera;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.FogRenderer;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.material.FogType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import ru.bclib.client.render.CustomBackgroundRenderer;
import ru.bclib.util.BackgroundInfo;
@Mixin(FogRenderer.class)
public class FogRendererMixin {
@Shadow
private static float fogRed;
@Shadow
private static float fogGreen;
@Shadow
private static float fogBlue;
@Inject(method = "setupColor", at = @At("RETURN"))
private static void bclib_onRender(Camera camera, float tickDelta, ClientLevel world, int i, float f, CallbackInfo info) {
FogType fogType = camera.getFluidInCamera();
if (fogType != FogType.WATER && world.dimension().equals(Level.END)) {
Entity entity = camera.getEntity();
boolean skip = false;
if (entity instanceof LivingEntity) {
MobEffectInstance effect = ((LivingEntity) entity).getEffect(MobEffects.NIGHT_VISION);
skip = effect != null && effect.getDuration() > 0;
}
if (!skip) {
fogRed *= 4;
fogGreen *= 4;
fogBlue *= 4;
}
}
BackgroundInfo.fogColorRed = fogRed;
BackgroundInfo.fogColorGreen = fogGreen;
BackgroundInfo.fogColorBlue = fogBlue;
}
@Inject(method = "setupFog", at = @At("HEAD"), cancellable = true)
private static void bclib_fogDensity(Camera camera, FogRenderer.FogMode fogMode, float viewDistance, boolean thickFog, CallbackInfo info) {
if (CustomBackgroundRenderer.applyFogDensity(camera, fogMode, viewDistance, thickFog)) {
info.cancel();
}
}
}

View file

@ -6,11 +6,11 @@
"client": [
"SimpleReloadableResourceManagerMixin",
"EnchantingTableBlockMixin",
"BackgroundRendererMixin",
"ClientRecipeBookMixin",
"ModelManagerMixin",
"TextureAtlasMixin",
"AnvilScreenMixin",
"FogRendererMixin",
"ModelBakeryMixin",
"WorldPresetMixin",
"MinecraftMixin",