Jump to content

[Solved] [1.16.5] Semi-Transparent Particle Rendering


Mariobro85

Recommended Posts

Hello everyone,

I just started modding with Forge and am currently working on custom particles. The particles themselves work perfectly, however, transparent particles make other particles behind them invisible.

I know this issue is also present in Vanilla Minecraft and I was hoping that it could be eliminated with Forge since it makes particles with a lot of semi-transparent pixels  ugly (as you can see in the attachment).

 

This is the code I use for all my particles:

public void renderParticle(IVertexBuilder buffer, ActiveRenderInfo renderInfo, float partialTicks) {
    RenderSystem.disableDepthTest();
    RenderSystem.depthMask(false);
    RenderSystem.defaultAlphaFunc();
    
    Vector3d vector3d = renderInfo.getProjectedView();
    
    float f = (float)(MathHelper.lerp((double)partialTicks, this.prevPosX, this.posX) - vector3d.getX());
    float g = (float)(MathHelper.lerp((double)partialTicks, this.prevPosY, this.posY) - vector3d.getY());
    float h = (float)(MathHelper.lerp((double)partialTicks, this.prevPosZ, this.posZ) - vector3d.getZ());
    
    Quaternion quaternion;
    
    if(this.particleAngle == 0.0F){
      quaternion = renderInfo.getRotation();
    }
    else{
      quaternion = new Quaternion(renderInfo.getRotation());
      float f3 = MathHelper.lerp(partialTicks, this.prevParticleAngle, this.particleAngle);
      quaternion.multiply(Vector3f.ZP.rotation(f3));
    }
    
    Vector3f vector3f1 = new Vector3f(-1.0F, -1.0F, 0.0F);
    vector3f1.transform(quaternion);
    Vector3f[] avector3f = new Vector3f[]{new Vector3f(-1.0F, -1.0F, 0.0F), new Vector3f(-1.0F, 1.0F, 0.0F), new Vector3f(1.0F, 1.0F, 0.0F), new Vector3f(1.0F, -1.0F, 0.0F)};
    float f4 = this.getScale(partialTicks);
    
    for(int i = 0; i < 4; ++i) {
      Vector3f vector3f = avector3f[i];
      vector3f.transform(quaternion);
      vector3f.mul(f4);
      vector3f.add(f, g, h);
    }
    
    float f7 = this.getMinU();
    float f8 = this.getMaxU();
    float f5 = this.getMinV();
    float f6 = this.getMaxV();
    int j = this.getBrightnessForRender(partialTicks);
    
    buffer.pos((double)avector3f[0].getX(), (double)avector3f[0].getY(), (double)avector3f[0].getZ()).tex(f8, f6).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j).endVertex();
    buffer.pos((double)avector3f[1].getX(), (double)avector3f[1].getY(), (double)avector3f[1].getZ()).tex(f8, f5).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j).endVertex();
    buffer.pos((double)avector3f[2].getX(), (double)avector3f[2].getY(), (double)avector3f[2].getZ()).tex(f7, f5).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j).endVertex();
    buffer.pos((double)avector3f[3].getX(), (double)avector3f[3].getY(), (double)avector3f[3].getZ()).tex(f7, f6).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j).endVertex();
    
    RenderSystem.enableDepthTest();
    RenderSystem.depthMask(true);
  }

 

I tried the disableDepthTest() and depthMask(false) methods because they appearantly worked for an older version of Minecraft, but they have no effect in 1.16.5. The defaultAlphaFunc() method makes the texture look a bit smoother, but that's about it.

I also played around with other methods of RenderSystem, but I just kept making it worse that it already is.

 

Does anyone have a solution for this?

Thanks in advance!

2021-03-19 23_46_47-Minecraft_ 1.16.5 - Singleplayer.png

Edited by Mariobro85
Link to comment
Share on other sites

9 minutes ago, ChampionAsh5357 said:

You would need to set the IParticleRenderType to PARTICLE_SHEET_TRANSLUCENT via Particle#getRenderType iirc. Don't manipulate the render system in any way.

@Override
public IParticleRenderType getRenderType() {
  return IParticleRenderType.PARTICLE_SHEET_TRANSLUCENT;
}

 

It already is.

Link to comment
Share on other sites

  • Mariobro85 changed the title to [Solved] [1.16.5] Semi-Transparent Particle Rendering

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.