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

Ambient occlusion bug on staircase structures

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • Minecraft 1.7.4, Minecraft 1.8.1-pre3, Minecraft 1.8.2, Minecraft 1.8.4, Minecraft 15w42a, Minecraft 1.10.2, Minecraft 16w41a, Minecraft 16w42a, Minecraft 16w43a, Minecraft 1.11, Minecraft 1.11.2, Minecraft 17w14a, Minecraft 1.12, Minecraft 1.12.1 Pre-Release 1, Minecraft 1.12.1, Minecraft 1.12.2, Minecraft 17w47b, Minecraft 18w16a, Minecraft 1.13-pre2, Minecraft 1.13.1, 1.14.4, 19w34a, 19w45b, 1.15 Pre-release 1, 1.15 Pre-release 6, 1.15.2, 20w15a, 20w28a, 20w29a, 20w30a, 1.16.2 Pre-release 1, 20w51a, 21w03a, 21w05b, 21w10a, 21w20a, 1.17 Pre-release 1, 1.17.1, 1.18 Pre-release 1, 1.18.1, 22w05a, 22w16b, 23w44a
    • Confirmed
    • Lighting, Rendering
    • Normal
    • Platform

      NOTE: the following fix pertains to 1.7, an updated version will be needed for 1.16+

      Let me first off say that I know this is a duplicate, but I have code-fixes for it.

      As you can see in the 2 images, the first one (The bugged version), has inconsistent lighting travelling from one block to the next, the corners don't match up. This is primarily noticeable in 1 wide staircases underground, and for good reason.

      Basically what is happening is that the render code is checking the transparency of blocks with an incorrect offset. When you get your coordinates wrong you're bound to get some weird results.

      This code is drawing the bottom face.

      if (this.renderMinY <= 0.0D)
      {
           --y;
      }
      
      this.aoBrightnessXYNN = par1Block.getMixedBrightnessForBlock(this.blockAccess, x - 1, y, z);
      this.aoBrightnessYZNN = par1Block.getMixedBrightnessForBlock(this.blockAccess, x, y, z - 1);
      this.aoBrightnessYZNP = par1Block.getMixedBrightnessForBlock(this.blockAccess, x, y, z + 1);
      this.aoBrightnessXYPN = par1Block.getMixedBrightnessForBlock(this.blockAccess, x + 1, y, z);
      this.aoLightValueScratchXYNN = par1Block.getAmbientOcclusionLightValue(this.blockAccess, x - 1, y, z);
      this.aoLightValueScratchYZNN = par1Block.getAmbientOcclusionLightValue(this.blockAccess, x, y, z - 1);
      this.aoLightValueScratchYZNP = par1Block.getAmbientOcclusionLightValue(this.blockAccess, x, y, z + 1);
      this.aoLightValueScratchXYPN = par1Block.getAmbientOcclusionLightValue(this.blockAccess, x + 1, y, z);
      transparencyXYPN = Block.canBlockGrass[this.blockAccess.getBlockId(x + 1, y - 1, z)];
      transparencyXYNN = Block.canBlockGrass[this.blockAccess.getBlockId(x - 1, y - 1, z)];
      transparencyYZNP = Block.canBlockGrass[this.blockAccess.getBlockId(x, y - 1, z + 1)];
      transparencyYZNN = Block.canBlockGrass[this.blockAccess.getBlockId(x, y - 1, z - 1)];
      
      if (!transparencyYZNN && !transparencyXYNN)
      {
           this.aoLightValueScratchXYZNNN = this.aoLightValueScratchXYNN;
           this.aoBrightnessXYZNNN = this.aoBrightnessXYNN;
      }
      else
      {
           this.aoLightValueScratchXYZNNN = par1Block.getAmbientOcclusionLightValue(this.blockAccess, x - 1, y, z - 1);
           this.aoBrightnessXYZNNN = par1Block.getMixedBrightnessForBlock(this.blockAccess, x - 1, y, z - 1);
      }

      What it does is decrements the y value to save a bunch of subtractions since the whole next section uses "y - 1". It appears as if in the case of every face, a part was left as "y - 1" (Or any other respective coordinate changes such as "y + 1", "x - 1", "x + 1", "z - 1", "z + 1").

      transparencyXYPN = Block.canBlockGrass[this.blockAccess.getBlockId(x + 1, y - 1, z)];
      transparencyXYNN = Block.canBlockGrass[this.blockAccess.getBlockId(x - 1, y - 1, z)];
      transparencyYZNP = Block.canBlockGrass[this.blockAccess.getBlockId(x, y - 1, z + 1)];
      transparencyYZNN = Block.canBlockGrass[this.blockAccess.getBlockId(x, y - 1, z - 1)];

      The way I was able to fix this was by adding 3 ints at the top of the method called xConst, yConst, zConst (or more appropriate names), set those to the coordinates passed into the function and changed the code to

      transparencyXYPN = Block.canBlockGrass[this.blockAccess.getBlockId(x + 1, yConst - 1, z)];
      transparencyXYNN = Block.canBlockGrass[this.blockAccess.getBlockId(x - 1, yConst - 1, z)];
      transparencyYZNP = Block.canBlockGrass[this.blockAccess.getBlockId(x, yConst - 1, z + 1)];
      transparencyYZNN = Block.canBlockGrass[this.blockAccess.getBlockId(x, yConst - 1, z - 1)];

      This bug is both aesthetically unpleasing, but also causes the "Lava light leaking through corners" bug.

      Also, while I was looking through the rendering code, I found the source of the upside-down half-slab lighting bug. A half-slab gets lit using the highest of the neighbour's light values, but it doesn't check the light value of the block below.

      topBrightness = this.getSpecialBlockBrightness(par1EnumSkyBlock, par2, par3 + 1, par4);
      eastBrightness = this.getSpecialBlockBrightness(par1EnumSkyBlock, par2 + 1, par3, par4);
      int westBrightness = this.getSpecialBlockBrightness(par1EnumSkyBlock, par2 - 1, par3, par4);
      int northBrightness = this.getSpecialBlockBrightness(par1EnumSkyBlock, par2, par3, par4 + 1);
      int southBrightness = this.getSpecialBlockBrightness(par1EnumSkyBlock, par2, par3, par4 - 1);
      
      if (eastBrightness > topBrightness)
      {
      	topBrightness = eastBrightness;
      }
      
      if (westBrightness > topBrightness)
      {
      	topBrightness = westBrightness;
      }
      
      if (northBrightness > topBrightness)
      {
      	topBrightness = northBrightness;
      }
      
      if (southBrightness > topBrightness)
      {
      	topBrightness = southBrightness;
      }
      
      return topBrightness;

      The first idea that comes to mind is to push this code into the Block class so that it can be overloaded in child classes such as slabs.

        1. 13w11a staircase.png
          13w11a staircase.png
          222 kB
        2. 13w12~ staircase.png
          13w12~ staircase.png
          211 kB
        3. 2015-05-03_16.18.33.png
          2015-05-03_16.18.33.png
          875 kB
        4. 2015-05-22_23.34.01.png
          2015-05-22_23.34.01.png
          196 kB
        5. 2017-11-26_19.11.53.png
          2017-11-26_19.11.53.png
          1.20 MB
        6. 2017-11-26_19.11.55.png
          2017-11-26_19.11.55.png
          1.08 MB
        7. 2018-04-30_00.22.04.png
          2018-04-30_00.22.04.png
          791 kB
        8. 2019-08-24_21.57.22.png
          2019-08-24_21.57.22.png
          637 kB
        9. 2021-05-31_18.14.48.png
          2021-05-31_18.14.48.png
          165 kB
        10. 2021-08-19_09.33.49.png
          2021-08-19_09.33.49.png
          387 kB
        11. Bugged.png
          Bugged.png
          475 kB
        12. Fixed.png
          Fixed.png
          477 kB

            Unassigned Unassigned
            Awesoman3000 Connor Steppie
            Votes:
            85 Vote for this issue
            Watchers:
            33 Start watching this issue

              Created:
              Updated:
              CHK: