sp614x / optifine

1.81k stars 416 forks source link

[Shader] Issue with parsing if shadowtex and shadowcolor is used #7503

Open GeForceLegend opened 1 year ago

GeForceLegend commented 1 year ago

Description of Issue

With certain macro blocks, Optifine will consider shadowtex and shadowcolor is not used even its actually used in shader source. When happening, all shadowtex and shadowcolor samples will result in black, and anything uses shadow matrix (including custom uniforms) will be absolutely wrong.

Steps to Reproduce

I'll provide an exmaple shader, and here is its core code: There is an include file test.glsl with code below:

#ifndef TEST_INCLUDE
#define TEST_INCLUDE

uniform sampler2D shadowtex0;
uniform sampler2D shadowtex1;
uniform sampler2D shadowcolor0;
uniform sampler2D shadowcolor1;

#endif

And in composite.fsh, we use this include in this way:

#ifdef TEST
    #include "/test.glsl"
#else
    #include "/test.glsl"
#endif

If TEST is not defined, no shadowtex or shadowcolor will be considered as used, and then Optifine will not even call the shadow pass.

OptiFine Version

1.20.1 I5

Installation Method

Standalone

Log Files/Crash Reports

If the TEST described above is not defined, info in log says that no shadowtex or shadowcolor is used;

[Render thread/INFO]: [Shaders] usedShadowColorBuffers: 0
[Render thread/INFO]: [Shaders] usedShadowDepthBuffers: 0

But if TEST is defined, everything just looks fine

[Render thread/INFO]: [Shaders] usedShadowColorBuffers: 2
[Render thread/INFO]: [Shaders] usedShadowDepthBuffers: 2

F3 Debug Screenshot

If TEST is defined: 2023-07-26_13 11 00 If its not defined: 2023-07-26_13 10 38

Additional Information

shaders.zip

GeForceLegend commented 2 months ago

Still exist in 1.21.1 J1. This is mostly happen when shader developers merging vert and frag shader source to one file, and using defines to use part of it, like the code below:

#ifdef VSH
// vertex shader file, including those uniforms
#else
// fragment shader file, including those uniforms too
#endif

Changing fragment part to the top can save it, but this also should be considerd as a macro parsing issue, meaning Optifine skipped, or ignored some macro branches when parsing.