Skip to content

Commit

Permalink
Allow shader packs to disable clouds
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbot16 committed Jun 8, 2021
1 parent b1c6868 commit 07601ea
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 12 deletions.
7 changes: 7 additions & 0 deletions src/main/java/net/coderbot/iris/mixin/MixinWorldRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ public class MixinWorldRenderer {
pipeline.pushProgram(GbufferProgram.CLOUDS);
}

@Inject(method = "renderClouds", at = @At("HEAD"), cancellable = true)
private void iris$maybeRemoveClouds(MatrixStack matrices, float tickDelta, double cameraX, double cameraY, double cameraZ, CallbackInfo ci) {
if (!pipeline.shouldRenderClouds()) {
ci.cancel();
}
}

@Inject(method = RENDER, at = @At(value = "INVOKE", target = RENDER_CLOUDS, shift = At.Shift.AFTER))
private void iris$endClouds(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f matrix4f, CallbackInfo callback) {
pipeline.popProgram(GbufferProgram.CLOUDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline {

private final int waterId;
private final float sunPathRotation;
private final boolean shouldRenderClouds;

private static final List<GbufferProgram> programStack = new ArrayList<>();
private static final List<String> programStackLog = new ArrayList<>();
Expand All @@ -115,6 +116,7 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline {
public DeferredWorldRenderingPipeline(ProgramSet programs) {
Objects.requireNonNull(programs);

this.shouldRenderClouds = programs.getPackDirectives().areCloudsEnabled();
this.updateNotifier = new FrameUpdateNotifier();

this.renderTargets = new RenderTargets(MinecraftClient.getInstance().getFramebuffer(), programs.getPackDirectives().getRenderTargetDirectives());
Expand Down Expand Up @@ -364,6 +366,11 @@ public boolean shouldDisableDirectionalShading() {
return true;
}

@Override
public boolean shouldRenderClouds() {
return shouldRenderClouds;
}

@Override
public float getSunPathRotation() {
return sunPathRotation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import net.coderbot.iris.layer.GbufferProgram;
import net.coderbot.iris.mixin.WorldRendererAccessor;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.Camera;

import java.util.List;

public class FixedFunctionWorldRenderingPipeline implements WorldRenderingPipeline {
@Override
Expand All @@ -13,6 +16,16 @@ public void beginWorldRendering() {
GlStateManager.useProgram(0);
}

@Override
public void renderShadows(WorldRendererAccessor worldRenderer, Camera camera) {
// stub: nothing to do here
}

@Override
public void addDebugText(List<String> messages) {
// stub: nothing to do here
}

@Override
public void beginShadowRender() {
// stub: nothing to do here
Expand Down Expand Up @@ -52,4 +65,16 @@ public boolean shouldDisableVanillaEntityShadows() {
public boolean shouldDisableDirectionalShading() {
return false;
}

@Override
public boolean shouldRenderClouds() {
// Keep clouds enabled
return true;
}

@Override
public float getSunPathRotation() {
// No sun tilt
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@

public interface WorldRenderingPipeline {
void beginWorldRendering();
default void renderShadows(WorldRendererAccessor worldRenderer, Camera camera) {
}
default void addDebugText(List<String> messages) {
}
void renderShadows(WorldRendererAccessor worldRenderer, Camera camera);
void addDebugText(List<String> messages);
void beginShadowRender();
void endShadowRender();
void beginTranslucents();
Expand All @@ -21,8 +19,7 @@ default void addDebugText(List<String> messages) {

boolean shouldDisableVanillaEntityShadows();
boolean shouldDisableDirectionalShading();
boolean shouldRenderClouds();

default float getSunPathRotation() {
return 0.0F;
}
float getSunPathRotation();
}
18 changes: 16 additions & 2 deletions src/main/java/net/coderbot/iris/shaderpack/PackDirectives.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,28 @@
public class PackDirectives {
private int noiseTextureResolution;
private float sunPathRotation;
private boolean areCloudsEnabled;

private final PackRenderTargetDirectives renderTargetDirectives;
private final PackShadowDirectives shadowDirectives;

PackDirectives(Set<Integer> supportedRenderTargets) {
private PackDirectives(Set<Integer> supportedRenderTargets) {
noiseTextureResolution = 256;
sunPathRotation = 0.0F;

renderTargetDirectives = new PackRenderTargetDirectives(supportedRenderTargets);
shadowDirectives = new PackShadowDirectives();
}

PackDirectives(Set<Integer> supportedRenderTargets, ShaderProperties properties) {
this(supportedRenderTargets);
areCloudsEnabled = properties.areCloudsEnabled();
}

PackDirectives(Set<Integer> supportedRenderTargets, PackDirectives directives) {
this(supportedRenderTargets);
areCloudsEnabled = directives.areCloudsEnabled();
}

public int getNoiseTextureResolution() {
return noiseTextureResolution;
}
Expand All @@ -25,6 +35,10 @@ public float getSunPathRotation() {
return sunPathRotation;
}

public boolean areCloudsEnabled() {
return areCloudsEnabled;
}

public PackRenderTargetDirectives getRenderTargetDirectives() {
return renderTargetDirectives;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/coderbot/iris/shaderpack/ProgramSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class ProgramSet {

public ProgramSet(Path root, Path inclusionRoot, ShaderProperties shaderProperties, ShaderPack pack) throws IOException {
// TODO: Support additional render targets beyond 8
this.packDirectives = new PackDirectives(PackRenderTargetDirectives.BASELINE_SUPPORTED_RENDER_TARGETS);
this.packDirectives = new PackDirectives(PackRenderTargetDirectives.BASELINE_SUPPORTED_RENDER_TARGETS, shaderProperties);
this.pack = pack;

this.shadow = readProgramSource(root, inclusionRoot, "shadow", this, shaderProperties);
Expand Down Expand Up @@ -106,7 +106,7 @@ private ProgramSet(ProgramSet base, ProgramSet overrides) {
}

// TODO: Support additional render targets beyond 8
this.packDirectives = new PackDirectives(PackRenderTargetDirectives.BASELINE_SUPPORTED_RENDER_TARGETS);
this.packDirectives = new PackDirectives(PackRenderTargetDirectives.BASELINE_SUPPORTED_RENDER_TARGETS, getPackDirectives());

this.shadow = merge(base.shadow, overrides.shadow);

Expand Down
11 changes: 10 additions & 1 deletion src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import net.coderbot.iris.gl.blending.AlphaTestOverride;

public class ShaderProperties {
// TODO: clouds
private boolean enableClouds = true;
private OptionalBoolean oldHandLight;
private OptionalBoolean dynamicHandLight;
private OptionalBoolean oldLighting;
Expand Down Expand Up @@ -67,6 +67,11 @@ public ShaderProperties(Properties properties) {
noiseTexturePath = value;
}

if ("clouds".equals(key) && value.equals("off")) {
// TODO: Force clouds to fast / fancy as well if the shaderpack wants it
enableClouds = false;
}

handleBooleanDirective(key, value, "oldHandLight", bool -> oldHandLight = bool);
handleBooleanDirective(key, value, "dynamicHandLight", bool -> dynamicHandLight = bool);
handleBooleanDirective(key, value, "oldLighting", bool -> oldLighting = bool);
Expand Down Expand Up @@ -184,6 +189,10 @@ public static ShaderProperties empty() {
return new ShaderProperties();
}

public boolean areCloudsEnabled() {
return enableClouds;
}

public OptionalBoolean getOldHandLight() {
return oldHandLight;
}
Expand Down

0 comments on commit 07601ea

Please sign in to comment.