-
Notifications
You must be signed in to change notification settings - Fork 811
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
occlusion check based off `RenderSectionManager.getEffectiveRenderDistance`
- Loading branch information
1 parent
888d922
commit efdc207
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
...n/java/net/caffeinemc/mods/sodium/mixin/features/render/particle/ParticleEngineMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package net.caffeinemc.mods.sodium.mixin.features.render.particle; | ||
|
||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import com.mojang.blaze3d.vertex.VertexConsumer; | ||
import net.caffeinemc.mods.sodium.client.SodiumClientMod; | ||
import net.minecraft.client.Camera; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.particle.Particle; | ||
import net.minecraft.client.particle.ParticleEngine; | ||
import net.minecraft.util.Mth; | ||
import net.minecraft.world.phys.Vec3; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
@Mixin(ParticleEngine.class) | ||
public class ParticleEngineMixin { | ||
|
||
/** | ||
* @author AnOpenSauceDev | ||
* @reason Prevent Minecraft from rendering particles that are fog occluded. | ||
*/ | ||
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/Particle;render(Lcom/mojang/blaze3d/vertex/VertexConsumer;Lnet/minecraft/client/Camera;F)V")) | ||
public void particleFogOcclusion(Particle instance, VertexConsumer vertexConsumer, Camera camera, float v){ | ||
if(!SodiumClientMod.options().performance.useFogOcclusion){ | ||
instance.render(vertexConsumer,camera,v); | ||
return; | ||
} | ||
|
||
if(sodium$isParticleFogOccluded(camera.getPosition(),instance.getBoundingBox().getCenter())){ | ||
instance.render(vertexConsumer,camera,v); | ||
} | ||
} | ||
|
||
@Unique | ||
public boolean sodium$isParticleFogOccluded(Vec3 pointA, Vec3 pointB){ | ||
double dx = pointA.x - pointB.x; | ||
double dz = pointA.z - pointB.z; | ||
double distance = (dx * dx + dz * dz); | ||
|
||
var renderDistance = Minecraft.getInstance().gameRenderer.getRenderDistance(); | ||
var color = RenderSystem.getShaderFogColor(); | ||
|
||
if(!Mth.equal(color[3],1.0f)){ | ||
return false; | ||
} | ||
|
||
var fogDist = Math.min(renderDistance,distance); | ||
|
||
return distance < fogDist * fogDist; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters