Skip to content

Commit

Permalink
Merge branch '1.19.4' into 1.20.1
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Nov 9, 2023
2 parents 5e14fde + e5e8fe9 commit a913a89
Show file tree
Hide file tree
Showing 15 changed files with 153 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/main/java/kroppeb/stareval/function/Type.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public static UniformType convert(Type type) {
else if (type == VectorType.VEC3) return UniformType.VEC3;
else if (type == VectorType.VEC4) return UniformType.VEC4;
else if (type == VectorType.I_VEC2) return UniformType.VEC2I;
else if (type == VectorType.I_VEC3) return UniformType.VEC3I;
else if (type == MatrixType.MAT4) return UniformType.MAT4;
else throw new IllegalArgumentException("Unsupported custom uniform type: " + type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public int getUsedSize() {

@Override
public void freeAndDeleteBuffer() {
MemoryUtil.memFree(buffer);
if (buffer == null) return;
MemoryUtil.getAllocator(false).free(MemoryUtil.memAddress(buffer));
buffer = null;
}
}
5 changes: 5 additions & 0 deletions src/main/java/net/coderbot/iris/gl/IrisRenderSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ public static void uniform3f(int location, float v0, float v1, float v2) {
GL32C.glUniform3f(location, v0, v1, v2);
}

public static void uniform3i(int location, int v0, int v1, int v2) {
RenderSystem.assertOnRenderThreadOrInit();
GL32C.glUniform3i(location, v0, v1, v2);
}

public static void uniform4f(int location, float v0, float v1, float v2, float v3) {
RenderSystem.assertOnRenderThreadOrInit();
GL32C.glUniform4f(location, v0, v1, v2, v3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ private static UniformType getExpectedType(int type) {
} else if (type == GL20C.GL_FLOAT_VEC3) {
return UniformType.VEC3;
} else if (type == GL20C.GL_INT_VEC3) {
return null;
return UniformType.VEC3I;
} else if (type == GL20C.GL_FLOAT_MAT2) {
return null;
} else if (type == GL20C.GL_FLOAT_VEC2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
import org.joml.Vector3d;
import org.joml.Vector3f;
import org.joml.Vector4f;
import org.joml.Matrix4f;
import org.joml.Vector2f;
import org.joml.Vector2i;
import org.joml.Vector3d;
import org.joml.Vector3f;
import org.joml.Vector4f;
import org.joml.Vector3i;

import java.util.OptionalInt;
import java.util.function.BooleanSupplier;
Expand Down Expand Up @@ -80,6 +75,13 @@ default LocationalUniformHolder uniform3f(UniformUpdateFrequency updateFrequency
return this;
}

@Override
default LocationalUniformHolder uniform3i(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector3i> value) {
location(name, UniformType.VEC3I).ifPresent(id -> addUniform(updateFrequency, new Vector3IntegerUniform(id, value)));

return this;
}

@Override
default LocationalUniformHolder uniformTruncated3f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector4f> value) {
location(name, UniformType.VEC3).ifPresent(id -> addUniform(updateFrequency, Vector3Uniform.truncated(id, value)));
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/coderbot/iris/gl/uniform/UniformHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.joml.Vector2i;
import org.joml.Vector3d;
import org.joml.Vector3f;
import org.joml.Vector3i;
import org.joml.Vector4f;

import java.util.function.BooleanSupplier;
Expand All @@ -28,6 +29,7 @@ public interface UniformHolder {
UniformHolder uniform2i(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector2i> value);

UniformHolder uniform3f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector3f> value);
UniformHolder uniform3i(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector3i> value);

UniformHolder uniformTruncated3f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector4f> value);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public enum UniformType {
VEC2,
VEC2I,
VEC3,
VEC3I,
VEC4,
VEC4I
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package net.coderbot.iris.gl.uniform;

import net.coderbot.iris.gl.IrisRenderSystem;
import net.coderbot.iris.gl.state.ValueUpdateNotifier;
import org.joml.Vector3d;
import org.joml.Vector3f;
import org.joml.Vector3i;
import org.joml.Vector4f;

import java.util.function.Supplier;

public class Vector3IntegerUniform extends Uniform {
private final Vector3i cachedValue;
private final Supplier<Vector3i> value;

Vector3IntegerUniform(int location, Supplier<Vector3i> value) {
super(location);

this.cachedValue = new Vector3i();
this.value = value;
}

Vector3IntegerUniform(int location, Supplier<Vector3i> value, ValueUpdateNotifier notifier) {
super(location, notifier);

this.cachedValue = new Vector3i();
this.value = value;
}
@Override
public void update() {
updateValue();

if (notifier != null) {
notifier.setListener(this::updateValue);
}
}

private void updateValue() {
Vector3i newValue = value.get();

if (!newValue.equals(cachedValue)) {
cachedValue.set(newValue.x(), newValue.y(), newValue.z());
IrisRenderSystem.uniform3i(location, cachedValue.x(), cachedValue.y(), cachedValue.z());
}
}
}
2 changes: 2 additions & 0 deletions src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.coderbot.iris.pipeline.WorldRenderingPipeline;
import net.coderbot.iris.shadows.frustum.fallback.NonCullingFrustum;
import net.coderbot.iris.uniforms.CapturedRenderingState;
import net.coderbot.iris.uniforms.IrisTimeUniforms;
import net.coderbot.iris.uniforms.SystemTimeUniforms;
import org.joml.Vector3d;
import net.fabricmc.api.EnvType;
Expand Down Expand Up @@ -81,6 +82,7 @@ public class MixinLevelRenderer {
" didn't work. This is a bug! Please report it to the Iris developers.");
}

IrisTimeUniforms.updateTime();
CapturedRenderingState.INSTANCE.setGbufferModelView(poseStack.last().pose());
CapturedRenderingState.INSTANCE.setGbufferProjection(projection);
CapturedRenderingState.INSTANCE.setTickDelta(tickDelta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ public TranslationUnit parseTranslationUnit(Root rootInstance, String input) {
default:
// handling of Optifine's special core profile mode
boolean isLine = (parameters.patch == Patch.VANILLA && ((VanillaParameters) parameters).isLines());

if (profile == Profile.CORE || version.number >= 150 && profile == null || isLine) {
// patch the version number to at least 330
if (version.number < 330) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public static void addNonDynamicUniforms(UniformHolder uniforms, IdMap idMap, Pa
BiomeParameters.addBiomeUniforms(uniforms);
new CelestialUniforms(directives.getSunPathRotation()).addCelestialUniforms(uniforms);
IrisExclusiveUniforms.addIrisExclusiveUniforms(uniforms);
IrisTimeUniforms.addTimeUniforms(uniforms);
MatrixUniforms.addMatrixUniforms(uniforms, directives);
IdMapUniforms.addIdMapUniforms(updateNotifier, uniforms, idMap, directives.isOldHandLight());
CommonUniforms.generalCommonUniforms(uniforms, updateNotifier, directives);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.coderbot.iris.uniforms;

import net.coderbot.iris.JomlConversions;
import net.coderbot.iris.gl.uniform.UniformHolder;
import net.coderbot.iris.gl.uniform.UniformUpdateFrequency;
import net.coderbot.iris.gui.option.IrisVideoSettings;
Expand All @@ -10,7 +11,10 @@
import org.joml.Vector4f;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.HumanoidArm;
import net.minecraft.world.entity.LightningBolt;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.GameType;
import net.minecraft.world.phys.Vec3;

Expand All @@ -35,6 +39,15 @@ public static void addIrisExclusiveUniforms(UniformHolder uniforms) {
uniforms.uniform1b(UniformUpdateFrequency.PER_TICK, "isSpectator", IrisExclusiveUniforms::isSpectator);
uniforms.uniform3d(UniformUpdateFrequency.PER_FRAME, "eyePosition", IrisExclusiveUniforms::getEyePosition);
uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "cloudTime", CapturedRenderingState.INSTANCE::getCloudTime);
uniforms.uniform3d(UniformUpdateFrequency.PER_FRAME, "relativeEyePosition", () -> {
return CameraUniforms.getUnshiftedCameraPosition().sub(getEyePosition());
});
uniforms.uniform3d(UniformUpdateFrequency.PER_FRAME, "playerLookVector", () -> {
return JomlConversions.fromVec3(Minecraft.getInstance().getCameraEntity().getLookAngle());
});
uniforms.uniform3d(UniformUpdateFrequency.PER_FRAME, "playerBodyVector", () -> {
return JomlConversions.fromVec3(Minecraft.getInstance().getCameraEntity().getForward());
});
Vector4f zero = new Vector4f(0, 0, 0, 0);
uniforms.uniform4f(UniformUpdateFrequency.PER_TICK, "lightningBoltPosition", () -> {
if (Minecraft.getInstance().level != null) {
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/net/coderbot/iris/uniforms/IrisTimeUniforms.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package net.coderbot.iris.uniforms;

import net.coderbot.iris.Iris;
import net.coderbot.iris.gl.uniform.UniformHolder;
import net.coderbot.iris.gl.uniform.UniformUpdateFrequency;
import org.joml.Vector2i;
import org.joml.Vector3i;

import java.time.LocalDateTime;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalField;
import java.util.GregorianCalendar;

public class IrisTimeUniforms {
private static LocalDateTime dateTime;

public static void updateTime() {
dateTime = LocalDateTime.now();
}

public static void addTimeUniforms(UniformHolder uniforms) {
Vector3i date = new Vector3i();
Vector3i time = new Vector3i();
Vector2i yearTime = new Vector2i();
uniforms.uniform3i(UniformUpdateFrequency.PER_TICK, "currentDate", () -> date.set(dateTime.getYear(), dateTime.getMonthValue(), dateTime.getDayOfMonth()));
uniforms.uniform3i(UniformUpdateFrequency.PER_TICK, "currentTime", () -> time.set(dateTime.getHour(), dateTime.getMinute(), dateTime.getSecond()));
uniforms.uniform2i(UniformUpdateFrequency.PER_TICK, "currentYearTime", () -> yearTime.set(
((dateTime.getDayOfYear() - 1) * 86400) + (dateTime.getHour() * 3600) + (dateTime.getMinute() * 60) + dateTime.getSecond(),
(dateTime.toLocalDate().lengthOfYear() * 86400) - (((dateTime.getDayOfYear() - 1) * 86400) + (dateTime.getHour() * 3600) + (dateTime.getMinute() * 60) + dateTime.getSecond())
));
}

static {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ public Builder uniform3f(UniformUpdateFrequency updateFrequency, String name, Su
return this.put(name, new Float3VectorCachedUniform(name, updateFrequency, value));
}

@Override
public Builder uniform3i(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector3i> value) {
return this.put(name, new Int3VectorCachedUniform(name, updateFrequency, value));
}

@Override
public Builder uniformTruncated3f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector4f> value) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package net.coderbot.iris.uniforms.custom.cached;

import net.coderbot.iris.gl.uniform.UniformUpdateFrequency;
import net.coderbot.iris.parsing.VectorType;
import org.joml.Vector3f;
import org.joml.Vector3i;
import org.lwjgl.opengl.GL21;

import java.util.function.Supplier;

public class Int3VectorCachedUniform extends VectorCachedUniform<Vector3i> {

public Int3VectorCachedUniform(String name, UniformUpdateFrequency updateFrequency, Supplier<Vector3i> supplier) {
super(name, updateFrequency, new Vector3i(), supplier);
}

@Override
protected void setFrom(Vector3i other) {
this.cached.set(other);
}

@Override
public void push(int location) {
GL21.glUniform3i(location, this.cached.x, this.cached.y, this.cached.z);
}

@Override
public VectorType getType() {
return VectorType.I_VEC3;
}
}

0 comments on commit a913a89

Please sign in to comment.