Skip to content

Commit

Permalink
Merge branch '1.20-new' into 1.20-new-sodium
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Aug 1, 2023
2 parents 0088fe3 + e1488e3 commit 231387c
Show file tree
Hide file tree
Showing 32 changed files with 491 additions and 74 deletions.
Binary file added .idea/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ public enum TransparencyType {
* Opaque, non transparent content.
*/
OPAQUE,
/**
* Opaque, non transparent content that must be rendered after other opaque content, but before translucents.
*/
OPAQUE_DECAL,
/**
* Generally transparent / translucent content.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class MixinLevelRenderer {
Minecraft.getInstance().getProfiler().popPush("entity_draws_opaque");
if (renderBuffers.bufferSource() instanceof FullyBufferedMultiBufferSource source) {
source.endBatchWithType(TransparencyType.OPAQUE);
source.endBatchWithType(TransparencyType.OPAQUE_DECAL);
} else {
this.renderBuffers.bufferSource().endBatch();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class MixinSheets {

@Inject(method = "<clinit>", at = @At("TAIL"))
private static void setSheet(CallbackInfo ci) {
((BlendingStateHolder) ARMOR_TRIMS_SHEET_TYPE).setTransparencyType(TransparencyType.GENERAL_TRANSPARENT);
((BlendingStateHolder) ARMOR_TRIMS_SHEET_TYPE).setTransparencyType(TransparencyType.OPAQUE_DECAL);
((BlendingStateHolder) RenderType.textBackground()).setTransparencyType(TransparencyType.OPAQUE);
((BlendingStateHolder) RenderType.textBackgroundSeeThrough()).setTransparencyType(TransparencyType.OPAQUE);
}
Expand Down
15 changes: 5 additions & 10 deletions src/main/java/net/coderbot/iris/Iris.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.coderbot.iris.shaderpack.ProgramSet;
import net.coderbot.iris.shaderpack.ShaderPack;
import net.coderbot.iris.shaderpack.discovery.ShaderpackDirectoryManager;
import net.coderbot.iris.shaderpack.materialmap.NamespacedId;
import net.coderbot.iris.shaderpack.option.OptionSet;
import net.coderbot.iris.shaderpack.option.Profile;
import net.coderbot.iris.shaderpack.option.values.MutableOptionValues;
Expand Down Expand Up @@ -642,19 +643,13 @@ private static void destroyEverything() {
}
}

public static DimensionId lastDimension = null;
public static NamespacedId lastDimension = null;

public static DimensionId getCurrentDimension() {
public static NamespacedId getCurrentDimension() {
ClientLevel level = Minecraft.getInstance().level;

if (level != null) {
if (level.dimensionType().effectsLocation().equals(BuiltinDimensionTypes.END_EFFECTS) || level.dimension().equals(net.minecraft.world.level.Level.END)) {
return DimensionId.END;
} else if (level.dimensionType().effectsLocation().equals(BuiltinDimensionTypes.NETHER_EFFECTS) || level.dimension().equals(net.minecraft.world.level.Level.NETHER)) {
return DimensionId.NETHER;
} else {
return DimensionId.OVERWORLD;
}
return new NamespacedId(level.dimension().location().getNamespace(), level.dimension().location().getPath());
} else {
// This prevents us from reloading the shaderpack unless we need to. Otherwise, if the player is in the
// nether and quits the game, we might end up reloading the shaders on exit and on entry to the level
Expand All @@ -663,7 +658,7 @@ public static DimensionId getCurrentDimension() {
}
}

private static WorldRenderingPipeline createPipeline(DimensionId dimensionId) {
private static WorldRenderingPipeline createPipeline(NamespacedId dimensionId) {
if (currentPack == null) {
// Completely disables shader-based rendering
return new FixedFunctionWorldRenderingPipeline();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.coderbot.iris.gl.state;

import java.util.function.IntSupplier;

/**
* Holds some standard update notifiers for various elements of GL state. Currently, this class has a few listeners for
* fog-related values.
Expand All @@ -12,4 +14,5 @@ public class StateUpdateNotifiers {
public static ValueUpdateNotifier normalTextureChangeNotifier;
public static ValueUpdateNotifier specularTextureChangeNotifier;
public static ValueUpdateNotifier phaseChangeNotifier;
public static ValueUpdateNotifier fallbackEntityNotifier;
}
8 changes: 8 additions & 0 deletions src/main/java/net/coderbot/iris/layer/GbufferPrograms.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class GbufferPrograms {
private static boolean blockEntities;
private static boolean outline;
private static Runnable phaseChangeListener;
private static Runnable fallbackEntityListener;

private static void checkReentrancy() {
if (entities || blockEntities || outline) {
Expand Down Expand Up @@ -96,6 +97,12 @@ public static void runPhaseChangeNotifier() {
}
}

public static void runFallbackEntityListener() {
if (fallbackEntityListener != null) {
fallbackEntityListener.run();
}
}

public static void setupSpecialRenderCondition(SpecialCondition override) {
Iris.getPipelineManager().getPipeline().ifPresent(p -> p.setSpecialCondition(override));
}
Expand All @@ -106,6 +113,7 @@ public static void teardownSpecialRenderCondition(SpecialCondition override) {

static {
StateUpdateNotifiers.phaseChangeNotifier = listener -> phaseChangeListener = listener;
StateUpdateNotifiers.fallbackEntityNotifier = listener -> fallbackEntityListener = listener;
}

public static void init() {
Expand Down
103 changes: 103 additions & 0 deletions src/main/java/net/coderbot/iris/layer/InnerWrappedRenderType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package net.coderbot.iris.layer;

import net.coderbot.batchedentityrendering.impl.BlendingStateHolder;
import net.coderbot.batchedentityrendering.impl.TransparencyType;
import net.coderbot.batchedentityrendering.impl.WrappableRenderType;
import net.coderbot.iris.mixin.rendertype.RenderTypeAccessor;
import net.minecraft.client.renderer.RenderStateShard;
import net.minecraft.client.renderer.RenderType;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;
import java.util.Optional;

public class InnerWrappedRenderType extends RenderType implements WrappableRenderType, BlendingStateHolder {
private final RenderStateShard extra;
private final RenderType wrapped;

public InnerWrappedRenderType(String name, RenderType wrapped, RenderStateShard extra) {
super(name, wrapped.format(), wrapped.mode(), wrapped.bufferSize(),
wrapped.affectsCrumbling(), shouldSortOnUpload(wrapped), wrapped::setupRenderState, wrapped::clearRenderState);

this.extra = extra;
this.wrapped = wrapped;
}

public static InnerWrappedRenderType wrapExactlyOnce(String name, RenderType wrapped, RenderStateShard extra) {
if (wrapped instanceof InnerWrappedRenderType) {
wrapped = ((InnerWrappedRenderType) wrapped).unwrap();
}

return new InnerWrappedRenderType(name, wrapped, extra);
}

@Override
public void setupRenderState() {
super.setupRenderState();

extra.setupRenderState();
}

@Override
public void clearRenderState() {
extra.clearRenderState();

super.clearRenderState();
}

@Override
public RenderType unwrap() {
return this.wrapped;
}

@Override
public Optional<RenderType> outline() {
return this.wrapped.outline();
}

@Override
public boolean isOutline() {
return this.wrapped.isOutline();
}

@Override
public boolean equals(@Nullable Object object) {
if (object == null) {
return false;
}

if (object.getClass() != this.getClass()) {
return false;
}

InnerWrappedRenderType other = (InnerWrappedRenderType) object;

return Objects.equals(this.wrapped, other.wrapped) && Objects.equals(this.extra, other.extra);
}

@Override
public int hashCode() {
// Add two so that we don't have the exact same hash as the wrapped object.
// This means that we won't have a guaranteed collision if we're inserted to a map alongside the unwrapped object.
return this.wrapped.hashCode() + 2;
}

@Override
public String toString() {
return "iris_wrapped:" + this.wrapped.toString();
}

private static boolean shouldSortOnUpload(RenderType type) {
return ((RenderTypeAccessor) type).shouldSortOnUpload();
}

@Override
public TransparencyType getTransparencyType() {
return ((BlendingStateHolder) wrapped).getTransparencyType();
}

@Override
public void setTransparencyType(TransparencyType transparencyType) {
((BlendingStateHolder) wrapped).setTransparencyType(transparencyType);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package net.coderbot.iris.layer;

import net.coderbot.iris.block_rendering.BlockRenderingSettings;
import net.coderbot.iris.shaderpack.materialmap.NamespacedId;
import net.coderbot.iris.uniforms.CapturedRenderingState;
import net.minecraft.client.renderer.RenderStateShard;

public class LightningRenderStateShard extends RenderStateShard {
public static final LightningRenderStateShard INSTANCE = new LightningRenderStateShard();
private static int backupValue = 0;

private static final NamespacedId LIGHT = new NamespacedId("minecraft", "lightning_bolt");

public LightningRenderStateShard() {
super("iris:lightning", () -> {
if (BlockRenderingSettings.INSTANCE.getEntityIds() != null) {
backupValue = CapturedRenderingState.INSTANCE.getCurrentRenderedEntity();
CapturedRenderingState.INSTANCE.setCurrentEntity(BlockRenderingSettings.INSTANCE.getEntityIds().applyAsInt(LIGHT));
GbufferPrograms.runFallbackEntityListener();
}
}, () -> {
if (BlockRenderingSettings.INSTANCE.getEntityIds() != null) {
CapturedRenderingState.INSTANCE.setCurrentEntity(backupValue);
backupValue = 0;
GbufferPrograms.runFallbackEntityListener();
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ public class MixinEntityRenderDispatcher {
"Lnet/minecraft/client/renderer/entity/EntityRenderDispatcher;renderBlockShadow(Lcom/mojang/blaze3d/vertex/PoseStack$Pose;Lcom/mojang/blaze3d/vertex/VertexConsumer;Lnet/minecraft/world/level/chunk/ChunkAccess;Lnet/minecraft/world/level/LevelReader;Lnet/minecraft/core/BlockPos;DDDFF)V";

@Unique
private static final NamespacedId id = new NamespacedId("minecraft", "entity_shadow");
private static final NamespacedId shadowId = new NamespacedId("minecraft", "entity_shadow");

@Unique
private static final NamespacedId flameId = new NamespacedId("minecraft", "entity_flame");

@Unique
private static int cachedId;
Expand All @@ -46,7 +49,7 @@ public class MixinEntityRenderDispatcher {
}

cachedId = CapturedRenderingState.INSTANCE.getCurrentRenderedEntity();
CapturedRenderingState.INSTANCE.setCurrentEntity(entityIds.getInt(id));
CapturedRenderingState.INSTANCE.setCurrentEntity(entityIds.getInt(shadowId));
}
}

Expand All @@ -56,6 +59,24 @@ private static void restoreShadow(PoseStack pPoseStack0, MultiBufferSource pMult
cachedId = 0;
}

@Inject(method = "renderFlame", at = @At("HEAD"))
private void iris$setFlameId(PoseStack pEntityRenderDispatcher0, MultiBufferSource pMultiBufferSource1, Entity pEntity2, CallbackInfo ci) {
Object2IntFunction<NamespacedId> entityIds = BlockRenderingSettings.INSTANCE.getEntityIds();

if (entityIds == null) {
return;
}

cachedId = CapturedRenderingState.INSTANCE.getCurrentRenderedEntity();
CapturedRenderingState.INSTANCE.setCurrentEntity(entityIds.getInt(flameId));
}

@Inject(method = "renderFlame", at = @At("RETURN"))
private void restoreFlameId(PoseStack pEntityRenderDispatcher0, MultiBufferSource pMultiBufferSource1, Entity pEntity2, CallbackInfo ci) {
CapturedRenderingState.INSTANCE.setCurrentEntity(cachedId);
cachedId = 0;
}

// The underlying method called by renderShadow.
@Inject(method = "renderBlockShadow", at = @At("HEAD"), cancellable = true)
private static void renderBlockShadow(PoseStack.Pose pPoseStack$Pose0, VertexConsumer pVertexConsumer1, ChunkAccess pChunkAccess2, LevelReader pLevelReader3, BlockPos pBlockPos4, double pDouble5, double pDouble6, double pDouble7, float pFloat8, float pFloat9, CallbackInfo ci) {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/coderbot/iris/mixin/MixinGameRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,10 @@ public class MixinGameRenderer {
}

@Inject(method = {
"getRendertypeEnergySwirlShader"
}, at = @At("HEAD"), cancellable = true)
private static void iris$overrideEnergySwirlShader(CallbackInfoReturnable<ShaderInstance> cir) {
"getRendertypeEnergySwirlShader",
"getRendertypeEntityShadowShader"
}, at = @At("HEAD"), cancellable = true)
private static void iris$overrideEnergySwirlShadowShader(CallbackInfoReturnable<ShaderInstance> cir) {
if (ShadowRenderer.ACTIVE) {
// TODO: Wrong program
override(ShaderKey.SHADOW_ENTITIES_CUTOUT, cir);
Expand Down Expand Up @@ -264,8 +265,7 @@ public class MixinGameRenderer {
}

@Inject(method = {
"getRendertypeWaterMaskShader",
"getRendertypeEntityShadowShader"
"getRendertypeWaterMaskShader"
}, at = @At("HEAD"), cancellable = true)
private static void iris$overrideEntitySolidShader(CallbackInfoReturnable<ShaderInstance> cir) {
if (ShadowRenderer.ACTIVE) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package net.coderbot.iris.mixin;

import com.mojang.blaze3d.vertex.VertexConsumer;
import net.coderbot.iris.pipeline.LightningHandler;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.LightningBoltRenderer;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.resources.ResourceLocation;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(LightningBoltRenderer.class)
public class MixinLightningBoltRenderer {
@Redirect(method = "render(Lnet/minecraft/world/entity/LightningBolt;FFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/RenderType;lightning()Lnet/minecraft/client/renderer/RenderType;"))
private RenderType iris$overrideTex() {
return LightningHandler.IRIS_LIGHTNING;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ private void fillExtendedData(int vertexAmount) {
midV /= vertexAmount;

if (vertexAmount == 3) {
NormalHelper.computeFaceNormalTri(normal, polygon);
// Removed to enable smooth shaded triangles. Mods rendering triangles with bad normals need to recalculate their normals manually or otherwise shading might be inconsistent.
// NormalHelper.computeFaceNormalTri(normal, polygon);
} else {
NormalHelper.computeFaceNormal(normal, polygon);
}
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/net/coderbot/iris/pipeline/LightningHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package net.coderbot.iris.pipeline;

import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.VertexFormat;
import net.coderbot.iris.layer.InnerWrappedRenderType;
import net.coderbot.iris.layer.LightningRenderStateShard;
import net.coderbot.iris.layer.OuterWrappedRenderType;
import net.minecraft.client.renderer.RenderType;

public class LightningHandler extends RenderType {
public static final RenderType IRIS_LIGHTNING = new InnerWrappedRenderType("iris_lightning2", RenderType.create(
"iris_lightning",
DefaultVertexFormat.POSITION_COLOR,
VertexFormat.Mode.QUADS,
256,
false,
true,
RenderType.CompositeState.builder()
.setShaderState(RENDERTYPE_LIGHTNING_SHADER)
.setWriteMaskState(COLOR_DEPTH_WRITE)
.setTransparencyState(LIGHTNING_TRANSPARENCY)
.setOutputState(WEATHER_TARGET)
.createCompositeState(false)
), new LightningRenderStateShard());

public LightningHandler(String pRenderType0, VertexFormat pVertexFormat1, VertexFormat.Mode pVertexFormat$Mode2, int pInt3, boolean pBoolean4, boolean pBoolean5, Runnable pRunnable6, Runnable pRunnable7) {
super(pRenderType0, pVertexFormat1, pVertexFormat$Mode2, pInt3, pBoolean4, pBoolean5, pRunnable6, pRunnable7);
}
}
Loading

0 comments on commit 231387c

Please sign in to comment.