Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-267281

Fence multipart model system performance optimization

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • 1.20.4
    • Confirmed
    • Performance, Textures and models
    • Normal
    • Gameplay

      The bug

      Fences are a particularly laggy block due to their often complex geometry (see also MC-123584). For fences where two opposite directions have a connection, it is possible to optimize the geometry such that the game needs to render fewer triangles for effectively the same visual result.

      Currently in vanilla, fences use a multipart model consisting of a central post plus one to four outward connection pieces. These outward connections have up to ten faces each, although adjacent block culling often reduces this to eight. For fences which have both north and south connections and/or east and west connections, this adds up to 20 (often culled to 16) faces for the relevant axis. However, it's possible to reduce this to 12 (8) faces with a bit of resource pack magic.

      We implement a third model file for each fence, titled [material]_fence_side_long, which defines the two bars stretching from one end of the block to the other via one cuboid per bar, rather than the standard approach which splits it into two elements. The blockstates file for each fence is edited as to not use the standard fence_side in cases where both north and south are true (or both east and west are true), and instead use this specific long side model. As such, with less faces needed for the game to render, we get a visually identical result with less rendering performance impact.

      An implementation of this fix is attached in the form of a resource pack. Unless you use Spectator mode or otherwise find yourself intersecting fence blocks, there should be no visual difference from vanilla fences (aside from the fact that this resource pack fixes MC-109478). All fence types are affected by this fix with the exception of bamboo fences, as these use their own texturing system which would require rewriting to work with this fix.

      How to reproduce

      1. Create a creative Superflat world with the following preset:
        minecraft:barrier;minecraft:the_void
      2. Enter flying mode by double pressing the jump button
      3. Run the command
        /tp @s 0 -20 0 0 90
      4. Run the command
        /fill -30 -63 -30 30 -56 30 oak_fence
      5. Open the performance graphs via F3+2
      6. Switch between the default resources and the attached resource pack, comparing the performance

      Expected results

      Good framerates in vanilla.

      Actual results

      We can do far better.

      How to fix

      Simply implement the resources in the attached resource pack into vanilla. I give Mojang my full permission and encouragement to use these files to make vanilla Minecraft run better.

            Unassigned Unassigned
            Awesoman3000 Connor Steppie
            Votes:
            3 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              CHK: