Jump to content

[Solved] [1.16.5] Rendering translucent armor / item layers


Recommended Posts

Posted (edited)

I'm porting my mod that creates armor dynamically from blocks from 1.12 to 1.16.5 and having some difficulties with rendering translucent armor and the item layers.

So the way my item models are made is by combining quads from a base texture, a template (with the block's texture), and a partially-transparent overlay to give it some texture/lighting:

image.png

The issue I'm having is that the partially-transparent parts of the overlay are rendering invisible in the 3d model:

image.png

Does anyone know any solution to this? My code for creating the item model quads is below:

ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
int color = new Color(1f, 1f, 1f, 1f).getRGB();

//Base texture and model
builder.addAll(model.getQuads(null, null, new Random()));

//Template texture for left half
ResourceLocation templateLocation = new ResourceLocation(BlockArmor.MODID+":items/icons/block_armor_"+armorType+"1_template");
TextureAtlasSprite templateTexture = Minecraft.getInstance().getModelManager().getAtlasTexture(AtlasTexture.LOCATION_BLOCKS_TEXTURE).getSprite(templateLocation);
builder.addAll(ItemTextureQuadConverter.convertTexture(transform, templateTexture, sprite, NORTH_Z_FLUID, Direction.NORTH, color, 1));
builder.addAll(ItemTextureQuadConverter.convertTexture(transform, templateTexture, sprite, SOUTH_Z_FLUID, Direction.SOUTH, color, 1));

//Template texture for right half
templateLocation = new ResourceLocation(BlockArmor.MODID+":items/icons/block_armor_"+armorType+"2_template");
templateTexture = Minecraft.getInstance().getModelManager().getAtlasTexture(AtlasTexture.LOCATION_BLOCKS_TEXTURE).getSprite(templateLocation);
builder.addAll(ItemTextureQuadConverter.convertTexture(transform, templateTexture, sprite, NORTH_Z_FLUID, Direction.NORTH, color, 1));
builder.addAll(ItemTextureQuadConverter.convertTexture(transform, templateTexture, sprite, SOUTH_Z_FLUID, Direction.SOUTH, color, 1));

//Overlay texture
ResourceLocation coverLocation = new ResourceLocation(BlockArmor.MODID+":items/icons/block_armor_"+armorType+"_cover");
TextureAtlasSprite coverTexture = templateTexture = Minecraft.getInstance().getModelManager().getAtlasTexture(AtlasTexture.LOCATION_BLOCKS_TEXTURE).getSprite(coverLocation);
builder.add(ItemTextureQuadConverter.genQuad(transform, 0, 0, 16, 16, NORTH_Z_BASE, coverTexture, Direction.NORTH, color, 1));
builder.add(ItemTextureQuadConverter.genQuad(transform, 0, 0, 16, 16, SOUTH_Z_BASE, coverTexture, Direction.SOUTH, color, 1));

ImmutableList<BakedQuad> quads = builder.build();

 

Another issue I'm having is rendering translucent armor. This is magenta glass armor, but it is not rendering transparent at all:

image.png

Here is the rendering code for it:

matrix.push();
RenderSystem.enableBlend();
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
float alpha = 0.5f; // I've tried different alpha values with no difference
this.bipedHead.render(matrix, vertex, lightMapUV, overlayUV, red, green, blue, alpha);
this.bipedBody.render(matrix, vertex, lightMapUV, overlayUV, red, green, blue, alpha);
this.bipedRightArm.render(matrix, vertex, lightMapUV, overlayUV, red, green, blue, alpha);
this.bipedLeftArm.render(matrix, vertex, lightMapUV, overlayUV, red, green, blue, alpha);
this.bipedWaist.render(matrix, vertex, lightMapUV, overlayUV, red, green, blue, alpha);
this.bipedRightLeg.render(matrix, vertex, lightMapUV, overlayUV, red, green, blue, alpha);
this.bipedLeftLeg.render(matrix, vertex, lightMapUV, overlayUV, red, green, blue, alpha);
this.bipedRightFoot.render(matrix, vertex, lightMapUV, overlayUV, red, green, blue, alpha);
this.bipedLeftFoot.render(matrix, vertex, lightMapUV, overlayUV, red, green, blue, alpha);
RenderSystem.disableBlend();
matrix.pop();

In 1.12, I used to have this code and it would render transparent properly:

GlStateManager.color(red, green, blue, alpha);
GlStateManager.pushMatrix();
GlStateManager.enableBlend(); //enables transparency
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
this.bipedHead.render(scale);
this.bipedBody.render(scale);
this.bipedRightArm.render(scale);
this.bipedLeftArm.render(scale);
this.bipedWaist.render(scale);
this.bipedRightLeg.render(scale);
this.bipedLeftLeg.render(scale);
this.bipedRightFoot.render(scale);
this.bipedLeftFoot.render(scale);
GlStateManager.disableBlend(); //disables transparency
GlStateManager.popMatrix();

I'm not very familiar with OpenGL/rendering, so any help here would be appreciated!

Edited by Furgl
  • Furgl changed the title to [Solved] [1.16.5] Rendering translucent armor / item layers
  • 2 months later...
Posted
On 4/6/2021 at 12:05 AM, Furgl said:

I fixed the item rendering issue by overriding my IBakedModel#getLayerModels to use RenderType.getTranslucent() when rendering the Overlay layer, so that it is not culled.

And similarly I fixed the armor rendering issue by using RenderType.getEntityTranslucent(loc).

 

Hey i have the same problem,and i have hear you have fixed this already can you maybe show me the code of it?

Posted
On 4/6/2021 at 12:05 AM, Furgl said:

I fixed the item rendering issue by overriding my IBakedModel#getLayerModels to use RenderType.getTranslucent() when rendering the Overlay layer, so that it is not culled.

And similarly I fixed the armor rendering issue by using RenderType.getEntityTranslucent(loc).

 

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.