Skip to content

Commit

Permalink
Do not cache ambient brightness at initialization
Browse files Browse the repository at this point in the history
The world may not be assigned to the renderer at
initialization, which is the case for non-terrain
rendering (i.e. block entities.)

Likely, there is no performance benefit to caching
this data in the first place, so the easiest solution
is to just remove the code.
  • Loading branch information
jellysquid3 committed Dec 17, 2024
1 parent 6c75859 commit 0d4ab84
Showing 1 changed file with 2 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import net.caffeinemc.mods.sodium.client.model.light.data.QuadLightData;
import net.caffeinemc.mods.sodium.client.model.quad.ModelQuadView;
import net.caffeinemc.mods.sodium.client.model.quad.properties.ModelQuadFlags;
import net.caffeinemc.mods.sodium.client.util.DirectionUtil;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.Mth;
Expand Down Expand Up @@ -58,23 +57,12 @@ public class SmoothLightPipeline implements LightPipeline {
*/
private final float[] weights = new float[4];

// Cached per-face brightness received from the dimension's ambient lighting.
// This data is static for a given world and dimension.
private final float[] ambientBrightnessShaded = new float[6];
private final float[] ambientBrightnessUnshaded = new float[6];

public SmoothLightPipeline(LightDataAccess cache) {
this.lightCache = cache;

for (int i = 0; i < this.cachedFaceData.length; i++) {
this.cachedFaceData[i] = new AoFaceData();
}

for (Direction direction : DirectionUtil.ALL_DIRECTIONS) {
var level = cache.getLevel();
this.ambientBrightnessShaded[direction.ordinal()] = level.getShade(direction, true);
this.ambientBrightnessUnshaded[direction.ordinal()] = level.getShade(direction, false);
}
}

@Override
Expand Down Expand Up @@ -348,7 +336,8 @@ private void applyAmbientLighting(final float[] brightness, Direction face, bool
* @param shade Whether the block face is receiving directional light
*/
private float getAmbientBrightness(Direction face, boolean shade) {
return (shade ? this.ambientBrightnessShaded : this.ambientBrightnessUnshaded)[face.ordinal()];
return this.lightCache.getLevel()
.getShade(face, shade);
}

/**
Expand Down

0 comments on commit 0d4ab84

Please sign in to comment.