Class EnhancedAoRenderStorage
java.lang.Object
net.minecraft.client.renderer.block.ModelBlockRenderer.CommonRenderStorage
net.minecraft.client.renderer.block.ModelBlockRenderer.AmbientOcclusionRenderStorage
net.neoforged.neoforge.client.model.ao.EnhancedAoRenderStorage
public class EnhancedAoRenderStorage
extends net.minecraft.client.renderer.block.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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final record
Cache these objects so that they don't need to be reallocated for everyEnhancedAoRenderStorage
. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final float
private static final ThreadLocal
<EnhancedAoRenderStorage.AoObjectCache> private static final float
private final FullFaceCalculator
Calculator for full faces.private static final boolean
Debug option to compare the emulated vanilla AO with the actual vanilla AO.private net.minecraft.client.renderer.block.model.BakedQuad
private static final org.slf4j.Logger
private static final float
private final float[]
Fields inherited from class net.minecraft.client.renderer.block.ModelBlockRenderer.AmbientOcclusionRenderStorage
faceShape
Fields inherited from class net.minecraft.client.renderer.block.ModelBlockRenderer.CommonRenderStorage
brightness, cache, faceCubic, facePartial, lightmap, scratchPos, tintCacheIndex, tintCacheValue
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
applyFlatQuadBrightness
(net.minecraft.world.level.BlockAndTintGetter level, net.minecraft.client.renderer.block.model.BakedQuad quad, net.minecraft.client.renderer.block.ModelBlockRenderer.CommonRenderStorage storage) "Enhanced" flat shading logic.void
calculate
(net.minecraft.world.level.BlockAndTintGetter level, net.minecraft.world.level.block.state.BlockState state, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction direction, boolean shade) private void
calculateAxisAligned
(net.minecraft.world.level.BlockAndTintGetter level, net.minecraft.world.level.block.state.BlockState state, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction direction, boolean shade) Computes AO for an axis-aligned quad.private void
calculateIrregular
(net.minecraft.world.level.BlockAndTintGetter level, net.minecraft.world.level.block.state.BlockState state, net.minecraft.core.BlockPos pos, boolean shade) Computes AO for a general quad.void
captureQuad
(net.minecraft.client.renderer.block.model.BakedQuad quad) private static float
interpolateBrightness
(AoCalculatedFace in, float[] weights) Interpolates brightness from the 4 corners of a face.private static int
interpolateLightmap
(AoCalculatedFace in, float[] weights) Interpolates lightmap from the 4 corners of a face.private static int
lerpLightmap
(int lightmap1, float w1, int lightmap2, float w2) Interpolates two lightmaps linearly.(package private) static int
maxLightmap
(int lightmap1, int lightmap2) static net.minecraft.client.renderer.block.ModelBlockRenderer.AmbientOcclusionRenderStorage
private static float
normalComponent
(int normal, int axis) Unpacks a normal component.private static float
vertexPos
(int[] vertices, int vertex, int axis) Extracts the position of a vertex from quad data.Methods inherited from class net.minecraft.client.renderer.block.ModelBlockRenderer.AmbientOcclusionRenderStorage
blend
-
Field Details
-
COMPARE_WITH_VANILLA
private static final boolean COMPARE_WITH_VANILLADebug 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
-
calculator
Calculator for full faces. -
weights
private final float[] weights -
currentQuad
private net.minecraft.client.renderer.block.model.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
public static net.minecraft.client.renderer.block.ModelBlockRenderer.AmbientOcclusionRenderStorage newInstance() -
applyFlatQuadBrightness
public static void applyFlatQuadBrightness(net.minecraft.world.level.BlockAndTintGetter level, net.minecraft.client.renderer.block.model.BakedQuad quad, net.minecraft.client.renderer.block.ModelBlockRenderer.CommonRenderStorage storage) "Enhanced" flat shading logic. -
captureQuad
public void captureQuad(net.minecraft.client.renderer.block.model.BakedQuad quad) - Overrides:
captureQuad
in classnet.minecraft.client.renderer.block.ModelBlockRenderer.AmbientOcclusionRenderStorage
-
calculate
public void calculate(net.minecraft.world.level.BlockAndTintGetter level, net.minecraft.world.level.block.state.BlockState state, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction direction, boolean shade) - Overrides:
calculate
in classnet.minecraft.client.renderer.block.ModelBlockRenderer.AmbientOcclusionRenderStorage
-
calculateAxisAligned
private void calculateAxisAligned(net.minecraft.world.level.BlockAndTintGetter level, net.minecraft.world.level.block.state.BlockState state, net.minecraft.core.BlockPos pos, net.minecraft.core.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(net.minecraft.world.level.BlockAndTintGetter level, net.minecraft.world.level.block.state.BlockState state, net.minecraft.core.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 datavertex
- vertex index, from 0 to 3 includedaxis
- axis index, for 0 to 2 included
-
normalComponent
private static float normalComponent(int normal, int axis) Unpacks a normal component. -
interpolateBrightness
Interpolates brightness from the 4 corners of a face. -
interpolateLightmap
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)
-