Jump to content

[1.20.1] Shaders alpha channel don't work


Recommended Posts

At the time of forge 1.16.5, I used this code:

RenderSystem.enableBlend();
RenderSystem.disableAlphaTest();
RenderSystem.defaultBlendFunc();
// render
RenderSystem.disableBlend();
RenderSystem.enableAlphaTest();

But when switching to version 1.20.1, I ran into a problem: GL_ALPHA_TEST cap can no longer be enabled, and if you specify any color with alpha less than 1.0 in the shader, then the pixel color will still be with alpha 1.0

My current code:

Shader:

#version 330 core

out vec4 fragColor;

void main() {
    fragColor = vec4(1.0, 0.0, 0.0, 0.5);
}
@SubscribeEvent
        public static void registerShader(RegisterShadersEvent event) {
            try {
                event.registerShader(new ShaderInstance(event.getResourceProvider(), new ResourceLocation("untitled", "tst"), DefaultVertexFormat.POSITION), instance -> {
                    shaderInstance = instance;
                });
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

@SubscribeEvent
    public void render2D(RenderGuiOverlayEvent.Post event) {
        RenderSystem.enableBlend();
        RenderSystem.defaultBlendFunc();

        RenderSystem.setShader(() -> shaderInstance);

        Tesselator tesselator = Tesselator.getInstance();
        BufferBuilder bufferBuilder = tesselator.getBuilder();
        bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION);
        bufferBuilder.vertex(0, 0, 0).endVertex();
        bufferBuilder.vertex(0, 50, 0).endVertex();
        bufferBuilder.vertex(100, 50, 0).endVertex();
        bufferBuilder.vertex(100, 0, 0).endVertex();
        tesselator.end();

        RenderSystem.disableBlend();
    }

If anything, the shader itself is working. I also tried rendering using POSITION_TEX vertex format, but nothing has changed.

spacer.png

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.