Jump to content

[1.14.4] FastTESR - Only render quads facing player


TehStoneMan

Recommended Posts

I am trying to create a tank to contain fluids. Everything seems to be working, except when it contains a transparent fluid (water), I can see the opposite sides of the fluid. How can I only render the faces that the player can see?

 

public class TileEntityTankRenderer extends TileEntityRenderer< TileEntityTank >
{
	private static AtlasTexture textureAtlas;

	@Override
	public void renderTileEntityFast( TileEntityTank tileEntity, double x, double y, double z, float partialTicks, int destroyStage,
			BufferBuilder buffer )
	{
		final int capacity = tileEntity.getCapacity();
		final FluidStack fluidStack = tileEntity.getFluid();
		final Fluid fluid = fluidStack.getFluid();

		if( !fluidStack.isEmpty() )
		{
			if( textureAtlas == null )
				textureAtlas = Minecraft.getInstance().getTextureMap();

			final ResourceLocation fuildStillTexture = fluid.getAttributes().getStillTexture();
			final TextureAtlasSprite fluidStillSprite = textureAtlas.getAtlasSprite( fuildStillTexture.toString() );

			final double posY = 0.0625 + 0.875 * ( (float)fluidStack.getAmount() / (float)capacity );
			final int color = fluid.getAttributes().getColor();
			final float alpha = ( color >> 24 & 255 ) / 255.0F;
			final float red = ( color >> 16 & 255 ) / 255.0F;
			final float green = ( color >> 8 & 255 ) / 255.0F;
			final float blue = ( color & 255 ) / 255.0F;

			final BlockPos pos = tileEntity.getPos();
			final BlockState blockState = tileEntity.getBlockState();

			final int packedLightMap = blockState.getPackedLightmapCoords( getWorld(), pos );
			final int skyLight = packedLightMap >> 16 & 0xFFFF;
			final int blockLight = packedLightMap & 0xFFFF;

			final double height = 0.875 + ( blockState.get( BlockTank.UP ) ? 0.0625 : 0.0 ) + ( blockState.get( BlockTank.DOWN ) ? 0.0625 : 0.0 );

			final double x1 = 0.125;
			final double y1 = blockState.get( BlockTank.DOWN ) ? 0.0 : 0.0625;
			final double z1 = 0.125;
			final double x2 = 0.875;
			final double y2 = y1 + height * ( (float)fluidStack.getAmount() / (float)capacity );
			final double z2 = 0.875;

			final double u1 = fluidStillSprite.getInterpolatedU( x1 * 16 );
			final double v1 = fluidStillSprite.getInterpolatedV( z1 * 16 );
			final double u2 = fluidStillSprite.getInterpolatedU( x2 * 16 );
			final double v2 = fluidStillSprite.getInterpolatedV( z2 * 16 );
			final double u3 = fluidStillSprite.getInterpolatedU( z1 * 16 );
			final double v3 = fluidStillSprite.getInterpolatedV( y1 * 16 );
			final double u4 = fluidStillSprite.getInterpolatedU( z2 * 16 );
			final double v4 = fluidStillSprite.getInterpolatedV( y2 * 16 );

			buffer.setTranslation( x, y, z );

			// Top
			if( y2 < 1.0 || tileEntity.getFluidAmountAbove() == 0 )
			{
				buffer.pos( x1, y2, z1 ).color( red, green, blue, alpha ).tex( u1, v1 ).lightmap( skyLight, blockLight ).endVertex();
				buffer.pos( x1, y2, z2 ).color( red, green, blue, alpha ).tex( u1, v2 ).lightmap( skyLight, blockLight ).endVertex();
				buffer.pos( x2, y2, z2 ).color( red, green, blue, alpha ).tex( u2, v2 ).lightmap( skyLight, blockLight ).endVertex();
				buffer.pos( x2, y2, z1 ).color( red, green, blue, alpha ).tex( u2, v1 ).lightmap( skyLight, blockLight ).endVertex();
			}

			// Bottom
			if( y1 > 0.0 || tileEntity.getFluidAmountBelow() == 0 )
			{
				buffer.pos( x1, y1, z1 ).color( red, green, blue, alpha ).tex( u1, v1 ).lightmap( skyLight, blockLight ).endVertex();
				buffer.pos( x2, y1, z1 ).color( red, green, blue, alpha ).tex( u2, v1 ).lightmap( skyLight, blockLight ).endVertex();
				buffer.pos( x2, y1, z2 ).color( red, green, blue, alpha ).tex( u2, v2 ).lightmap( skyLight, blockLight ).endVertex();
				buffer.pos( x1, y1, z2 ).color( red, green, blue, alpha ).tex( u1, v2 ).lightmap( skyLight, blockLight ).endVertex();
			}

			// North
			buffer.pos( x2, y2, z1 ).color( red, green, blue, alpha ).tex( u2, v4 ).lightmap( skyLight, blockLight ).endVertex();
			buffer.pos( x2, y1, z1 ).color( red, green, blue, alpha ).tex( u2, v3 ).lightmap( skyLight, blockLight ).endVertex();
			buffer.pos( x1, y1, z1 ).color( red, green, blue, alpha ).tex( u1, v3 ).lightmap( skyLight, blockLight ).endVertex();
			buffer.pos( x1, y2, z1 ).color( red, green, blue, alpha ).tex( u1, v4 ).lightmap( skyLight, blockLight ).endVertex();

			// East
			buffer.pos( x2, y2, z2 ).color( red, green, blue, alpha ).tex( u4, v4 ).lightmap( skyLight, blockLight ).endVertex();
			buffer.pos( x2, y1, z2 ).color( red, green, blue, alpha ).tex( u4, v3 ).lightmap( skyLight, blockLight ).endVertex();
			buffer.pos( x2, y1, z1 ).color( red, green, blue, alpha ).tex( u3, v3 ).lightmap( skyLight, blockLight ).endVertex();
			buffer.pos( x2, y2, z1 ).color( red, green, blue, alpha ).tex( u3, v4 ).lightmap( skyLight, blockLight ).endVertex();

			// South
			buffer.pos( x1, y2, z2 ).color( red, green, blue, alpha ).tex( u1, v4 ).lightmap( skyLight, blockLight ).endVertex();
			buffer.pos( x1, y1, z2 ).color( red, green, blue, alpha ).tex( u1, v3 ).lightmap( skyLight, blockLight ).endVertex();
			buffer.pos( x2, y1, z2 ).color( red, green, blue, alpha ).tex( u2, v3 ).lightmap( skyLight, blockLight ).endVertex();
			buffer.pos( x2, y2, z2 ).color( red, green, blue, alpha ).tex( u2, v4 ).lightmap( skyLight, blockLight ).endVertex();

			// West
			buffer.pos( x1, y2, z1 ).color( red, green, blue, alpha ).tex( u3, v4 ).lightmap( skyLight, blockLight ).endVertex();
			buffer.pos( x1, y1, z1 ).color( red, green, blue, alpha ).tex( u3, v3 ).lightmap( skyLight, blockLight ).endVertex();
			buffer.pos( x1, y1, z2 ).color( red, green, blue, alpha ).tex( u4, v3 ).lightmap( skyLight, blockLight ).endVertex();
			buffer.pos( x1, y2, z2 ).color( red, green, blue, alpha ).tex( u4, v4 ).lightmap( skyLight, blockLight ).endVertex();
		}
	}
}

 

