|
22 | 22 |
|
23 | 23 | package com.ventooth.beddium.mixin.mixins.client.TerrainRendering; |
24 | 24 |
|
| 25 | +import com.falsepattern.lib.util.MathUtil; |
25 | 26 | import com.llamalad7.mixinextras.injector.wrapoperation.Operation; |
26 | 27 | import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; |
27 | 28 | import com.ventooth.beddium.config.TerrainRenderingConfig; |
28 | 29 | import com.ventooth.beddium.modules.TerrainRendering.fog.FogStateTracker; |
| 30 | +import lombok.val; |
| 31 | +import org.lwjgl.opengl.GL11; |
29 | 32 | import org.spongepowered.asm.mixin.Mixin; |
| 33 | +import org.spongepowered.asm.mixin.Shadow; |
30 | 34 | import org.spongepowered.asm.mixin.injection.At; |
| 35 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 36 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
31 | 37 |
|
32 | 38 | import net.minecraft.client.renderer.EntityRenderer; |
33 | 39 |
|
34 | 40 | import java.nio.FloatBuffer; |
35 | 41 |
|
36 | 42 | @Mixin(EntityRenderer.class) |
37 | 43 | public abstract class EntityRendererMixin { |
| 44 | + @Shadow |
| 45 | + private float farPlaneDistance; |
| 46 | + |
| 47 | + @Inject(method = "setupFog", |
| 48 | + at = @At(value = "RETURN")) |
| 49 | + private void applyFogBias(CallbackInfo ci) { |
| 50 | + val fogBias = (float) TerrainRenderingConfig.FastChunkDrawModeFogBias; |
| 51 | + if (TerrainRenderingConfig.ChunkDrawMode != TerrainRenderingConfig.DrawModeEnum.Fast || MathUtil.epsilonEquals(fogBias, 0F)) { |
| 52 | + return; |
| 53 | + } |
| 54 | + |
| 55 | + float fogEnd; |
| 56 | + float fogStart; |
| 57 | + if (TerrainRenderingConfig.FastFog) { |
| 58 | + fogEnd = FogStateTracker.end; |
| 59 | + fogStart = FogStateTracker.start; |
| 60 | + } else { |
| 61 | + fogEnd = GL11.glGetInteger(GL11.GL_FOG_END); |
| 62 | + fogStart = GL11.glGetInteger(GL11.GL_FOG_START); |
| 63 | + } |
| 64 | + val maxFogEnd = this.farPlaneDistance + fogBias; |
| 65 | + |
| 66 | + if (maxFogEnd >= fogEnd || fogStart > fogEnd) { |
| 67 | + return; |
| 68 | + } |
| 69 | + |
| 70 | + val biasRatio = maxFogEnd / fogEnd; |
| 71 | + fogEnd = maxFogEnd; |
| 72 | + fogStart *= biasRatio; |
| 73 | + |
| 74 | + GL11.glFogf(GL11.GL_FOG_END, fogEnd); |
| 75 | + GL11.glFogf(GL11.GL_FOG_START, fogStart); |
| 76 | + |
| 77 | + if (TerrainRenderingConfig.FastFog) { |
| 78 | + FogStateTracker.end = fogEnd; |
| 79 | + FogStateTracker.start = fogStart; |
| 80 | + } |
| 81 | + } |
| 82 | + |
38 | 83 | @WrapOperation(method = "setupFog", |
39 | 84 | at = @At(value = "INVOKE", |
40 | 85 | target = "Lorg/lwjgl/opengl/GL11;glFog(ILjava/nio/FloatBuffer;)V")) |
@@ -75,7 +120,6 @@ private void track_glEnable(int cap, Operation<Void> original) { |
75 | 120 | original.call(cap); |
76 | 121 | } |
77 | 122 |
|
78 | | - |
79 | 123 | @WrapOperation(method = "renderWorld", |
80 | 124 | at = @At(value = "INVOKE", |
81 | 125 | target = "Lorg/lwjgl/opengl/GL11;glDisable(I)V")) |
|
0 commit comments