Skip to content

Commit

Permalink
ambientOcclusionLevel constant support (IrisShaders#797)
Browse files Browse the repository at this point in the history
* Initial support for ambientOcclusionLevel

* Make Indigo and Indium respect ambientOcclusionLevel

* rework ambientOcclusionLevel support

* Return 1.0 if ambientOcclusionLevel is not set

* Rework code again

* Remove unneeded if check

* Use AbstractBlock.getAmbientOcclusionLightLevel

* Remove useless shadow
  • Loading branch information
IMS212 authored Sep 3, 2021
1 parent 1eecdf0 commit 7c8d8d6
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class BlockRenderingSettings {

private boolean reloadRequired;
private IdMap idMap;
private float ambientOcclusionLevel;
private boolean disableDirectionalShading;
private boolean useSeparateAo;

Expand Down Expand Up @@ -38,6 +39,19 @@ public void setIdMap(IdMap idMap) {
this.idMap = idMap;
}

public float getAmbientOcclusionLevel() {
return ambientOcclusionLevel;
}

public void setAmbientOcclusionLevel(float ambientOcclusionLevel) {
if (ambientOcclusionLevel == this.ambientOcclusionLevel) {
return;
}

this.reloadRequired = true;
this.ambientOcclusionLevel = ambientOcclusionLevel;
}

public boolean shouldDisableDirectionalShading() {
return disableDirectionalShading;
}
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/net/coderbot/iris/mixin/MixinAbstractBlockState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package net.coderbot.iris.mixin;

import net.coderbot.iris.block_rendering.BlockRenderingSettings;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(AbstractBlock.AbstractBlockState.class)
public abstract class MixinAbstractBlockState {
@Shadow
public abstract Block getBlock();

@Shadow
protected abstract BlockState asBlockState();

/**
* @author IMS
* @reason ambientOcclusionLevel support
*/
@Environment(EnvType.CLIENT)
@Deprecated
@Overwrite
public float getAmbientOcclusionLightLevel(BlockView world, BlockPos pos) {
float originalValue = this.getBlock().getAmbientOcclusionLightLevel(this.asBlockState(), world, pos);
float aoLightValue = BlockRenderingSettings.INSTANCE.getAmbientOcclusionLevel();
return 1.0F - aoLightValue * (1.0F - originalValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public DeferredWorldRenderingPipeline(ProgramSet programs) {
this.sunPathRotation = programs.getPackDirectives().getSunPathRotation();

BlockRenderingSettings.INSTANCE.setIdMap(programs.getPack().getIdMap());
BlockRenderingSettings.INSTANCE.setAmbientOcclusionLevel(programs.getPackDirectives().getAmbientOcclusionLevel());
BlockRenderingSettings.INSTANCE.setDisableDirectionalShading(shouldDisableDirectionalShading());
BlockRenderingSettings.INSTANCE.setUseSeparateAo(programs.getPackDirectives().shouldUseSeparateAo());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class FixedFunctionWorldRenderingPipeline implements WorldRenderingPipeli
public FixedFunctionWorldRenderingPipeline() {
BlockRenderingSettings.INSTANCE.setDisableDirectionalShading(shouldDisableDirectionalShading());
BlockRenderingSettings.INSTANCE.setUseSeparateAo(false);
BlockRenderingSettings.INSTANCE.setAmbientOcclusionLevel(1.0f);
}

@Override
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/net/coderbot/iris/shaderpack/PackDirectives.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
public class PackDirectives {
private int noiseTextureResolution;
private float sunPathRotation;
private float ambientOcclusionLevel;
private boolean areCloudsEnabled;
private boolean separateAo;

Expand All @@ -14,6 +15,7 @@ public class PackDirectives {
private PackDirectives(Set<Integer> supportedRenderTargets) {
noiseTextureResolution = 256;
sunPathRotation = 0.0F;
ambientOcclusionLevel = 1.0F;
renderTargetDirectives = new PackRenderTargetDirectives(supportedRenderTargets);
shadowDirectives = new PackShadowDirectives();
}
Expand All @@ -38,6 +40,10 @@ public float getSunPathRotation() {
return sunPathRotation;
}

public float getAmbientOcclusionLevel() {
return ambientOcclusionLevel;
}

public boolean areCloudsEnabled() {
return areCloudsEnabled;
}
Expand All @@ -63,5 +69,9 @@ public void acceptDirectivesFrom(DirectiveHolder directives) {

directives.acceptConstFloatDirective("sunPathRotation",
sunPathRotation -> this.sunPathRotation = sunPathRotation);

directives.acceptConstFloatDirective("ambientOcclusionLevel",
ambientOcclusionLevel -> this.ambientOcclusionLevel = ambientOcclusionLevel);

}
}
1 change: 1 addition & 0 deletions src/main/resources/mixins.iris.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"plugin": "net.coderbot.iris.mixin.shadows.IrisShadowsMixinPlugin",
"compatibilityLevel": "JAVA_8",
"client": [
"MixinAbstractBlockState",
"MixinBackgroundRenderer",
"MixinDebugHud",
"MixinEndPortalBlockEntityRenderer",
Expand Down

0 comments on commit 7c8d8d6

Please sign in to comment.