Link to comment
Share on other sites

AFAIK only faces facing towards the player will be rendered anyway. Can you please provide a screenshot example of this?

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

1138486840_RenderExample.thumb.png.0a011485bb8d65a50dfefcbff4492074.png

You can see here where the back of the faces are being rendered behind the front faces. This can be particularly seen with the lava below the water. (Stacked tanks shouldn't really have different flids in them, but that check has not been implemented yet)

Link to comment
Share on other sites

That is interesting. I'm not sure what would be causing this because I played around with block rendering, TESRs and the fluid renderer a lot in 1.12.2 & 1.14.4 and you needed to explicitly draw the backing quad for both sides to be drawn. An example of this is how you can see through the world in spectator mode and do not see the insides of walls. Can you try simplifying your code to just draw a single quad and see if this still occurs?

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

When I was using a regular TESR, the backface wasn't being drawn, but this is a FastTESR (renderTileEntityFast). In looking at how they are rendered, it appears that Forge turns off backface culling before drawing the buffer. As OpenGL calls can't be used in a FastTESR, would I have to go back to using a regular TESR?

Link to comment
Share on other sites

Yeah and FastTESR is gone in 1.15.1 anyway - everything changed and is more like a FastTESR with the new render system.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Slot deposit 3000 adalah situs slot deposit 3000 via dana yang super gacor dimana para pemain dijamin garansi wd hari ini juga hanya dengan modal receh berupa deposit sebesar 3000 baik via dana, ovo, gopay maupun linkaja untuk para pemain pengguna e-wallet di seluruh Indonesia.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT 3000 ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • OLXTOTO: Menikmati Sensasi Bermain Togel dan Slot dengan Aman dan Mengasyikkan Dunia perjudian daring terus berkembang dengan cepat, dan salah satu situs yang telah menonjol dalam pasar adalah OLXTOTO. Sebagai platform resmi untuk permainan togel dan slot, OLXTOTO telah memenangkan kepercayaan banyak pemain dengan menyediakan pengalaman bermain yang aman, adil, dan mengasyikkan. DAFTAR OLXTOTO DISINI <a href="https://imgbb.com/"><img src="https://i.ibb.co/GnjSVpx/daftar1-480x480.webp" alt="daftar1-480x480" border="0" /></a> Keamanan Sebagai Prioritas Utama Salah satu aspek utama yang membuat OLXTOTO begitu menonjol adalah komitmennya terhadap keamanan pemain. Dengan menggunakan teknologi enkripsi terkini, situs ini memastikan bahwa semua informasi pribadi dan keuangan para pemain tetap aman dan terlindungi dari akses yang tidak sah. Beragam Permainan yang Menarik Di OLXTOTO, pemain dapat menemukan beragam permainan yang menarik untuk dinikmati. Mulai dari permainan klasik seperti togel hingga slot modern dengan fitur-fitur inovatif, ada sesuatu untuk setiap selera dan preferensi. Grafik yang memukau dan efek suara yang mengagumkan menambah keseruan setiap putaran. Peluang Menang yang Tinggi Salah satu hal yang paling menarik bagi para pemain adalah peluang menang yang tinggi yang ditawarkan oleh OLXTOTO. Dengan pembayaran yang adil dan peluang yang setara bagi semua pemain, setiap taruhan memberikan kesempatan nyata untuk memenangkan hadiah besar. Layanan Pelanggan yang Responsif Tim layanan pelanggan OLXTOTO siap membantu para pemain dengan setiap pertanyaan atau masalah yang mereka hadapi. Dengan layanan yang ramah dan responsif, pemain dapat yakin bahwa mereka akan mendapatkan bantuan yang mereka butuhkan dengan cepat dan efisien. Kesimpulan OLXTOTO telah membuktikan dirinya sebagai salah satu situs terbaik untuk penggemar togel dan slot online. Dengan fokus pada keamanan, beragam permainan yang menarik, peluang menang yang tinggi, dan layanan pelanggan yang luar biasa, tidak mengherankan bahwa situs ini telah menjadi pilihan utama bagi banyak pemain. Jadi, jika Anda mencari pengalaman bermain yang aman, adil, dan mengasyikkan, jangan ragu untuk bergabung dengan OLXTOTO hari ini dan rasakan sensasi kemenangan!
    • Slot deposit dana adalah situs slot deposit dana yang juga menerima dari e-wallet lain seperti deposit via dana, ovo, gopay & linkaja terlengkap saat ini, sehingga para pemain yang tidak memiliki rekening bank lokal bisa tetap bermain slot dan terbantu dengan adanya fitur tersebut.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT DANA ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • Slot deposit dana adalah situs slot deposit dana minimal 5000 yang dijamin garansi super gacor dan gampang menang, dimana para pemain yang tidak memiliki rekening bank lokal tetap dalam bermain slot dengan melakukan deposit dana serta e-wallet lainnya seperti ovo, gopay maupun linkaja lengkap. Agar para pecinta slot di seluruh Indonesia tetap dapat menikmati permainan tanpa halangan apapun khususnya metode deposit, dimana ketersediaan cara deposit saat ini yang lebih beragam tentunya sangat membantu para pecinta slot.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT DANA ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • Slot deposit pulsa adalah situs slot deposit pulsa tanpa potongan apapun yang dijamin garansi terpercaya, dimana kamu bisa bermain slot dengan melakukan deposit pulsa dan tanpa dikenakan potongan apapun sehingga dana yang masuk ke dalam akun akan 100% utuh. Proses penarikan dana juga dijamin gampang dan tidak sulit sehingga kamu tidak perlu khawatir akan kemenangan yang akan kamu peroleh dengan sangat mudah jika bermain disini.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT PULSA TANPA POTONGAN ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
  • Topics

×
×
  • Create New...

Important Information

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