Jump to content

[1.7.10] Massive rendering glitches with Multiblock OBJ Model


BenignBanana

Recommended Posts

Hi guys,

I'm working on a somewhat complex Mod Project right now and I want to use a custom single model for my multiblock structure. Everything worked fine for a while, until i started noticing massive glitches in the rendering of the models.

 

Here are some screenshots:

 

 

 

This is how the model is supposed to look:

 

maya.png

 

 

As you can see, the back of the model is rendering over the front (or in picture 2, the second model is rendering over the first).

 

These are the main relevant files, the rest can be found on my https://github.com/Todkommt/Mass-Effect-Ships-Mod:

 

 

TileEntityCustomRenderer:

public class TileEntityEezoCoreBaseRenderer extends TileEntitySpecialRenderer {
    private static final ModelSphere model = new ModelSphere();

    private final DisplayListWrapper wrapper = new DisplayListWrapper() {
        @Override
        public void compile() {
            Tessellator t = Tessellator.instance;
            RenderBlocks renderBlocks = new RenderBlocks();
            renderBlocks.setRenderBounds(0.05D, 0.05D, 0.05D, 0.95D, 0.95D, 0.95D);
            t.startDrawingQuads();
            t.setBrightness(200);
            renderBlocks.renderFaceXNeg(ModBlocks.eezoCoreBase, -0.5D, 0.0D, -0.5D, Icons.marker);
            renderBlocks.renderFaceXPos(ModBlocks.eezoCoreBase, -0.5D, 0.0D, -0.5D, Icons.marker);
            renderBlocks.renderFaceYNeg(ModBlocks.eezoCoreBase, -0.5D, 0.0D, -0.5D, Icons.marker);
            renderBlocks.renderFaceYPos(ModBlocks.eezoCoreBase, -0.5D, 0.0D, -0.5D, Icons.marker);
            renderBlocks.renderFaceZNeg(ModBlocks.eezoCoreBase, -0.5D, 0.0D, -0.5D, Icons.marker);
            renderBlocks.renderFaceZPos(ModBlocks.eezoCoreBase, -0.5D, 0.0D, -0.5D, Icons.marker);
            t.draw();
        }
    };

    public TileEntityEezoCoreBaseRenderer() {
        MinecraftForge.EVENT_BUS.register(this);
    }

    @SubscribeEvent
    public void onTextureChange(TextureStitchEvent event) {
        if (event.map.getTextureType() == 0) wrapper.reset();
    }

    @Override
    public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) {
        TileEntityEezoCoreMultiblock multiblock = (TileEntityEezoCoreMultiblock)tileentity;

        if(multiblock.isComplete()) {
            GL11.glPushMatrix();

            int diameter = multiblock.getRadius() * 2 + 1;
            GL11.glTranslated(x - multiblock.getRadius(), y + ((multiblock.getRadius() * 2 + 1) * 0.106), z + multiblock.getRadius() + 1);
            //GL11.glScaled(diameter, diameter, diameter);
            GL11.glScaled(diameter * 0.00156493134906993521705858633492d, diameter * 0.00160472945866056441544520009372d, diameter * 0.00156486196352619735413139206991d);

            bindTexture(Textures.Model.CORE_BASE);
            model.renderPart("base");

            bindTexture(Textures.Model.CORE_MID);
            model.renderPart("mid");

            if (multiblock.isActive())
            {
                this.bindTexture(Textures.Model.CORE_ACTIVE);
            }
            else
            {
                this.bindTexture(Textures.Model.CORE_IDLE);
            }

            model.renderPart("core");

            /*model.renderPart("sphere");

            bindTexture(Textures.Model.CORE_BOTTOM);

            model.renderPart("bottom");*/
            GL11.glPopMatrix();
        } else if (multiblock.shouldRenderGuide()) {
            GL11.glPushMatrix();
            GL11.glTranslated(x, y, z);
            float scaleDelta = multiblock.getTimeSinceChange();
            renderShape(multiblock, multiblock.getShape(), multiblock.getColor(), scaleDelta);
            if (scaleDelta < 1.0) {
                renderShape(multiblock, multiblock.getShape(), multiblock.getColor(), 1.0f - scaleDelta);
            }
            GL11.glPopMatrix();
        }
    }

    private void renderShape(TileEntityEezoCoreMultiblock tileEntity, Collection<Coord> shape, int color, float scale) {
        if (shape == null) return;

        TextureUtils.bindDefaultTerrainTexture();

        GL11.glColor3ub((byte) (color >> 16), (byte) (color >> , (byte) (color >> 0));
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
        GL11.glDisable(GL11.GL_LIGHTING);

        for (Coord coord : shape)
            renderAt(coord.x, coord.y + tileEntity.getRadius(), coord.z, scale);

        GL11.glEnable(GL11.GL_LIGHTING);
        GL11.glDisable(GL11.GL_BLEND);
    }

    private void renderAt(double x, double y, double z, float scale) {
        GL11.glPushMatrix();
        GL11.glTranslated(x + 0.5F, y, z + 0.5F);
        GL11.glScalef(scale, scale, scale);
        wrapper.render();
        GL11.glPopMatrix();
    }
}

 

