Class EnhancedAoRenderStorage


public class EnhancedAoRenderStorage extends ModelBlockRenderer.AmbientOcclusionRenderStorage
Entrypoint and main class of our enhanced AO pipeline.

Vanilla's AO logic works well for faces that are axis-aligned. That computation is replicated in FullFaceCalculator, with some bug fixes. The job of the enhanced pipeline is to handle faces that are more complicated, by combining multiple full faces as needed using interpolation.

Compared to vanilla, we also remove any assumption about vertex order in the quad.

  • Field Details

    • COMPARE_WITH_VANILLA

      private static final boolean COMPARE_WITH_VANILLA
      Debug option to compare the emulated vanilla AO with the actual vanilla AO. Only does something if emulated AO is enabled.
    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • AO_OBJECT_CACHE

      private static final ThreadLocal<EnhancedAoRenderStorage.AoObjectCache> AO_OBJECT_CACHE
    • calculator

      private final FullFaceCalculator calculator
      Calculator for full faces.
    • weights

      private final float[] weights
    • currentQuad

      private BakedQuad currentQuad
    • AO_EPS

      private static final float AO_EPS
      See Also:
    • AVERAGE_WEIGHT

      private static final float AVERAGE_WEIGHT
      See Also:
    • MAX_WEIGHT

      private static final float MAX_WEIGHT
      See Also:
  • Constructor Details

    • EnhancedAoRenderStorage

      public EnhancedAoRenderStorage()
  • Method Details

    • newInstance

    • applyFlatQuadBrightness

      public static void applyFlatQuadBrightness(BlockAndTintGetter level, BakedQuad quad, ModelBlockRenderer.CommonRenderStorage storage)
      "Enhanced" flat shading logic.
    • captureQuad

      public void captureQuad(BakedQuad quad)
      Overrides:
      captureQuad in class ModelBlockRenderer.AmbientOcclusionRenderStorage
    • calculate

      public void calculate(BlockAndTintGetter level, BlockState state, BlockPos pos, Direction direction, boolean shade)
      Overrides:
      calculate in class ModelBlockRenderer.AmbientOcclusionRenderStorage
    • calculateAxisAligned

      private void calculateAxisAligned(BlockAndTintGetter level, BlockState state, BlockPos pos, Direction direction, boolean shade)
      Computes AO for an axis-aligned quad.

      This is similar to vanilla in how we select whether to use the inside or outside light. However, we still use our own interpolation logic which does not make any assumption about vertex winding order.

    • calculateIrregular

      private void calculateIrregular(BlockAndTintGetter level, BlockState state, BlockPos pos, boolean shade)
      Computes AO for a general quad. Projects onto each axis, computes the AO, then combines proportionally to the square of each normal component.
    • vertexPos

      private static float vertexPos(int[] vertices, int vertex, int axis)
      Extracts the position of a vertex from quad data.
      Parameters:
      vertices - quad data
      vertex - vertex index, from 0 to 3 included
      axis - axis index, for 0 to 2 included
    • normalComponent

      private static float normalComponent(int normal, int axis)
      Unpacks a normal component.
    • interpolateBrightness

      private static float interpolateBrightness(AoCalculatedFace in, float[] weights)
      Interpolates brightness from the 4 corners of a face.
    • interpolateLightmap

      private static int interpolateLightmap(AoCalculatedFace in, float[] weights)
      Interpolates lightmap from the 4 corners of a face.
    • lerpLightmap

      private static int lerpLightmap(int lightmap1, float w1, int lightmap2, float w2)
      Interpolates two lightmaps linearly.
    • maxLightmap

      static int maxLightmap(int lightmap1, int lightmap2)