Skip to content

Commit

Permalink
return particle cull
Browse files Browse the repository at this point in the history
  • Loading branch information
Asek3 committed Jan 12, 2024
1 parent 3dbfc36 commit 2752c29
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,14 @@ public static OptionPage advanced() {
.setBinding((opts, value) -> opts.advanced.useEntityCulling = value, opts -> opts.advanced.useEntityCulling)
.build()
)
.add(OptionImpl.createBuilder(boolean.class, sodiumOpts)
.setName(new TextComponentTranslation("sodium.options.use_particle_culling.name"))
.setTooltip(new TextComponentTranslation("sodium.options.use_particle_culling.tooltip"))
.setControl(TickBoxControl::new)
.setImpact(OptionImpact.LOW)
.setBinding((opts, value) -> opts.advanced.useParticleCulling = value, opts -> opts.advanced.useParticleCulling)
.build()
)
.add(OptionImpl.createBuilder(boolean.class, sodiumOpts)
.setName(new TextComponentTranslation("sodium.options.animate_only_visible_textures.name"))
.setTooltip(new TextComponentTranslation("sodium.options.animate_only_visible_textures.tooltip"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package me.jellysquid.mods.sodium.mixin.features.particle.cull;

import com.llamalad7.mixinextras.injector.WrapWithCondition;
import me.jellysquid.mods.sodium.client.SodiumClientMod;
import me.jellysquid.mods.sodium.client.render.SodiumWorldRenderer;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.particle.ParticleManager;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.culling.Frustum;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.AxisAlignedBB;
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.callback.CallbackInfo;

@Mixin(ParticleManager.class)
public class MixinParticleManager {

private Frustum cullingFrustum;

@Inject(method = {"renderParticles", "renderLitParticles"}, at = @At("HEAD"))
private void preRenderParticles(Entity entity, float partialTicks, CallbackInfo ci) {
Frustum frustum = SodiumWorldRenderer.getInstance().getFrustum();
boolean useCulling = SodiumClientMod.options().advanced.useParticleCulling;

// Setup the frustum state before rendering particles
if (useCulling && frustum != null) {
this.cullingFrustum = frustum;
} else {
this.cullingFrustum = null;
}
}

@WrapWithCondition(method = {"renderParticles", "renderLitParticles"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/Particle;renderParticle(Lnet/minecraft/client/renderer/BufferBuilder;Lnet/minecraft/entity/Entity;FFFFFF)V"))
private boolean filterParticleList(Particle particle, BufferBuilder f8, Entity f9, float f10, float f11, float f12, float vec3d, float v, float buffer) {
AxisAlignedBB box = particle.getBoundingBox();

// Hack: Grow the particle's bounding box in order to work around mis-behaved particles
return this.cullingFrustum.isBoxInFrustum(box.minX - 1.0D, box.minY - 1.0D, box.minZ - 1.0D, box.maxX + 1.0D, box.maxY + 1.0D, box.maxZ + 1.0D);

This comment has been minimized.

Copy link
@embeddedt

embeddedt Jan 12, 2024

Collaborator

Should probably add this.cullingFrustum != null here.

This comment has been minimized.

Copy link
@Asek3

Asek3 Jan 12, 2024

Author Owner

logical, fixed it

}

}
1 change: 1 addition & 0 deletions src/main/resources/sodium.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"features.options.MixinMinecraftClient",
"features.options.MixinOptionsScreen",
"features.options.MixinWorldRenderer",
"features.particle.cull.MixinParticleManager",
"features.render_layer.leaves.MixinLeavesBlock",
"features.sky.MixinWorldRenderer",
"features.texture_tracking.MixinDrawableHelper",
Expand Down

0 comments on commit 2752c29

Please sign in to comment.