sp614x / optifine

1.78k stars 419 forks source link

[shader] Wrong at_midBlock attribute on CTM overlay #7516

Open GeForceLegend opened 11 months ago

GeForceLegend commented 11 months ago

Description of Issue

Some part of CTM using overlay method will have incorrect at_midBlock attribute. Unload and load shader again will make this attribute becomes defferent. Press F3+R can also change at_midBlock of CTM overlays, tho after several reload it will not change anymore (and still incorrect).

Steps to Reproduce

An shader with only 2 files described below will directly output the at_midBlock for debug: gbuffers_terrain.vsh:

#version 450

in vec3 vaPosition;
in vec2 vaUV0;
in vec3 at_midBlock;

uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
uniform vec3 chunkOffset;

out vec2 texcoord;
out vec3 midBlock;

void main()
{
    texcoord = vaUV0;
    midBlock = at_midBlock;
    gl_Position = projectionMatrix * modelViewMatrix * vec4(vaPosition + chunkOffset, 1.0);
}

gbuffers_terrain.fsh:

#version 450

layout (location = 0) out vec4 fragColor0;

in vec2 texcoord;
in vec3 midBlock;

uniform sampler2D tex;
uniform float alphaTestRef;

void main()
{
    fragColor0 = texture(tex, texcoord);
    if (fragColor0.w < alphaTestRef)
        discard;
    fragColor0.rgb = midBlock / 64.0 + 0.5;
}

/* DRAWBUFFERS:0 */

And you will see the color of CTM overlay is incorrect.

OptiFine Version

1.20.1 I5

Installation Method

Standalone

F3 Debug Screenshot

Used resourcepack: https://modrinth.com/resourcepack/alacrity/version/24 Grass block with 8 dirt surrounding it. F3 debug screen: 2023-08-02_09 35 38 Screenshot without F3 overlay: (Reloaded the shader before take this screenshot. So it looks different with above pic.) 2023-08-02_09 26 11 Vanilla color reference: 2023-08-02_09 26 34