Class FullFaceCalculator
java.lang.Object
net.neoforged.neoforge.client.model.ao.FullFaceCalculator
Calculates AO for a full cube face.
There are 24 possible configurations for each block, depending on: the direction,
whether the quad wants to be shaded, and whether the sample is taken outside the block.
The EnhancedAoRenderStorage
then works by combining the results of multiple configurations,
using various interpolation schemes depending on the quad.
The logic is mostly contained in calculateFaceUncached(net.neoforged.neoforge.client.model.ao.AoCalculatedFace, net.minecraft.world.level.BlockAndTintGetter, net.minecraft.world.level.block.state.BlockState, net.minecraft.core.BlockPos, net.minecraft.core.Direction, boolean, boolean)
,
and derives from vanilla's ModelBlockRenderer.AmbientOcclusionRenderStorage.calculate(net.minecraft.world.level.BlockAndTintGetter, net.minecraft.world.level.block.state.BlockState, net.minecraft.core.BlockPos, net.minecraft.core.Direction, boolean)
,
with a few fixes applied:
- Fix vanilla sampling adjacent blocks 2 blocks away instead of 1 block away.
- Fix vanilla using the wrong edges when computing some corners when both `sideClear`s are false.
- Replace vanilla lightmap blending formula which can cause seams by an improved formula.
- Always use the sampling position to compute the inner light, even if the block outside of the face is not solid. This is not guaranteed to be an improvement in all cases, but it does at least fix some cases.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AoCalculatedFace[]
private net.minecraft.client.renderer.block.ModelBlockRenderer.Cache
private int
private static final boolean
Debug option to disable the lightmap blending formula fix.(package private) final net.minecraft.core.BlockPos.MutableBlockPos
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static int
blend
(int sideLightmapA, int sideLightmapB, int cornerLightmap, int insideLightmap, boolean sideClearA, boolean sideClearB, boolean cornerClear, boolean insideClear) Computes the lightmap of the corner of an AO face, by combining the lightmap values on the two neighbor blocks, on the corner block, and inside the block.(package private) AoCalculatedFace
calculateFace
(net.minecraft.world.level.BlockAndTintGetter level, net.minecraft.world.level.block.state.BlockState renderedState, net.minecraft.core.BlockPos renderedPos, net.minecraft.core.Direction direction, boolean shade, boolean sampleOutside) private void
calculateFaceUncached
(AoCalculatedFace out, net.minecraft.world.level.BlockAndTintGetter level, net.minecraft.world.level.block.state.BlockState renderedState, net.minecraft.core.BlockPos renderedPos, net.minecraft.core.Direction direction, boolean shade, boolean sampleOutside) Computes the AO for a full face.(package private) void
startBlock
(net.minecraft.client.renderer.block.ModelBlockRenderer.Cache cache)
-
Field Details
-
DISABLE_LIGHTMAP_BLENDING_FIX
private static final boolean DISABLE_LIGHTMAP_BLENDING_FIXDebug option to disable the lightmap blending formula fix. See below for an explanation. -
scratchPos
final net.minecraft.core.BlockPos.MutableBlockPos scratchPos -
cache
private net.minecraft.client.renderer.block.ModelBlockRenderer.Cache cache -
aoFaces
-
calculatedAoFaces
private int calculatedAoFaces
-
-
Constructor Details
-
FullFaceCalculator
FullFaceCalculator()
-
-
Method Details
-
startBlock
void startBlock(net.minecraft.client.renderer.block.ModelBlockRenderer.Cache cache) -
calculateFace
AoCalculatedFace calculateFace(net.minecraft.world.level.BlockAndTintGetter level, net.minecraft.world.level.block.state.BlockState renderedState, net.minecraft.core.BlockPos renderedPos, net.minecraft.core.Direction direction, boolean shade, boolean sampleOutside) -
calculateFaceUncached
private void calculateFaceUncached(AoCalculatedFace out, net.minecraft.world.level.BlockAndTintGetter level, net.minecraft.world.level.block.state.BlockState renderedState, net.minecraft.core.BlockPos renderedPos, net.minecraft.core.Direction direction, boolean shade, boolean sampleOutside) Computes the AO for a full face.- Parameters:
out
- storage for the computed lightmap and brightness.sampleOutside
-true
to sample the light outside the block,false
to sample the light inside the block. In vanilla, this is equivalent tofaceCubic
.
-
blend
private static int blend(int sideLightmapA, int sideLightmapB, int cornerLightmap, int insideLightmap, boolean sideClearA, boolean sideClearB, boolean cornerClear, boolean insideClear) Computes the lightmap of the corner of an AO face, by combining the lightmap values on the two neighbor blocks, on the corner block, and inside the block.
-