Jump to content

[Solved][1.6.x] TESR with transparency depth issue


Recommended Posts

Posted

Hey all, I've got an issue with a custom tile entity special renderer that I searched long and hard for a solution for, but wasn't able to find.

 

The tile entity is suppose to be a completely transparent, collision-free block that renders a highly animated magic circle at its location.  The animation would have had an enormous number of frames if I had just done it as a texture with an mcmeta file, so I decided to split it into sections and have the tessellator handle the rotation animations for me.

[spoiler=textures (warning, large)]

IOShSBk.png

qIGgeVV.png

 

 

One section rotates clockwise, while the other rotates counter-clockwise.  They share a common center point, with a slight y-offset to prevent z-fighting.

 

Now... my problem is this.  When placed in an open space, the entity functions perfectly.  However, when placed near other, opaque blocks... well...

 

YAMQnbz.png

 

The textures are rendered around the middle of the block level that the tile entity is on, so I know that they're supposed to be showing over the blocks below them, and the same issue happens when I reverse the setup and stick the tile entity below a level of blocks.  For some reason, the blocks are being rendered on top of my texture, despite being below it.  Furthermore, the effect is inconsistent...  If I move within a block or so y-distance to the tile entity, the problem goes away (at least, until I move again).

 

[spoiler=Here's my render code:]

package narhiril.homblocks.client;

import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import narhiril.homblocks.common.HomBlocks;
import narhiril.homblocks.common.blocks.BlockAthiCircle;
import narhiril.homblocks.common.tileentity.TileEntityAthiCircle;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;

public class TileEntityCircleRenderer extends TileEntitySpecialRenderer{
  
    private float rotationAngle = 0.01F;
    private float holdRotationAngle = 0.01F;
    private static double minu = 0.0D;
    private static double minv = 0.0D;
    private static double maxu = 1.0D;
    private static double maxv = 1.0D;
    private static final ResourceLocation rl1 = new ResourceLocation("homblocks:textures/blocks/athiPortalCircleInner.png");
    private static final ResourceLocation rl2 = new ResourceLocation("homblocks:textures/blocks/athiPortalCircleOuter.png");
    
      
@Override
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) {

	Minecraft.getMinecraft().renderEngine.bindTexture(rl1);
        x-= 0.5D;
        z-= 0.5D;
	float size = 5.0F; // in blocks
	float height = 0.7F; // in blocks
	double cx = x;
	double cz = z;
	double tempX = 0D;
	double tempZ = 0D;	
	double rotatedX = 0D;
	double rotatedZ = 0D;
	double cornerX = x;
	double cornerZ = z;

	rotationAngle = rotationAngle + 0.01F;
	if (rotationAngle >= 360.0F)
	{
		rotationAngle = 0.0F;
	}
	holdRotationAngle = rotationAngle;

	double sinRot = Math.sin(rotationAngle);
	double cosRot = Math.cos(rotationAngle);

	Tessellator tessellator = Tessellator.instance;
        GL11.glPushMatrix();
        GL11.glTranslated(x+(size/2)-0.5, y+0.1, z+(size/2)-0.5);
        GL11.glDisable(GL11.GL_LIGHTING);
	GL11.glDisable(GL11.GL_CULL_FACE);
	GL11.glEnable(GL11.GL_BLEND);

    //first ring
    
    tessellator.startDrawingQuads();
    
    //rotation for corner 1
    cornerX = x-size;
    cornerZ = z-size;
    tempX = cornerX - cx;
    tempZ = cornerZ - cz;
    rotatedX = tempX*cosRot - tempZ*sinRot;
    rotatedZ = tempX*sinRot + tempZ*cosRot;
    cornerX = rotatedX + cx;
    cornerZ = rotatedZ + cz;
    
    tessellator.addVertexWithUV(cornerX, y+height, cornerZ, minu, minv);

    //rotation for corner 2
    cornerX = x-size;
    cornerZ = z+size;
    tempX = cornerX - cx;
    tempZ = cornerZ - cz;
    rotatedX = tempX*cosRot - tempZ*sinRot;
    rotatedZ = tempX*sinRot + tempZ*cosRot;
    cornerX = rotatedX + cx;
    cornerZ = rotatedZ + cz;
    
    tessellator.addVertexWithUV(cornerX, y+height, cornerZ, minu, maxv);
    

    //rotation for corner 3
    cornerX = x+size;
    cornerZ = z+size;
    tempX = cornerX - cx;
    tempZ = cornerZ - cz;
    rotatedX = tempX*cosRot - tempZ*sinRot;
    rotatedZ = tempX*sinRot + tempZ*cosRot;
    cornerX = rotatedX + cx;
    cornerZ = rotatedZ + cz;
    
    tessellator.addVertexWithUV(cornerX, y+height, cornerZ, maxu, maxv);

    //rotation for corner 4
    cornerX = x+size;
    cornerZ = z-size;
    tempX = cornerX - cx;
    tempZ = cornerZ - cz;
    rotatedX = tempX*cosRot - tempZ*sinRot;
    rotatedZ = tempX*sinRot + tempZ*cosRot;
    cornerX = rotatedX + cx;
    cornerZ = rotatedZ + cz;
    
    tessellator.addVertexWithUV(cornerX, y+height, cornerZ, maxu , minv);

    tessellator.draw();


    //second ring
    
    rotationAngle = 360-rotationAngle; //retrograde spin

    Minecraft.getMinecraft().renderEngine.bindTexture(rl2);
    sinRot = Math.sin(rotationAngle);
    cosRot = Math.cos(rotationAngle);
    size = 5.0F;
    height = 0.6F;

    
    
    tessellator.startDrawingQuads();
    
    //rotation for corner 1
    cornerX = x-size;
    cornerZ = z-size;
    tempX = cornerX - cx;
    tempZ = cornerZ - cz;
    rotatedX = tempX*cosRot - tempZ*sinRot;
    rotatedZ = tempX*sinRot + tempZ*cosRot;
    cornerX = rotatedX + cx;
    cornerZ = rotatedZ + cz;
    
    tessellator.addVertexWithUV(cornerX, y+height, cornerZ, minu, minv);

    //rotation for corner 2
    cornerX = x-size;
    cornerZ = z+size;
    tempX = cornerX - cx;
    tempZ = cornerZ - cz;
    rotatedX = tempX*cosRot - tempZ*sinRot;
    rotatedZ = tempX*sinRot + tempZ*cosRot;
    cornerX = rotatedX + cx;
    cornerZ = rotatedZ + cz;
    
    tessellator.addVertexWithUV(cornerX, y+height, cornerZ, minu, maxv);
    

    //rotation for corner 3
    cornerX = x+size;
    cornerZ = z+size;
    tempX = cornerX - cx;
    tempZ = cornerZ - cz;
    rotatedX = tempX*cosRot - tempZ*sinRot;
    rotatedZ = tempX*sinRot + tempZ*cosRot;
    cornerX = rotatedX + cx;
    cornerZ = rotatedZ + cz;
    
    tessellator.addVertexWithUV(cornerX, y+height, cornerZ, maxu, maxv);

    //rotation for corner 4
    cornerX = x+size;
    cornerZ = z-size;
    tempX = cornerX - cx;
    tempZ = cornerZ - cz;
    rotatedX = tempX*cosRot - tempZ*sinRot;
    rotatedZ = tempX*sinRot + tempZ*cosRot;
    cornerX = rotatedX + cx;
    cornerZ = rotatedZ + cz;
    
    tessellator.addVertexWithUV(cornerX, y+height, cornerZ, maxu , minv);
    
    tessellator.draw();
    
    rotationAngle = holdRotationAngle;

    GL11.glEnable(GL11.GL_CULL_FACE);
    GL11.glEnable(GL11.GL_LIGHTING);
    GL11.glPopMatrix();

}


}

 

 

 

