Skip to content

Commit

Permalink
Fix rendering of non-translucent particles behind translucent geometry (
Browse files Browse the repository at this point in the history
  • Loading branch information
embeddedt authored May 22, 2024
1 parent d36fa2d commit 7c6475b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@
}
}

+ /** @deprecated Neo: use {@link #render(LightTexture, Camera, float, net.minecraft.client.renderer.culling.Frustum)} with Frustum as additional parameter */
+ /** @deprecated Neo: use {@link #render(LightTexture, Camera, float, net.minecraft.client.renderer.culling.Frustum, java.util.function.Predicate)} with additional parameters */
+ @Deprecated
public void render(LightTexture p_107339_, Camera p_107340_, float p_107341_) {
+ render(p_107339_, p_107340_, p_107341_, null);
+ render(p_107339_, p_107340_, p_107341_, null, type -> true);
+ }
+
+ public void render(LightTexture p_107339_, Camera p_107340_, float p_107341_, @Nullable net.minecraft.client.renderer.culling.Frustum frustum) {
+ public void render(LightTexture p_107339_, Camera p_107340_, float p_107341_, @Nullable net.minecraft.client.renderer.culling.Frustum frustum, java.util.function.Predicate<ParticleRenderType> renderTypePredicate) {
p_107339_.turnOnLightLayer();
RenderSystem.enableDepthTest();
+ //TODO porting: is this even needed with the particle render order fix???
Expand All @@ -72,7 +72,7 @@

- for (ParticleRenderType particlerendertype : RENDER_ORDER) {
+ for(ParticleRenderType particlerendertype : this.particles.keySet()) { // Forge: allow custom IParticleRenderType's
+ if (particlerendertype == ParticleRenderType.NO_RENDER) continue;
+ if (particlerendertype == ParticleRenderType.NO_RENDER || !renderTypePredicate.test(particlerendertype)) continue;
Iterable<Particle> iterable = this.particles.get(particlerendertype);
if (iterable != null) {
RenderSystem.setShader(GameRenderer::getParticleShader);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
--- a/net/minecraft/client/particle/ParticleRenderType.java
+++ b/net/minecraft/client/particle/ParticleRenderType.java
@@ -52,6 +_,11 @@
public String toString() {
return "PARTICLE_SHEET_OPAQUE";
}
+
+ @Override
+ public boolean isTranslucent() {
+ return false;
+ }
};
ParticleRenderType PARTICLE_SHEET_TRANSLUCENT = new ParticleRenderType() {
@Override
@@ -91,6 +_,11 @@
public String toString() {
return "PARTICLE_SHEET_LIT";
}
+
+ @Override
+ public boolean isTranslucent() {
+ return false;
+ }
};
ParticleRenderType CUSTOM = new ParticleRenderType() {
@Override
@@ -126,4 +_,9 @@
void begin(BufferBuilder p_107436_, TextureManager p_107437_);

void end(Tesselator p_107438_);
+
+ /** {@return whether this type renders before or after the translucent chunk layer} */
+ default boolean isTranslucent() {
+ return true;
+ }
}
11 changes: 8 additions & 3 deletions patches/net/minecraft/client/renderer/LevelRenderer.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,27 @@
}

this.minecraft.debugRenderer.render(posestack, multibuffersource$buffersource, d0, d1, d2);
@@ -1173,7 +_,8 @@
@@ -1173,9 +_,13 @@
this.particlesTarget.copyDepthFrom(this.minecraft.getMainRenderTarget());
RenderStateShard.PARTICLES_TARGET.setupRenderState();
profilerfiller.popPush("particles");
- this.minecraft.particleEngine.render(p_109606_, p_109604_, f);
+ this.minecraft.particleEngine.render(p_109606_, p_109604_, f, frustum);
+ this.minecraft.particleEngine.render(p_109606_, p_109604_, f, frustum, type -> true);
+ net.neoforged.neoforge.client.ClientHooks.dispatchRenderStage(net.neoforged.neoforge.client.event.RenderLevelStageEvent.Stage.AFTER_PARTICLES, this, posestack, p_254120_, p_323920_, this.ticks, p_109604_, frustum);
RenderStateShard.PARTICLES_TARGET.clearRenderState();
} else {
+ // Neo: render solid particles before translucent geometry to match order of chunk render types, fixes solid particles disappearing underwater in Fast/Fancy (MC-161917)
+ profilerfiller.popPush("solid_particles");
+ this.minecraft.particleEngine.render(p_109606_, p_109604_, f, frustum, type -> !type.isTranslucent());
profilerfiller.popPush("translucent");
if (this.translucentTarget != null) {
this.translucentTarget.clear(Minecraft.ON_OSX);
@@ -1187,7 +_,8 @@
profilerfiller.popPush("string");
this.renderSectionLayer(RenderType.tripwire(), d0, d1, d2, p_254120_, p_323920_);
profilerfiller.popPush("particles");
- this.minecraft.particleEngine.render(p_109606_, p_109604_, f);
+ this.minecraft.particleEngine.render(p_109606_, p_109604_, f, frustum);
+ this.minecraft.particleEngine.render(p_109606_, p_109604_, f, frustum, type -> type.isTranslucent()); // Neo: only render translucent particles at this stage
+ net.neoforged.neoforge.client.ClientHooks.dispatchRenderStage(net.neoforged.neoforge.client.event.RenderLevelStageEvent.Stage.AFTER_PARTICLES, this, posestack, p_254120_, p_323920_, this.ticks, p_109604_, frustum);
}

Expand Down

0 comments on commit 7c6475b

Please sign in to comment.