Skip to content

Commit

Permalink
Add check for NeoForge per-quad AO flag
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Sep 23, 2024
1 parent 3fd78d9 commit 313f21f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ public interface BakedQuadView extends ModelQuadView {
int getFaceNormal();

boolean hasShade();

boolean hasAO();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package net.caffeinemc.mods.sodium.client.render.frapi.material;

import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial;
import net.fabricmc.fabric.api.util.TriState;

public class RenderMaterialImpl extends MaterialViewImpl implements RenderMaterial {
public static final int VALUE_COUNT = 1 << TOTAL_BIT_LENGTH;
Expand Down Expand Up @@ -49,4 +50,12 @@ public static RenderMaterialImpl setDisableDiffuse(RenderMaterialImpl material,

return material;
}

public static RenderMaterialImpl setAmbientOcclusion(RenderMaterialImpl material, TriState mode) {
if (material.ambientOcclusion() != mode) {
return byIndex((material.bits & ~AO_MASK) | (mode.ordinal() << AO_BIT_OFFSET));
}

return material;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter;
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadView;
import net.fabricmc.fabric.api.renderer.v1.model.SpriteFinder;
import net.fabricmc.fabric.api.util.TriState;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.core.Direction;
Expand Down Expand Up @@ -242,6 +243,10 @@ public final MutableQuadViewImpl fromVanilla(BakedQuad quad, RenderMaterial mate
material = RenderMaterialImpl.setDisableDiffuse((RenderMaterialImpl) material, true);
}

if (material.ambientOcclusion().orElse(true) && !((BakedQuadView) quad).hasAO()) {
material = RenderMaterialImpl.setAmbientOcclusion((RenderMaterialImpl) material, TriState.FALSE);
}

material(material);
tag(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,9 @@ public Direction getLightFace() {
public boolean hasShade() {
return this.shade;
}

@Override
public boolean hasAO() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(BakedQuad.class)
public class BakedQuadMixin implements BakedQuadView {
public abstract class BakedQuadMixin implements BakedQuadView {
@Shadow
@Final
protected int[] vertices;
Expand All @@ -37,6 +37,9 @@ public class BakedQuadMixin implements BakedQuadView {
@Final
private boolean shade;

@Shadow
public abstract boolean hasAmbientOcclusion();

@Unique
private int flags;

Expand Down Expand Up @@ -131,4 +134,9 @@ public Direction getLightFace() {
public boolean hasShade() {
return this.shade;
}

@Override
public boolean hasAO() {
return this.hasAmbientOcclusion();
}
}

0 comments on commit 313f21f

Please sign in to comment.