I was under the impression that tile entities were rendered last, after both block render passes.  So... why is this happening, and what can I do to fix it?

 

Thanks a bunch in advance.

Posted

I think 1.6.x is too outdated..

You would not be able to get supported with the version.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

My hands are kind of tied on that one.  This is a custom job for a server that's running on 1.6.4.

 

Nevertheless, I think the code is similar enough to 1.7.x that someone might be able to help me.

Posted

Hi

 

It doesn't matter whether your section is rendered first or last, the depth culling should take care of it. It seems pretty obvious to me that the ring is rendering below the blocks, I think there must be something wrong with your y-position.

 

I think it is here

tessellator.addVertexWithUV(cornerX, y+height, cornerZ, minu, minv);

 

You have already translated by y so you shouldn't have y in there.

 

-TGG

 

Posted

First of all, let me get over being starstruck for a moment since I learned how to do my first renderer based on your tutorials, TGG.

 

I went ahead and removed that height factor and upped the translation to +0.5 (rather than +0.1.  Also tried +1.5 with no improvement).  Unfortunately, my problem still persists.

 

[spoiler=From the side, to show height (curiously, it renders properly when I'm this close to it)]

HfLx7dT.png

 

 

 

[spoiler=The same circle, from above]

R5nxsLm.png

 

 

 

I tried using a texture without an alpha channel and turning GL_BLEND off, still happens.  I even tried turning off the rotation while I try to sort this out, but still no luck.  I'm still assuming the issue is with the renderer and not something else like the block or the tile entity, but here's the code for those just in case.  I'm completely baffled.

 

[spoiler= Block]



public class BlockAthiCircle extends BlockContainer {

public static Icon blockIconCopy;
public static Icon blockIconSecondary;
    public static String secondaryTexture = "homblocks:athiPortalCircleOuter";

    public BlockAthiCircle(int par1, String unlocalizedName) {
        super(par1, Material.iron);
        this.setUnlocalizedName(unlocalizedName);
        this.setHardness(2.0F);
        this.setResistance(6.0F);
        this.setTextureName("homblocks:athiPortalCircleInner");
        this.setBlockBounds(0,0,0,1,1,1);
        
    }

    @Override
    public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
    {
        return null;
    }

    
    public boolean isOpaqueCube()
    {
        return false;
    }

    
    @Override
    public boolean shouldSideBeRendered(IBlockAccess iblockaccess, int i, int j, int k, int l)
    {
    	return false;
    }
    
    public boolean renderAsNormalBlock()
    {
        return false;
    }
    public void registerIcons(IconRegister iconRegister)
    {
    	         blockIcon = iconRegister.registerIcon("homblocks:multitexture");
    	         blockIconCopy = iconRegister.registerIcon(this.textureName);
    	         blockIconSecondary = iconRegister.registerIcon(this.secondaryTexture);
    	
    }

    @Override
    public TileEntity createNewTileEntity(World world) {
        return new TileEntityAthiCircle();
    }
}


 

 

 

[spoiler= TileEntity]


public class TileEntityAthiCircle extends TileEntity{


    @Override
    @SideOnly(Side.CLIENT)
    public double getMaxRenderDistanceSquared()
    {
        return 4096.0D;
    }
}
[/spoiler]

Posted

Aaaaand I'm an idiot.  I completely misread your suggestion as "remove the +height" rather than "remove the y entirely."

 

Thanks TGG, that fixed it.  Everything works now.  ^_^

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.

Announcements



×
×
  • Create New...

Important Information

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