Skip to content

Commit

Permalink
Capture entity rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Luna0x01 committed Jan 7, 2025
1 parent ac60810 commit c2ad381
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 77 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package net.coderbot.iris.mixin;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
import net.coderbot.iris.Iris;
import net.coderbot.iris.layer.GbufferPrograms;
import net.coderbot.iris.pipeline.WorldRenderingPhase;
import net.coderbot.iris.pipeline.WorldRenderingPipeline;
import net.coderbot.iris.uniforms.CapturedRenderingState;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.entity.Entity;
import org.lwjgl.opengl.GL11;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
Expand Down Expand Up @@ -57,4 +63,17 @@ public class MixinLevelRenderer {
private void iris$renderSky$tiltSun(float tickDelta, int anaglyphFilter, CallbackInfo ci) {
GL11.glRotatef(pipeline.getSunPathRotation(), 0.0F, 0.0F, 1.0F);
}

@WrapOperation(method = "renderEntities", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/EntityRenderDispatcher;renderEntity(Lnet/minecraft/entity/Entity;F)Z"))
private boolean iris$renderEntities$capture(EntityRenderDispatcher instance, Entity entity, float f, Operation<Boolean> original) {
CapturedRenderingState.INSTANCE.setCurrentEntity(entity.getEntityId());
GbufferPrograms.beginEntities();
try {
return original.call(instance, entity, f);
} finally {
CapturedRenderingState.INSTANCE.setCurrentEntity(-1);
GbufferPrograms.endEntities();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,63 +9,40 @@

import java.util.Objects;

public class LabPBRTextureFormat implements TextureFormat {
public static final ChannelMipmapGenerator SPECULAR_MIPMAP_GENERATOR = new ChannelMipmapGenerator(
LinearBlendFunction.INSTANCE,
new DiscreteBlendFunction(v -> v < 230 ? 0 : v - 229),
new DiscreteBlendFunction(v -> v < 65 ? 0 : 1),
new DiscreteBlendFunction(v -> v < 255 ? 0 : 1)
);

private final String name;
@Nullable
private final String version;

public LabPBRTextureFormat(String name, @Nullable String version) {
this.name = name;
this.version = version;
}

@Override
public String getName() {
return name;
}

@Override
public @Nullable String getVersion() {
return version;
}

@Override
public boolean canInterpolateValues(PBRType pbrType) {
if (pbrType == PBRType.SPECULAR) {
return false;
}
return true;
}

@Override
public @Nullable CustomMipmapGenerator getMipmapGenerator(PBRType pbrType) {
if (pbrType == PBRType.SPECULAR) {
return SPECULAR_MIPMAP_GENERATOR;
}
return null;
}

@Override
public int hashCode() {
return Objects.hash(name, version);
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
LabPBRTextureFormat other = (LabPBRTextureFormat) obj;
return Objects.equals(name, other.name) && Objects.equals(version, other.version);
}
public record LabPBRTextureFormat(String name, @Nullable String version) implements TextureFormat {
public static final ChannelMipmapGenerator SPECULAR_MIPMAP_GENERATOR = new ChannelMipmapGenerator(
LinearBlendFunction.INSTANCE,
new DiscreteBlendFunction(v -> v < 230 ? 0 : v - 229),
new DiscreteBlendFunction(v -> v < 65 ? 0 : 1),
new DiscreteBlendFunction(v -> v < 255 ? 0 : 1)
);


@Override
public boolean canInterpolateValues(PBRType pbrType) {
if (pbrType == PBRType.SPECULAR) {
return false;
}
return true;
}

@Override
public @Nullable CustomMipmapGenerator getMipmapGenerator(PBRType pbrType) {
if (pbrType == PBRType.SPECULAR) {
return SPECULAR_MIPMAP_GENERATOR;
}
return null;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
LabPBRTextureFormat other = (LabPBRTextureFormat) obj;
return Objects.equals(name, other.name) && Objects.equals(version, other.version);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
import java.util.Locale;

public interface TextureFormat {
String getName();
String name();

@Nullable
String getVersion();
String version();

default List<String> getDefines() {
List<String> defines = new ArrayList<>();

String defineName = getName().toUpperCase(Locale.ROOT).replaceAll("-", "_");
String defineName = name().toUpperCase(Locale.ROOT).replaceAll("-", "_");
String define = "MC_TEXTURE_FORMAT_" + defineName;
defines.add(define);

String version = getVersion();
String version = version();
if (version != null) {
String defineVersion = version.replaceAll("[.-]", "_");
String versionDefine = define + "_" + defineVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,13 @@ public static void addWorldTimeUniforms(UniformHolder uniforms) {
}

static int getWorldDayTime() {
long timeOfDay = getWorld().getTimeOfDay();

if (Iris.getCurrentDimension() == DimensionId.END || Iris.getCurrentDimension() == DimensionId.NETHER) {
// If the dimension is the nether or the end, don't override the fixed time.
// This was an oversight in versions before and including 1.2.5 causing inconsistencies, such as Complementary's ender beams not moving.
return (int) (timeOfDay % 24000L);
}

long dayTime = timeOfDay % 24000L;

return (int) dayTime;
return (int) (getWorld().getTimeOfDay() % 24000L);
}

private static int getWorldDay() {
long timeOfDay = getWorld().getTimeOfDay();
long day = timeOfDay / 24000L;
long time = getWorld().getLevelProperties().getTime();

return (int) day;
return (int) (time / 24000L);
}

private static ClientWorld getWorld() {
Expand Down

0 comments on commit c2ad381

Please sign in to comment.