Jump to content

(Solved)How to make a texture in custom SkyRenderer overlap another


Recommended Posts

Posted (edited)

I recently got a custom SkyRenderer working by copying the vanilla overworld code, and have been figuring out how it works. I created a third celestial object using the same rendering code used for the sun and moon, and for the most part, it functions perfectly:

        GlStateManager.enableTexture2D();
        GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
        GlStateManager.pushMatrix();
        float f16 = 1.0F - world.getRainStrength(partialTicks);
        GlStateManager.color(1.0F, 1.0F, 1.0F, f16);
        GlStateManager.rotate(-90.0F, 0.0F, 1.0F, 0.0F);
        
        GlStateManager.rotate(world.getCelestialAngle(partialTicks) * 360.0F, 1.0F, 0.0F, 0.0F);
        
        float f17 = 30.0F; //size of the sun? default is 30.0F
        this.renderEngine.bindTexture(SUN_TEXTURES);
        bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
        bufferbuilder.pos((double)(-f17), 100.0D, (double)(-f17)).tex(0.0D, 0.0D).endVertex();
        bufferbuilder.pos((double)f17, 100.0D, (double)(-f17)).tex(1.0D, 0.0D).endVertex();
        bufferbuilder.pos((double)f17, 100.0D, (double)f17).tex(1.0D, 1.0D).endVertex();
        bufferbuilder.pos((double)(-f17), 100.0D, (double)f17).tex(0.0D, 1.0D).endVertex();
        tessellator.draw();
        
        f17 = 20.0F;
        this.renderEngine.bindTexture(MOON_PHASES_TEXTURES);
        int k1 = world.getMoonPhase();
        int i2 = k1 % 4;
        int k2 = k1 / 4 % 2;
        float f22 = (float)(i2 + 0) / 4.0F;
        float f23 = (float)(k2 + 0) / 2.0F;
        float f24 = (float)(i2 + 1) / 4.0F;
        float f14 = (float)(k2 + 1) / 2.0F;
        bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
        bufferbuilder.pos((double)(-f17), -100.0D, (double)f17).tex((double)f24, (double)f14).endVertex();
        bufferbuilder.pos((double)f17, -100.0D, (double)f17).tex((double)f22, (double)f14).endVertex();
        bufferbuilder.pos((double)f17, -100.0D, (double)(-f17)).tex((double)f22, (double)f23).endVertex();
        bufferbuilder.pos((double)(-f17), -100.0D, (double)(-f17)).tex((double)f24, (double)f23).endVertex();
        tessellator.draw();
        
        GlStateManager.rotate(-world.getCelestialAngle(partialTicks) * 360.0F, 1.0F, 0.0F, 0.0F); //reverse rotation for celestial angle
        
        GlStateManager.rotate(-80, 1.0F, 0.0F, 0.0F);//rotate drawing pad to horizon
        GlStateManager.rotate(75, 0.0F, 1.0F, 0.0F);//rotate drawing pad to sideways
        
        //custom third celestial object
        float jupSize = 65.0F; //size of the sun? default is 30.0F
        this.renderEngine.bindTexture(JUPITER_TEXTURES);
        bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
        bufferbuilder.pos((double)(-jupSize), 100.0D, (double)(-jupSize)).tex(0.0D, 0.0D).endVertex();
        bufferbuilder.pos((double)jupSize, 100.0D, (double)(-jupSize)).tex(1.0D, 0.0D).endVertex();
        bufferbuilder.pos((double)jupSize, 100.0D, (double)jupSize).tex(1.0D, 1.0D).endVertex();
        bufferbuilder.pos((double)(-jupSize), 100.0D, (double)jupSize).tex(0.0D, 1.0D).endVertex();
        tessellator.draw();
        
        GlStateManager.rotate(-75, 0.0F, 1.0F, 0.0F);//rotate back upright
        GlStateManager.rotate(80, 1.0F, 0.0F, 0.0F);//rotate drawing pad back to default position for vanilla celestial objects
        
        GlStateManager.disableTexture2D();

This creates a third visible 2d texture that always appears slanted on the horizon, which is perfect. The only issue is, I want the sun to render behind it. I tried drawing the third object both before and after the sun is drawn, but either way, the sun always appears on top of it, rather then behind it. How could I force the third image to overlap the sun? I'm new to working with minecrafts' rendering code, and I haven't been able to find any helpful resources for it.

 

EDIT: The moon overlaps it too...

EDIT2: I've figured out that the second argument in bufferbuilder.pos(#,#,#) controls depth, but it still doesn't seem to help the draw issue; textures behind other textures still render over for some reason.

Edited by pacguy
Posted

I was able to find a fix on my own! Turns out, it appears the way it does because of these lines earlier in the vanilla code:

        GlStateManager.disableAlpha();
        GlStateManager.enableBlend();

the blend feature caused all the images to appear transparent relative to each other, making it seem like they always overlapped. running disableBlend(), enableAlpha, then modifying the images to use transparency did the trick! Everything now renders based on the order it was drawn like expected :3

 

Posting this for reference, in case someone has a similar issue.

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

    • "I want to understand how complex mods with ASM transformation and coremods work, such as Xray or AntiXray. Why do they break when you simply rename packages? What features of their architecture make refactoring difficult? And what techniques are used to protect these mods? I am interested in technical aspects in order to better understand the bytecode and Forge loader system."
    • I can't figure out if you're looking for help trying to steal someone elses work, or cheat at the game....
    • Title: Why Is It So Hard to Rename and Restructure Mods Like Xray or AntiXray? 🤔 Post text: Hey everyone! I’ve been digging into Minecraft modding for a while and have one big question that I can’t figure out on my own. Maybe someone with more experience could help or give me some advice. Here’s the issue: When I take a “normal” Minecraft mod — for example, one that just adds some blocks or new items — I can easily change its structure, package names, or even rebrand it entirely. It’s straightforward. But as soon as I try this with cheat-type mods like XrayMod or AntiXray, everything falls apart. Even if I just rename the classes, refactor the packages, or hide its identity somehow, the mod either breaks or stops working properly. XrayMod in particular is proving to be a nightmare to modify without losing its core function. So my question is — why is this so much harder with cheat mods like Xray? Is there something fundamentally different about how they’re coded, loaded, or protected that prevents simple renaming or restructuring? And if so, how can I actually learn to understand someone else’s cheat mod enough to safely refactor it without breaking the core features? I’ve already been spending over two months trying to figure this out and haven’t gotten anywhere. It feels like there must be some trick or knowledge I’m missing. Would really appreciate any thoughts, tips, or references — maybe there are guides or techniques for understanding cheat-mod internals? Or if you’ve successfully “disguised” a cheat mod like Xray before, I’d love to hear how you did it. Thanks in advance for any help or discussion. ✌️
    • just started making cinamatic contect check it out on my channel or check out my facebook page    Humbug City Minecraft Youtube https://www.youtube.com/watch?v=v2N6OveKwno https://www.facebook.com/profile.php?id=61575866982337  
    • Where did you get the schematic? Source/Link? And do use an own modpack or a pre-configured from curseforge? If yes, which one On a later time, I can make some tests on my own - but I need the schematic and the modpack name
  • Topics

×
×
  • Create New...

Important Information

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