Rework fog
This commit is contained in:
@@ -1,7 +1,15 @@
|
||||
package me.cortex.voxy.client.core;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
public interface IGetVoxyRenderSystem {
|
||||
VoxyRenderSystem getVoxyRenderSystem();
|
||||
void shutdownRenderer();
|
||||
void createRenderer();
|
||||
|
||||
static VoxyRenderSystem getNullable() {
|
||||
var lr = (IGetVoxyRenderSystem)Minecraft.getInstance().levelRenderer;
|
||||
if (lr == null) return null;
|
||||
return lr.getVoxyRenderSystem();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,10 +108,15 @@ public class NormalRenderPipeline extends AbstractRenderPipeline {
|
||||
if (this.useEnvFog) {
|
||||
float start = viewport.fogParameters.environmentalStart();
|
||||
float end = viewport.fogParameters.environmentalEnd();
|
||||
float invEndFogDelta = 1f/(end-start);
|
||||
float endDistance = Minecraft.getInstance().gameRenderer.getRenderDistance()*1.5f;
|
||||
glUniform3f(4, endDistance, invEndFogDelta, Math.abs(start)*invEndFogDelta);
|
||||
glUniform3f(5, viewport.fogParameters.red(), viewport.fogParameters.green(), viewport.fogParameters.blue());
|
||||
if (Math.abs(end-start)>1) {
|
||||
float invEndFogDelta = 1f / (end - start);
|
||||
float endDistance = Minecraft.getInstance().gameRenderer.getRenderDistance() * 1.5f;
|
||||
glUniform4f(4, endDistance, invEndFogDelta, Math.abs(start) * invEndFogDelta, 0);
|
||||
glUniform4f(5, viewport.fogParameters.red(), viewport.fogParameters.green(), viewport.fogParameters.blue(), viewport.fogParameters.alpha());
|
||||
} else {
|
||||
glUniform4f(4, 0, 0, 0, 0);
|
||||
glUniform4f(5, 0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
glBindTextureUnit(3, this.colourSSAOTex.id);
|
||||
|
||||
@@ -1,30 +1,37 @@
|
||||
package me.cortex.voxy.client.mixin.minecraft;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import me.cortex.voxy.client.config.VoxyConfig;
|
||||
import me.cortex.voxy.client.core.IGetVoxyRenderSystem;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.DeltaTracker;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.renderer.fog.FogData;
|
||||
import net.minecraft.client.renderer.fog.FogRenderer;
|
||||
import org.joml.Vector4f;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(FogRenderer.class)
|
||||
public class MixinFogRenderer {
|
||||
@Redirect(method = "setupFog", at = @At(value = "FIELD", target ="Lnet/minecraft/client/renderer/fog/FogData;renderDistanceEnd:F", opcode = Opcodes.PUTFIELD), require = 0)
|
||||
private void voxy$modifyFog(FogData instance, float distance) {
|
||||
var vrs = (IGetVoxyRenderSystem) Minecraft.getInstance().levelRenderer;
|
||||
|
||||
if (VoxyConfig.CONFIG.renderVanillaFog || vrs == null || vrs.getVoxyRenderSystem() == null) {
|
||||
instance.renderDistanceEnd = distance;
|
||||
} else {
|
||||
instance.renderDistanceStart = 999999999;
|
||||
instance.renderDistanceEnd = 999999999;
|
||||
if (!VoxyConfig.CONFIG.useEnvironmentalFog) {
|
||||
instance.environmentalStart = 99999999;
|
||||
instance.environmentalEnd = 99999999;
|
||||
}
|
||||
@Inject(method = "setupFog", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;getDevice()Lcom/mojang/blaze3d/systems/GpuDevice;"))
|
||||
private void voxy$modifyFog(Camera camera, int rdInt, boolean fogStuff, DeltaTracker tracker, float pTick, ClientLevel lvl, CallbackInfoReturnable<Vector4f> cir, @Local(type=FogData.class) FogData data) {
|
||||
if (VoxyConfig.CONFIG.renderVanillaFog) {
|
||||
return;
|
||||
}
|
||||
var vrs = IGetVoxyRenderSystem.getNullable();
|
||||
if (vrs == null) return;
|
||||
data.renderDistanceStart = 999999999;
|
||||
data.renderDistanceEnd = 999999999;
|
||||
if (!VoxyConfig.CONFIG.useEnvironmentalFog) {
|
||||
data.environmentalStart = 99999999;
|
||||
data.environmentalEnd = 99999999;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ layout(location = 2) uniform mat4 projMat;
|
||||
#ifdef EMIT_COLOUR
|
||||
layout(binding = 3) uniform sampler2D colourTex;
|
||||
#ifdef USE_ENV_FOG
|
||||
layout(location = 4) uniform vec3 endParams;
|
||||
layout(location = 5) uniform vec3 fogColour;
|
||||
layout(location = 4) uniform vec4 endParams;
|
||||
layout(location = 5) uniform vec4 fogColour;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -43,9 +43,9 @@ void main() {
|
||||
discard;
|
||||
}
|
||||
#ifdef USE_ENV_FOG
|
||||
{
|
||||
if (fogColour.a>0.0){
|
||||
float fogLerp = clamp(fma(min(length(point.xyz), endParams.x),endParams.y,endParams.z),0,1);//512 is 32*16 which is the render distance in blocks
|
||||
colour.rgb = mix(colour.rgb, fogColour, fogLerp);
|
||||
colour.rgb = mix(colour.rgb, fogColour.rgb, fogLerp*fogColour.a);
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user