ModelSphere:

@SideOnly(Side.CLIENT)
public class ModelSphere
{
    private IModelCustom modelSphere;

    public ModelSphere()
    {
        modelSphere = AdvancedModelLoader.loadModel(Models.SPHERE);
    }

    public void render()
    {
        modelSphere.renderAll();
    }

    public void renderPart(String partName)
    {
        modelSphere.renderPart(partName);
    }
}

 

 

 

Any help would be greatly appreciated. I'd look into this myself, but I have no experience with OpenGL or 3D Programming in general, so I cant really figure out whats going on.

 

Thank you in advance.

Link to comment
Share on other sites

Ahh, good ol' depth sorting.

 

How many of those bits have transparent parts?

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

Ahh, good ol' depth sorting.

 

How many of those bits have transparent parts?

 

Ah, draco, I seem to see you in every thread that I find when googleing forge-related problems =)

Anyways, if you're talking about the model, I don't think it has any transparent parts. I extracted it from the Mass Effect 3 game files, but I had the same problem with a default sphere generated in Maya with a white Texture. If you're talking about transparent blocks, all multiblock parts apart from the base are transparent (for obvious reasons).

Link to comment
Share on other sites

Ok, so, basically the problem boils down to this:

 

Minecraft is really really bad at Z-sorting.  That is, figuring out what triangles need to be drawn first and which ones not at all.  It's a hard problem in any case, just Minecraft is less-good on average on account of having been programmed by one guy.  It gets away with this accurately on most occasions by assuming that everything is a cube and that triangles don't intersect.  Things get trickier if the triangles in question have any sort of transparency (and if you look at vanilla, it has this problem a lot: particles rendering behind water, and so on).

 

Anyway, if nothing's transparent, then there's some kind of z-sort that's assuming one thing, but which isn't true.  My guess is that the model pieces stick out of their blocks, but are being sorted by where they should be in screen-z-space as if they were contained to their cube volume.

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

Ok, so, basically the problem boils down to this:

 

Minecraft is really really bad at Z-sorting.  That is, figuring out what triangles need to be drawn first and which ones not at all.  It's a hard problem in any case, just Minecraft is less-good on average on account of having been programmed by one guy.  It gets away with this accurately on most occasions by assuming that everything is a cube and that triangles don't intersect.  Things get trickier if the triangles in question have any sort of transparency (and if you look at vanilla, it has this problem a lot: particles rendering behind water, and so on).

 

Anyway, if nothing's transparent, then there's some kind of z-sort that's assuming one thing, but which isn't true.  My guess is that the model pieces stick out of their blocks, but are being sorted by where they should be in screen-z-space as if they were contained to their cube volume.

 

That's quite unfortunate. Is there any way to fix this problem or do I just have to use a different way of rendering this and/or use a simpler model?

Link to comment
Share on other sites

Your easiest solutions are to break the model up differently or use a simpler model.

 

You're not likely to fix it by changing the rendering code, unless you want to solve some of the holy grails in computer graphics.

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

Hi

 

The problem that minecraft 1.7.10 has with z-sorting is only for partially transparent textures  (and it's fixed in 1.8 FYI).

 

Your object has fully-solid-or-fully-transparent texels only, so it should render fine - the z-buffer in OpenGL does all the work for you, minecraft doesn't need to do any sorting at all.

 

Your rendering code appears to turn on alpha blending, which is not needed, so perhaps it also turns off writing to the z-buffer.

Try adding these lines to the start of your rendering:

 

        GL11.glEnable(GL11.GL_DEPTH_TEST);

        GL11.glDepthMask(true);

        GL11.glEnable(GL11.GL_ALPHA_TEST);

        GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);

 

