Jump to content

Custom entity model renders like a grid of dots


williameze

Recommended Posts

I'm making custom models and renders for my entities, not using ModelBase. Basically they are presets of shapes so I can make complicated models faster. Sometimes they use texture, sometimes they use pure color (like GlStateManager.color((float) r, (float) g, (float) b, (float) a))

 

The models render really well, with color or texture, if there is no shader running.

But when GLSL shader is on, they either become tinted, noised, and sometimes even invisible.

 

Does anyone know the cause of this? :( I tried switching between GL11 functions and GlStateManager functions, no different, So i kinda ran out of ideas.

 

This is rendering ok

PNcSmCX.png

 

These are having problems

wUobrIT.png

wfkLeOa.png

41PEras.png

181aQvo.png

mnmE090.png

 

These are the codes.

 

CustomModelBase (the base for shapes like cubes, pipes, spheres,...)

 


    public void fullRender()
    {
        push();
        resetColor();
        enableNormalize(true);
        enableBlend(true);
        blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        if (shouldApplyTexture())
        {
            enableTexture(true);
            bindTexture(texture);
        }
        else
        {
            enableTexture(false);
            color(color.red, color.green, color.blue, color.alpha);
        }
        translate(localTranslate.xCoord, localTranslate.yCoord, localTranslate.zCoord);
        scale(localScale.xCoord, localScale.yCoord, localScale.zCoord);
        if (!centerRots.isEmpty())
        {
            translate(localCenter.xCoord, localCenter.yCoord, localCenter.zCoord);
            for (int a = centerRots.size() - 1; a >= 0; a--)
            {
                RotateVec rot = centerRots.get(a);
                rotate(rot.rotation, rot.vec.xCoord, rot.vec.yCoord, rot.vec.zCoord);
            }
            translate(-localCenter.xCoord, -localCenter.yCoord, -localCenter.zCoord);
        }
        if (visible == 2 || visible == 3) render();
        if (visible == 1 || visible == 3) renderChilds();
        enableNormalize(false);
        enableTexture(true);
        pop();
    }


    public boolean shouldApplyTexture()
    {
        return texture != null && (useTexture || color == null);
    }

    public static void push()
    {
        if (USEGLSM) GlStateManager.pushMatrix();
        else GL11.glPushMatrix();
    }

    public static void pop()
    {
        if (USEGLSM) GlStateManager.popMatrix();
        else GL11.glPopMatrix();
    }

    public static void color(double r, double g, double b)
    {
        color(r, g, b, 1);
    }

    public static void color(double r, double g, double b, double a)
    {
        if (USEGLSM) GlStateManager.color((float) r, (float) g, (float) b, (float) a);
        else GL11.glColor4d(r, g, b, a);
    }

    public static void resetColor()
    {
        color(1, 1, 1, 1);
    }

    public static void clearColor(double r, double g, double b, double a)
    {
        if (USEGLSM) GlStateManager.clearColor((float) r, (float) g, (float) b, (float) a);
        else GL11.glClearColor((float) r, (float) g, (float) b, (float) a);
    }

    public static void enableNormalize(boolean enable)
    {
        if (enable)
        {
            if (USEGLSM) GlStateManager.enableNormalize();
            else GL11.glEnable(GL11.GL_NORMALIZE);
        }
        else
        {
            if (USEGLSM) GlStateManager.disableNormalize();
            else GL11.glDisable(GL11.GL_NORMALIZE);
        }
    }

    public static void enableLighting(boolean enable)
    {
        if (enable)
        {
            if (USEGLSM) GlStateManager.enableLighting();
            else GL11.glEnable(GL11.GL_LIGHTING);
        }
        else
        {
            if (USEGLSM) GlStateManager.disableLighting();
            else GL11.glDisable(GL11.GL_LIGHTING);
        }
    }

    public static void enableFog(boolean enable)
    {
        if (enable)
        {
            if (USEGLSM) GlStateManager.enableFog();
            else GL11.glEnable(GL11.GL_FOG);
        }
        else
        {
            if (USEGLSM) GlStateManager.disableFog();
            else GL11.glDisable(GL11.GL_FOG);
        }
    }

    public static void enableTexture(boolean enable)
    {
        if (enable)
        {
            if (USEGLSM) GlStateManager.enableTexture2D();
            else GL11.glEnable(GL11.GL_TEXTURE_2D);
        }
        else
        {
            if (USEGLSM) GlStateManager.disableTexture2D();
            else GL11.glDisable(GL11.GL_TEXTURE_2D);
        }
    }

    public static void enableColorMaterial(boolean enable)
    {
        if (enable)
        {
            if (USEGLSM) GlStateManager.enableColorMaterial();
            else GL11.glEnable(GL11.GL_COLOR_MATERIAL);
        }
        else
        {
            if (USEGLSM) GlStateManager.disableColorMaterial();
            else GL11.glDisable(GL11.GL_COLOR_MATERIAL);
        }
    }

    public static void enableAlpha(boolean enable)
    {
        if (enable)
        {
            if (USEGLSM) GlStateManager.enableAlpha();
            else GL11.glEnable(GL11.GL_ALPHA_TEST);
        }
        else
        {
            if (USEGLSM) GlStateManager.disableAlpha();
            else GL11.glDisable(GL11.GL_ALPHA_TEST);
        }
    }

    public static void enableBlend(boolean enable)
    {
        if (enable)
        {
            if (USEGLSM) GlStateManager.enableBlend();
            else GL11.glEnable(GL11.GL_BLEND);
        }
        else
        {
            if (USEGLSM) GlStateManager.disableBlend();
            else GL11.glDisable(GL11.GL_BLEND);
        }
    }

    public static void enableCull(boolean enable)
    {
        if (enable)
        {
            if (USEGLSM) GlStateManager.enableCull();
            else GL11.glEnable(GL11.GL_CULL_FACE);
        }
        else
        {
            if (USEGLSM) GlStateManager.disableCull();
            else GL11.glDisable(GL11.GL_CULL_FACE);
        }
    }

    public static void blendFunc(int i1, int i2)
    {
        if (USEGLSM) GlStateManager.blendFunc(i1, i2);
        else GL11.glBlendFunc(i1, i2);
    }

    public static void translate(double x, double y, double z)
    {
        if (USEGLSM) GlStateManager.translate(x, y, z);
        else GL11.glTranslated(x, y, z);
    }

    public static void scale(double x, double y, double z)
    {
        if (USEGLSM) GlStateManager.scale(x, y, z);
        else GL11.glScaled(x, y, z);
    }

    public static void rotate(double angle, double x, double y, double z)
    {
        if (USEGLSM) GlStateManager.rotate((float) angle, (float) x, (float) y, (float) z);
        else GL11.glRotated(angle, x, y, z);
    }

    public static void lineWidth(double w)
    {
        if (USEGLSM) GlStateManager.glLineWidth((float) w);
        else GL11.glLineWidth((float) w);
    }

    public static void begin(int mode)
    {
        if (USEGLSM) GlStateManager.glBegin(mode);
        else GL11.glBegin(mode);
    }

    public static void enable(int enable)
    {
        if (USEGLSM) GlStateManager.glEnableClientState(enable);
        else GL11.glEnable(enable);
    }

    public void vertex(double x, double y, double z, double u, double v)
    {
        if (USEGLSM)
        {
            if (shouldApplyTexture()) GlStateManager.glTexCoord2f((float) u, (float) v);
            GlStateManager.glVertex3f((float) x, (float) y, (float) z);
        }
        else
        {
            if (shouldApplyTexture()) GL11.glTexCoord2d(u, v);
            GL11.glVertex3d(x, y, z);
        }
    }

    public void vertex(double x, double y, double z, double u, double v, double w, double h)
    {
        if (shouldApplyTexture()) GL11.glTexCoord4d(u, v, w, h);
        GL11.glVertex3d(x, y, z);
    }

    public static void normal(double x, double y, double z)
    {
        if (USEGLSM) GlStateManager.glNormal3f((float) x, (float) y, (float) z);
        else GL11.glNormal3d(x, y, z);
    }

    public static void end()
    {
        if (USEGLSM) GlStateManager.glEnd();
        else GL11.glEnd();
    }

 

 

CMBox (the cube model)

 

package williamle.drones.custommodel;

import org.lwjgl.opengl.GL11;

import net.minecraft.util.math.Vec3d;

public class CMBox extends CMBase
{
    double x1, y1, z1, x2, y2, z2;

    public CMBox(double size)
    {
        this(size, size, size, null);
    }

    public CMBox(double size, Vec3d mid)
    {
        this(size, size, size, mid);
    }

    public CMBox(double xw, double yw, double zw)
    {
        this(xw, yw, zw, null);
    }

    public CMBox(double xw, double yw, double zw, Vec3d mid)
    {
        this(-xw / 2 + (mid == null ? 0 : mid.xCoord), -yw / 2 + (mid == null ? 0 : mid.yCoord),
                -zw / 2 + (mid == null ? 0 : mid.zCoord), xw / 2 + (mid == null ? 0 : mid.xCoord),
                yw / 2 + (mid == null ? 0 : mid.yCoord), zw / 2 + (mid == null ? 0 : mid.zCoord));
    }

    public CMBox(double x, double y, double z, double xx, double yy, double zz)
    {
        x1 = x;
        x2 = xx;
        y1 = y;
        y2 = yy;
        z1 = z;
        z2 = zz;
    }

    @Override
    public void render()
    {
        double xw = Math.abs(x2 - x1);
        double yw = Math.abs(y2 - y1);
        double zw = Math.abs(z2 - z1);
        double tWidth = xw * 2 + zw * 2;
        double tHeight = zw + yw;

        double u1 = textureUV.u1;
        double u5 = textureUV.u2;
        double u2 = u1 + zw / tWidth * (u5 - u1);
        double u3 = u2 + xw / tWidth * (u5 - u1);
        double u4 = u3 + zw / tWidth * (u5 - u1);
        double v1 = textureUV.v1;
        double v4 = textureUV.v2;
        double v2 = v1 + zw / tHeight * (v4 - v1);

        begin(GL11.GL_QUAD_STRIP);
        normal(-1, 0, 0);
        vertex(x1, y2, z1, u1, v2);
        vertex(x1, y1, z1, u1, v4);
        normal(0, 0, 1);
        vertex(x1, y2, z2, u2, v2);
        vertex(x1, y1, z2, u2, v4);
        normal(1, 0, 0);
        vertex(x2, y2, z2, u3, v2);
        vertex(x2, y1, z2, u3, v4);
        normal(0, 0, -1);
        vertex(x2, y2, z1, u4, v2);
        vertex(x2, y1, z1, u4, v4);
        normal(-1, 0, 0);
        vertex(x1, y2, z1, u5, v2);
        vertex(x1, y1, z1, u5, v4);
        end();

        begin(GL11.GL_QUADS);
        normal(0, 1, 0);
        vertex(x1, y2, z1, u2, v1);
        vertex(x1, y2, z2, u2, v2);
        vertex(x2, y2, z2, u3, v2);
        vertex(x2, y2, z1, u3, v1);
        normal(0, -1, 0);
        vertex(x2, y1, z1, u5, v2);
        vertex(x2, y1, z2, u5, v1);
        vertex(x1, y1, z2, u4, v1);
        vertex(x1, y1, z1, u4, v2);
        end();
    }
}

 

 

Model Drone file

 


    public void doRender(Object... params)
    {
        DroneAppearance.loadPresetPalettes();
        applyAppearances(params);
        applyRotation(getDrone(params), params.length > 1 ? (Float) params[1] : 0,
                params.length > 2 ? (Float) params[2] : 0);
        for (CMBase cm : models.values())
        {
            cm.fullRender();
        }
    }

 

 

Render file

 

    @Override
    public void doRender(T entity, double x, double y, double z, float entityYaw, float partialTicks)
    {
        super.doRender(entity, x, y, z, entityYaw, partialTicks);
        GL11.glPushMatrix();
        GL11.glTranslated(x, y, z);
        double d = 1;
        GL11.glScaled(d, d, d);
        ModelDrone model = getModelForDrone(entity);
        if (model != null)
        {
            model.doRender(entity, entityYaw, partialTicks);
        }
        else
        {
            defaultModel.doRender(entity, entityYaw, partialTicks);
        }
        GL11.glPopMatrix();
    }

 

Link to comment
Share on other sites

I probably can't help you myself, but you should post your code to increase the chances of someone else being able to help you.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

I didn't notice that the problem is with GLSL shader.

It can hack with shaders and might always require textures to render the entire world. So, there is no much hope for it.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

Technically, if they require to render everything with texture, it's shaders' problem. You should probably report that. Meanwhile, use other shaders (or if you're feeling like editing shaders, add boolean uniform in fragment shader to activate/deactivate texture, if it's false, use only color - without multiplying it by

tex

).

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



×
×
  • Create New...

Important Information

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