sp614x / optifine

1.81k stars 416 forks source link

[Shader] Wrong texture when rendering invisible top face of boat #7608

Open GeForceLegend opened 10 months ago

GeForceLegend commented 10 months ago

Description of Issue

Boat has an invisible top that only writes to depth buffer but not color buffer to prevent water "leaks" into boat, and usually this face uses boat textures. But, if there is some rendering paintings, and the player is facing certain direction, invisible face of boat will using paintings texture. This will cause some shaders failed to discard that invisble face, as it will cause wrong depth when rendering faces inside the boat in deferred pipelines.

Steps to Reproduce

  1. Any shader that designed to discard the invisble face of boat (or create a new from shaderLABS example pack, and add discard to gbuffers_entities like this:)
    ...
    if (color.w < 0.1) discard;
    ...
  2. Placing a boat in water, and placing a painting near it. Moving around and keep looking the boat, on some angles, water in boat will get invisble. Then breaks the painting, and the water in boat will not disappear on same view angle.

Nsight graphics capture shows that the invisible top face of this oak boat is using painting texture: 20240122222451

After removing the painting, it turns normal: 20240122223124

OptiFine Version

1.20.1 I6 pre6

Installation Method

Standalone

F3 Debug Screenshot

2024-01-22_23 08 43

Prior Testing

If you've installed standalone:

Vanilla Minecraft does not using any texture when rendering this.

Additional Information

Jiingy commented 8 months ago

Can you please provide the shader used to reproduce this issue?

GeForceLegend commented 8 months ago

Can you please provide the shader used to reproduce this issue?

This affects almost all shaders simply using texture sample's alpha channel to discard the invisible top face of boats, for example, Chocapic13 V9.

This only happens when player is facing around -Z direction.

2024-03-06_10 14 55 2024-03-06_10 15 08

GeForceLegend commented 8 months ago

Noticed that when this bug happens, the invisible top part of boat is rendered directly after painting. Maybe Optifine does not set a texture, but using the prev draw call one when rendering this invisible part?

To approve this, I found another situation. If there are end portal blocks, the invisible top part sometimes (not always) writes to shadow. In this situation, the invisiable top part is using end portal texture, and it is rendered directly after end portals.

If Optifine set the texture of this invisbale part of boat to boat textures, it will fix this at most situation. Better fix might be creating and using a 1x1 texture with 0% opacity on this thing?

Related Nsight Grahpics capture, showing it's using end portal textures in shadow program. 20240307094351