If that doesn't work, there is probably something wrong with your model.  Round/spherical objects are always a problem.  If you post a video where you walk around the model and look at it from different angles, it will help us diagnose the issue.

 

-TGG

 

PS what is this?

        wrapper.render();

Couldn't find wrapper anywhere.

Link to comment
Share on other sites

Hi

 

The problem that minecraft 1.7.10 has with z-sorting is only for partially transparent textures  (and it's fixed in 1.8 FYI).

 

Your object has fully-solid-or-fully-transparent texels only, so it should render fine - the z-buffer in OpenGL does all the work for you, minecraft doesn't need to do any sorting at all.

 

Your rendering code appears to turn on alpha blending, which is not needed, so perhaps it also turns off writing to the z-buffer.

Try adding these lines to the start of your rendering:

 

        GL11.glEnable(GL11.GL_DEPTH_TEST);

        GL11.glDepthMask(true);

        GL11.glEnable(GL11.GL_ALPHA_TEST);

        GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);

 

If that doesn't work, there is probably something wrong with your model.  Round/spherical objects are always a problem.  If you post a video where you walk around the model and look at it from different angles, it will help us diagnose the issue.

 

-TGG

 

PS what is this?

        wrapper.render();

Couldn't find wrapper anywhere.

 

Man am I glad I left the E-Mail notifications on instead of giving up on this. That worked! You're a lifesaver! Also, it's irrelevant now but wrapper is the anonymous type in the TESR, it's used to render a block guide (I copied the code from OpenBlocks' guide).

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

    • I create my mod pack,yesterday my mod pack is fine but i add one mod and error. I'm delete this mmod but minecraft is still stop on CONFIG_LOAD then I tried to delete config and restart it but again. If you can pleace help me. https://imgur.com/ngZBzuv
    • game crashes before even opening (log:https://mclo.gs/M8xvX7c)
    • I have created a custom entity that extends "TamableAnimal", but I am wanting to have it spawn in the ocean. I have it spawning right now, but it spawns way too frequently even with weight set to 1. I am guessing it is because it is rolling in the spawn pool of land animals since TameableAnimal extends Animal and is different than WaterAnimal, and since no land animals spawn in the ocean it just fills every inch up with my custom entity. I have followed basic tutorials for spawning entities with Forge, but I feel like I am missing something about how to change what spawn pool this custom entity ends up in. Is it possible to change that or do I need to refactor it to be based off of WaterAnimal to get those spawn? My biome modifier JSON file: { "type": "forge:add_spawns", "biomes": "#minecraft:is_ocean", "spawners": { "type": "darwinsmysticalmounts:water_wyvern", "weight": 20, "minCount": 1, "maxCount": 1 } } My client event: event.register(ModEntityTypes.WATER_WYVERN.get(), SpawnPlacements.Type.NO_RESTRICTIONS, Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, WaterWyvernEntity::checkWaterWyvernSpawnRules, SpawnPlacementRegisterEvent.Operation.REPLACE); And the actual custom spawn rule that makes it spawn in the water: public static boolean checkWaterWyvernSpawnRules(EntityType<WaterWyvernEntity> pAnimal, LevelAccessor pLevel, MobSpawnType pSpawnType, BlockPos pPos, RandomSource pRandom) { return pPos.getY() > pLevel.getSeaLevel() - 16 && pLevel.getFluidState(pPos.below()).is(FluidTags.WATER); }  
    • Starting today, I am unable to load my modded minecraft world. Forge crash log initially said it was a specific mod called Doggy Talents, which I disabled. Then it blamed JEI, and when that was disabled it blamed another mod so I assume it's something more than a specific mod. Minecraft launcher log claims "Exit Code 1". Nothing had changed since last night when it was working fine Forge Log: https://pastebin.com/S1GiBGVJ Client Log: https://pastebin.com/aLwuGUNL  
    • I am using AMD, yes. I downloaded the website's drivers and am still having the issue. I also used the Cleanup Utility just in case. 
  • Topics

×
×
  • Create New...

Important Information

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