Jump to content

[SOLVED (kinda)][1.10.2] Rendering Translucent Armor Texture


Furgl

Recommended Posts

I'm trying to render armor with a translucent texture, but I haven't been able to get it to render perfectly. Currently, I am using code like this to render it:

GlStateManager.pushMatrix();
GlStateManager.enableBlend();
//render armor
GlStateManager.disableBlend();
GlStateManager.popMatrix();

Which works perfectly except for two situations:

 

 

1. When the armor is in front of water, it doesn't render the water behind it:

30f6fe85ef61c0aa9d2f96d3c4c86755.png

 

2. When the armor is on front of another entity at a certain angle and distance, it doesn't render the entity (in this case the armor stand with diamond armor on) behind it:

b9240acf2eee2ec75ef3d2d6f15fa9f9.png

 

Here's what the armor looks like without GlStateManager.enableBlend() for reference:

6e47fae35184e584eea47524bf0e088c.png

 

 

I'm not an expert at OpenGL, so could anyone help me with rendering translucent textures correctly?

 

Thanks in advance!

Link to comment
Share on other sites

I think that that is unfortunately due to Minecraft's approach to transparent rendering passes.  Ice and water do that all the time.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Another problem I'm having with translucent armor is that, when rendering the enchanted glint over top, every armor piece except for the first rendered piece (in the order of chestplate, leggings, boots, and helmet as rendered in LayerArmorBase#doRenderLayer) appears much brighter (enchanted set on left, unenchanted on right):

 

 

Rendering armor with GlStateManager.enableBlend() before and GlStateManager.disableBlend() after:

586dd06cbd8d31df981aa9d12987e801.png

Rendering armor without enabling or disabling blend:

04b594de40ccc4d6e697efba6cbb2583.png

Rendering armor with GlStateManager.enableBlend() before and GlStateManager.disableBlend() after but not doing any rendering when render is called from LayerArmorBase#renderEnchantedGlint (I have a variable to detect this):

950ab780e6b79b58018c997a847a26ab.png

 

 

I am rendering this armor model using a custom model that's called in my ItemArmor's getArmorModel method, as opposed to rendering it as a custom layer. Since the armor pieces only appear very bright when I use blending, I would assume it has something to do with that. I'm sure I could fix this by doing all my rendering using a custom layer instead, but since the first rendered armor piece (the chestplate in the pictures) is rendered correctly, I would assume that it is possible to fix this. Any ideas how I can fix it?

Link to comment
Share on other sites

After digging around through rendering code, specifically rendering for clouds, I found this magical line that fixes the enchanted glint problem: GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);

GlStateManager.pushMatrix();
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
//render armor
GlStateManager.disableBlend();
GlStateManager.popMatrix();

Link to comment
Share on other sites

Ideally the renderer would separate all opaque and transparent faces into separate lists, sort the opaque front to back, transparent back to front, turn glDepthMask on, render the opaque list, turn glDepthMask off, then render the transparent...but I have no idea what the vanilla renderer is doing.  I don't have the patience to try to go through it and figure out what's going on with it...and it might end up being easier to rewrite the whole thing than fixing what's there.

 

 

OpenGL 3.1+ would make it so much easier and more efficient...just sayin. ¯\_(ツ)_/¯

Link to comment
Share on other sites

Yes, that's what it should do.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.