Jump to content

[1.15.2] Translation for GL code


stepsword

Recommended Posts

So, I have some GL code in a custom RenderType, which I'm using as a wrapper for an actual RenderType. My overall goal is to apply clipping to a rendered entity.

 

                rendertype1 = new ClipWrappedRenderLayer(yaw, pitch, x,y,z,progress, rendertype1);
                IVertexBuilder ivertexbuilder = bufferIn.getBuffer(rendertype1);
                renderModel(modelIn, itemStackIn, combinedLightIn, combinedOverlayIn, matrixStackIn, ivertexbuilder);

 

    public ClipWrappedRenderLayer(double pitch, double yaw, double x,double y,double z, double p, RenderType delegate) {
        super(MahouTsukaiMod.modId + delegate.toString() + "_with_clip", delegate.getVertexFormat(), delegate.getDrawMode(), delegate.getBufferSize(), true, delegate.func_230041_s_(),
                () -> {

                    DoubleBuffer eqn1 = BufferUtils.createDoubleBuffer(8).put(new double[]{0,1,1,p});
                    eqn1.flip();
                    GL11.glClipPlane(GL11.GL_CLIP_PLANE0, eqn1);
                    GL11.glEnable(GL11.GL_CLIP_PLANE0);

                    delegate.setupRenderState();


                },
                () -> {
                    delegate.clearRenderState();

                    GL11.glDisable(GL11.GL_CLIP_PLANE0);

                });
        this.delegate = delegate;
    }

 

While the clipping does happen currently, it slides with the camera as opposed to being a static clip on the entity. Is there a way I can translate/rotate this clip to where the entity will be? Nothing I've tried in the way of translation seems to do anything except clip at a slightly different angle while still following the camera.

 

I'm assuming this setup code is called on the outside of the translation, so alternatively if there were a way to call this code on the inside of the translation, that would be good also, as that is how I did it in 1.12.2.

Link to comment
Share on other sites

Hi

 

I always find the order of translation-scaling-rotation-etc operations to be confusing so this might be off base, but I've usually found the trick to be either

1) put the operation in a different order (eg rotate then translate instead of translate then rotate); or

2) undo the transformation from model space to world space, perform the operation, then reapply the original transformation

Not sure if that's possible (or desirable) inside your new rendertype, but it might be worth a try.

-TGG

 

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.