Jump to content

[1.7.10][Glitch] Custom particle rendering before some transparent blocks


imadnsn

Recommended Posts

I made a particle effect that is in the shape of a block (renders 6 sides), it is rendering all well except when you try to see it with a portal, water or any other semi-transparent block (such as stained glass or ice) behind.

What happens is that the particle renders before the block does, which makes the block renders as if the particle is behind it although it is not. The way I made the particle is like vanilla ones, except it is static (i.e. doesn't move) and with renderParticle overridden (the super is not called in it).

I also made a utility class that spawns the particle just like how RenderGlobal does (the same mechanics).

 

Should I disable some OpenGL options before drawing or do something like that? I should note that I don't use "startDrawingQuads" or anything like that in the tesselatior because I think it is already preconfigured looking at vanilla code.

 

This is the render method:

        @Override
@SideOnly(Side.CLIENT)
        // the partial tick and all rotations aren't used in the rendering because the particle is not facing the player
public void renderParticle(Tessellator t, float partialTick, float rotationX, float rotationXZ, float rotationZ, float rotationYZ, float rotationXY) {
	double minu = 0;
	double maxu = 0.25;
	double minv = 0;
	double maxv = 1;

	// interpPos is related to the player's position, it renders the particle relatively to the player.
	double x = this.posX - interpPosX;
	double y = this.posY - interpPosY;
	double z = this.posZ - interpPosZ;

        // ... some logic that choose minu and maxu ...

	Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation(Magematica.MODID, "textures/particles/block_fade.png"));
                t.setColorRGBA_F(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha);
        
                // ... a lot of addVertexWithUVs that work fine ...

}

 

This is the spawning in the utility client-only class ParticleSpawner:

        public static void spawnParticle(String particleType, double x, double y, double z, double velX, double velY, double velZ) {
	EntityFX particle = getEntityFXToSpawn(particleType, x, y, z, velX, velY, velZ);
	if (particle != null) {
		mc.effectRenderer.addEffect(particle);
	}
}

private static EntityFX getEntityFXToSpawn(String particleType, double x, double y, double z, double velX, double velY, double velZ) {
	EntityFX ret = null;
        if (mc != null && mc.renderViewEntity != null && mc.effectRenderer != null) {
        	int particleSetting = mc.gameSettings.particleSetting;
        	
        	boolean spawn = particleSetting != 2; // Don't spawn on Minimal particle setting
        	
        	// 1/4 chance of not spawning when particle setting is Decreased
        	if (particleSetting == 1 && world.rand.nextInt(3) == 0) {
        		spawn = false;
        	}
        	
        	double xDist = mc.thePlayer.posX - x;
        	double yDist = mc.thePlayer.posY - y;
        	double zDist = mc.thePlayer.posZ - z;
        	// only spawn when player is within 16 blocks of range (squared to not account for signs).
        	spawn &= xDist * xDist + yDist * yDist + zDist * zDist <= 16 * 16;

                if (spawn) {
		switch (particleType) {
			case block_fade:
				ret = new EntityBlockFadeFX(world, x, y, z);
				PlayerMageProperties props = PlayerMageProperties.getFromPlayer(mc.thePlayer);
				// ... some logic to choose particle color (I assure it is not the problem) ...
				break;
		}
	}
        }
        
return ret;
}

Link to comment
Share on other sites

If you want to make sure your particles render last (after the blocks) then that is a good way to do it.  It's pretty straightforward.

 

It's funny though because I could have sworn that particles render last after blocks, (in EntityRenderer.renderWorld), and here's a comment taken straight from Forge MC 1.6.4

 

            //Forge: Moved section from above, now particles are the last thing to render.

 

Ah - when I look in 1.7.2 the particles are now back in the middle and I find this comment

 

                // ToDo: Try and figure out how to make particles render sorted correctly.. {They render behind water}

 

So I guess they broke something moving the particle render :)

 

Anyhow your queued render should work I reckon.

 

-TGG

 

 

Link to comment
Share on other sites

It did work but it made the problem opposite, which I can deal with.

The reason why it is hard to implement is because there is some logic behind it. A particle should render before transparent block if it is behind or inside the block, but it should render after the block if it is in front of it.

This is pretty much a basic graphical problem when it comes to rendering a scene.

And to make it worse, particles aren't blocks so the only way to solve this is by raytracing.

Link to comment
Share on other sites

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.