Skip to content

Commit

Permalink
Add ability to skip all rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Jun 2, 2024
1 parent f581eaf commit 811d85f
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package net.irisshaders.iris.mixin;

import com.llamalad7.mixinextras.injector.WrapWithCondition;
import com.mojang.blaze3d.vertex.PoseStack;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.pipeline.IrisRenderingPipeline;
import net.minecraft.client.Camera;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.chunk.SectionRenderDispatcher;
import net.minecraft.client.renderer.culling.Frustum;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.block.entity.BlockEntity;
import org.joml.Matrix4f;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import java.util.Collections;
import java.util.Set;

@Mixin(LevelRenderer.class)
public class MixinLevelRenderer_SkipRendering {
@Shadow
@Final
private ObjectArrayList<SectionRenderDispatcher.RenderSection> visibleSections;
@Shadow
@Final
private Set<BlockEntity> globalBlockEntities;
@Unique
private static final ObjectArrayList<SectionRenderDispatcher.RenderSection> EMPTY_LIST = new ObjectArrayList<>();

@WrapWithCondition(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;setupRender(Lnet/minecraft/client/Camera;Lnet/minecraft/client/renderer/culling/Frustum;ZZ)V"))
private boolean skipSetupRender(LevelRenderer instance, Camera camera, Frustum frustum, boolean bl, boolean bl2) {
if (Iris.getPipelineManager().getPipelineNullable() instanceof IrisRenderingPipeline pipeline) {
return !pipeline.skipAllRendering();
} else {
return true;
}
}

@WrapWithCondition(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;renderSectionLayer(Lnet/minecraft/client/renderer/RenderType;Lcom/mojang/blaze3d/vertex/PoseStack;DDDLorg/joml/Matrix4f;)V"))
private boolean skipRenderChunks(LevelRenderer instance, RenderType renderType, PoseStack poseStack, double d, double e, double f, Matrix4f matrix4f) {
if (Iris.getPipelineManager().getPipelineNullable() instanceof IrisRenderingPipeline pipeline) {
return !pipeline.skipAllRendering();
} else {
return true;
}
}

@Redirect(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/ClientLevel;entitiesForRendering()Ljava/lang/Iterable;"))
private Iterable<Entity> skipRenderEntities(ClientLevel instance) {
if (Iris.getPipelineManager().getPipelineNullable() instanceof IrisRenderingPipeline pipeline && pipeline.skipAllRendering()) {
return Collections.emptyList();
} else {
return instance.entitiesForRendering();
}
}

@Redirect(method = "renderLevel", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/LevelRenderer;visibleSections:Lit/unimi/dsi/fastutil/objects/ObjectArrayList;"))
private ObjectArrayList<SectionRenderDispatcher.RenderSection> skipLocalBlockEntities(LevelRenderer instance) {
if (Iris.getPipelineManager().getPipelineNullable() instanceof IrisRenderingPipeline pipeline && pipeline.skipAllRendering()) {
return EMPTY_LIST;
} else {
return this.visibleSections;
}
}

@Redirect(method = "renderLevel", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/LevelRenderer;globalBlockEntities:Ljava/util/Set;"))
private Set<BlockEntity> skipGlobalBlockEntities(LevelRenderer instance) {
if (Iris.getPipelineManager().getPipelineNullable() instanceof IrisRenderingPipeline pipeline && pipeline.skipAllRendering()) {
return Collections.emptySet();
} else {
return this.globalBlockEntities;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public class IrisRenderingPipeline implements WorldRenderingPipeline, ShaderRend
private final PackShadowDirectives shadowDirectives;
private final DHCompat dhCompat;
private final int stackSize = 0;
private final boolean skipAllRendering;
private boolean initializedBlockIds;
public boolean isBeforeTranslucent;
private ShaderStorageBufferHolder shaderStorageBufferHolder;
Expand Down Expand Up @@ -199,6 +200,7 @@ public IrisRenderingPipeline(ProgramSet programSet) {
this.shouldRenderSun = programSet.getPackDirectives().shouldRenderSun();
this.shouldRenderMoon = programSet.getPackDirectives().shouldRenderMoon();
this.allowConcurrentCompute = programSet.getPackDirectives().getConcurrentCompute();
this.skipAllRendering = programSet.getPackDirectives().skipAllRendering();
this.frustumCulling = programSet.getPackDirectives().shouldUseFrustumCulling();
this.occlusionCulling = programSet.getPackDirectives().shouldUseOcclusionCulling();
this.resolver = new ProgramFallbackResolver(programSet);
Expand Down Expand Up @@ -1303,4 +1305,8 @@ public GlFramebuffer createDHFramebufferShadow(ProgramSource sources) {
public boolean hasShadowRenderTargets() {
return shadowRenderTargets != null;
}

public boolean skipAllRendering() {
return skipAllRendering;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class PackDirectives {
private boolean separateAo;
private boolean voxelizeLightBlocks;
private boolean separateEntityDraws;
private boolean skipAllRendering;
private boolean frustumCulling;
private boolean occlusionCulling;
private boolean oldLighting;
Expand Down Expand Up @@ -75,6 +76,7 @@ public PackDirectives(Set<Integer> supportedRenderTargets, ShaderProperties prop
separateAo = properties.getSeparateAo().orElse(false);
voxelizeLightBlocks = properties.getVoxelizeLightBlocks().orElse(false);
separateEntityDraws = properties.getSeparateEntityDraws().orElse(false);
skipAllRendering = properties.skipAllRendering().orElse(false);
frustumCulling = properties.getFrustumCulling().orElse(true);
occlusionCulling = properties.getOcclusionCulling().orElse(true);
oldLighting = properties.getOldLighting().orElse(false);
Expand Down Expand Up @@ -202,6 +204,10 @@ public boolean isPrepareBeforeShadow() {
return prepareBeforeShadow;
}

public boolean skipAllRendering() {
return skipAllRendering;
}

public Object2ObjectMap<Tri<String, TextureType, TextureStage>, String> getTextureMap() {
return textureMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public class ShaderProperties {
private OptionalBoolean separateAo = OptionalBoolean.DEFAULT;
private OptionalBoolean voxelizeLightBlocks = OptionalBoolean.DEFAULT;
private OptionalBoolean separateEntityDraws = OptionalBoolean.DEFAULT;
private OptionalBoolean skipAllRendering = OptionalBoolean.DEFAULT;
private OptionalBoolean frustumCulling = OptionalBoolean.DEFAULT;
private OptionalBoolean occlusionCulling = OptionalBoolean.DEFAULT;
private ShadowCullState shadowCulling = ShadowCullState.DEFAULT;
Expand Down Expand Up @@ -199,6 +200,7 @@ public ShaderProperties(String contents, ShaderPackOptions shaderPackOptions, It
handleBooleanDirective(key, value, "frustum.culling", bool -> frustumCulling = bool);
handleBooleanDirective(key, value, "occlusion.culling", bool -> occlusionCulling = bool);
handleBooleanDirective(key, value, "shadow.enabled", bool -> shadowEnabled = bool);
handleBooleanDirective(key, value, "skipAllRendering", bool -> skipAllRendering = bool);
handleBooleanDirective(key, value, "dhShadow.enabled", bool -> dhShadowEnabled = bool);
handleBooleanDirective(key, value, "particles.before.deferred", bool -> {
if (bool.orElse(false) && particleRenderingSettings.isEmpty()) {
Expand Down Expand Up @@ -806,6 +808,10 @@ public OptionalBoolean getSeparateEntityDraws() {
return separateEntityDraws;
}

public OptionalBoolean skipAllRendering() {
return skipAllRendering;
}

public OptionalBoolean getFrustumCulling() {
return frustumCulling;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/mixins.iris.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"MixinItemBlockRenderTypes",
"MixinItemInHandRenderer",
"MixinLevelRenderer",
"MixinLevelRenderer_SkipRendering",
"MixinLightningBoltRenderer",
"MixinLightTexture",
"MixinLocalPlayer",
Expand Down

0 comments on commit 811d85f

Please sign in to comment.