Skip to content

Commit

Permalink
Merge branch '1.19.1' into 1.19.4
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Dec 26, 2023
2 parents c4f17ce + bdfea3f commit f7e2b59
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.coderbot.iris.gl.framebuffer;

public record ViewportData(float scale, float viewportX, float viewportY) {
private static ViewportData DEFAULT = new ViewportData(1.0f, 0.0f, 0.0f);

public static ViewportData defaultValue() {
return DEFAULT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.coderbot.iris.gl.IrisRenderSystem;
import net.coderbot.iris.gl.blending.BlendModeOverride;
import net.coderbot.iris.gl.framebuffer.GlFramebuffer;
import net.coderbot.iris.gl.framebuffer.ViewportData;
import net.coderbot.iris.gl.image.GlImage;
import net.coderbot.iris.gl.program.ComputeProgram;
import net.coderbot.iris.gl.program.Program;
Expand Down Expand Up @@ -213,7 +214,7 @@ private static class Pass {
ImmutableSet<Integer> flippedAtLeastOnce;
ImmutableSet<Integer> stageReadsFromAlt;
ImmutableSet<Integer> mipmappedBuffers;
float viewportScale;
ViewportData viewportScale;

protected void destroy() {
this.program.destroy();
Expand Down Expand Up @@ -271,9 +272,11 @@ public void renderAll() {
}
}

float scaledWidth = renderPass.viewWidth * renderPass.viewportScale;
float scaledHeight = renderPass.viewHeight * renderPass.viewportScale;
RenderSystem.viewport(0, 0, (int) scaledWidth, (int) scaledHeight);
float scaledWidth = renderPass.viewWidth * renderPass.viewportScale.scale();
float scaledHeight = renderPass.viewHeight * renderPass.viewportScale.scale();
int beginWidth = (int) (renderPass.viewWidth * renderPass.viewportScale.viewportX());
int beginHeight = (int) (renderPass.viewHeight * renderPass.viewportScale.viewportY());
RenderSystem.viewport(beginWidth, beginHeight, (int) scaledWidth, (int) scaledHeight);

renderPass.framebuffer.bind();
renderPass.program.use();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.coderbot.iris.gl.blending.BlendMode;
import net.coderbot.iris.gl.blending.BlendModeOverride;
import net.coderbot.iris.gl.blending.BufferBlendInformation;
import net.coderbot.iris.gl.framebuffer.ViewportData;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;
Expand All @@ -24,7 +25,7 @@ public class ProgramDirectives {
private static final ImmutableList<String> LEGACY_RENDER_TARGETS = PackRenderTargetDirectives.LEGACY_RENDER_TARGETS;

private final int[] drawBuffers;
private final float viewportScale;
private final ViewportData viewportScale;
@Nullable
private final AlphaTest alphaTestOverride;

Expand All @@ -34,7 +35,7 @@ public class ProgramDirectives {
private final ImmutableMap<Integer, Boolean> explicitFlips;
private boolean unknownDrawBuffers;

private ProgramDirectives(int[] drawBuffers, float viewportScale, @Nullable AlphaTest alphaTestOverride,
private ProgramDirectives(int[] drawBuffers, ViewportData viewportScale, @Nullable AlphaTest alphaTestOverride,
Optional<BlendModeOverride> blendModeOverride, List<BufferBlendInformation> bufferBlendInformations, ImmutableSet<Integer> mipmappedBuffers,
ImmutableMap<Integer, Boolean> explicitFlips) {
this.drawBuffers = drawBuffers;
Expand Down Expand Up @@ -74,7 +75,7 @@ private ProgramDirectives(int[] drawBuffers, float viewportScale, @Nullable Alph
});

if (properties != null) {
viewportScale = properties.getViewportScaleOverrides().getOrDefault(source.getName(), 1.0f);
viewportScale = properties.getViewportScaleOverrides().getOrDefault(source.getName(), ViewportData.defaultValue());
alphaTestOverride = properties.getAlphaTestOverrides().get(source.getName());

BlendModeOverride blendModeOverride = properties.getBlendModeOverrides().get(source.getName());
Expand All @@ -84,7 +85,7 @@ private ProgramDirectives(int[] drawBuffers, float viewportScale, @Nullable Alph

explicitFlips = source.getParent().getPackDirectives().getExplicitFlips(source.getName());
} else {
viewportScale = 1.0f;
viewportScale = ViewportData.defaultValue();
alphaTestOverride = null;
blendModeOverride = Optional.ofNullable(defaultBlendOverride);
bufferBlendInformations = Collections.emptyList();
Expand Down Expand Up @@ -173,7 +174,7 @@ public boolean hasUnknownDrawBuffers() {
return unknownDrawBuffers;
}

public float getViewportScale() {
public ViewportData getViewportScale() {
return viewportScale;
}

Expand Down
19 changes: 13 additions & 6 deletions src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.coderbot.iris.gl.blending.BlendModeFunction;
import net.coderbot.iris.gl.blending.BlendModeOverride;
import net.coderbot.iris.gl.buffer.ShaderStorageInfo;
import net.coderbot.iris.gl.framebuffer.ViewportData;
import net.coderbot.iris.gl.texture.InternalTextureFormat;
import net.coderbot.iris.gl.texture.PixelFormat;
import net.coderbot.iris.gl.texture.PixelType;
Expand Down Expand Up @@ -92,7 +93,7 @@ public class ShaderProperties {
// TODO: private Map<String, String> optifineVersionRequirements;
// TODO: Parse custom uniforms / variables
private final Object2ObjectMap<String, AlphaTest> alphaTestOverrides = new Object2ObjectOpenHashMap<>();
private final Object2FloatMap<String> viewportScaleOverrides = new Object2FloatOpenHashMap<>();
private final Object2ObjectMap<String, ViewportData> viewportScaleOverrides = new Object2ObjectOpenHashMap<>();
private final Object2ObjectMap<String, TextureScaleOverride> textureScaleOverrides = new Object2ObjectOpenHashMap<>();
private final Object2ObjectMap<String, BlendModeOverride> blendModeOverrides = new Object2ObjectOpenHashMap<>();
private final Object2ObjectMap<String, ArrayList<BufferBlendInformation>> bufferBlendOverrides = new Object2ObjectOpenHashMap<>();
Expand Down Expand Up @@ -212,16 +213,22 @@ public ShaderProperties(String contents, ShaderPackOptions shaderPackOptions, It
// TODO: Custom uniforms

handlePassDirective("scale.", key, value, pass -> {
float scale;
float scale, offsetX = 0.0f, offsetY = 0.0f;
String[] parts = value.split(" ");

try {
scale = Float.parseFloat(value);
} catch (NumberFormatException e) {
scale = Float.parseFloat(parts[0]);

if (parts.length > 1) {
offsetX = Float.parseFloat(parts[1]);
offsetY = Float.parseFloat(parts[2]);
}
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
Iris.logger.error("Unable to parse scale directive for " + pass + ": " + value, e);
return;
}

viewportScaleOverrides.put(pass, scale);
viewportScaleOverrides.put(pass, new ViewportData(scale, offsetX, offsetY));
});

handlePassDirective("size.buffer.", key, value, pass -> {
Expand Down Expand Up @@ -793,7 +800,7 @@ public OptionalBoolean getPrepareBeforeShadow() {
return prepareBeforeShadow;
}

public Object2FloatMap<String> getViewportScaleOverrides() {
public Object2ObjectMap<String, ViewportData> getViewportScaleOverrides() {
return viewportScaleOverrides;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.mojang.blaze3d.systems.RenderSystem;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import net.coderbot.iris.Iris;
import net.coderbot.iris.gl.framebuffer.ViewportData;
import net.coderbot.iris.gl.image.GlImage;
import net.coderbot.iris.features.FeatureFlags;
import net.coderbot.iris.gl.IrisRenderSystem;
Expand Down Expand Up @@ -154,7 +155,7 @@ private static class Pass {
ImmutableSet<Integer> flippedAtLeastOnce;
ImmutableSet<Integer> stageReadsFromAlt;
ImmutableSet<Integer> mipmappedBuffers;
float viewportScale;
ViewportData viewportScale;
ComputeProgram[] computes;

protected void destroy() {
Expand Down Expand Up @@ -213,9 +214,11 @@ public void renderAll() {
}
}

float scaledWidth = renderTargets.getResolution() * renderPass.viewportScale;
float scaledHeight = renderTargets.getResolution() * renderPass.viewportScale;
RenderSystem.viewport(0, 0, (int) scaledWidth, (int) scaledHeight);
float scaledWidth = renderTargets.getResolution() * renderPass.viewportScale.scale();
float scaledHeight = renderTargets.getResolution() * renderPass.viewportScale.scale();
int beginWidth = (int) (renderTargets.getResolution() * renderPass.viewportScale.viewportX());
int beginHeight = (int) (renderTargets.getResolution() * renderPass.viewportScale.viewportY());
RenderSystem.viewport(beginWidth, beginHeight, (int) scaledWidth, (int) scaledHeight);

renderPass.framebuffer.bind();
renderPass.program.use();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public static void addIrisExclusiveUniforms(UniformHolder uniforms) {
uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "maxPlayerHealth", IrisExclusiveUniforms::getMaxHealth);
uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "currentPlayerHunger", IrisExclusiveUniforms::getCurrentHunger);
uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "maxPlayerHunger", () -> 20);
uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "currentPlayerArmor", IrisExclusiveUniforms::getCurrentArmor);
uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "maxPlayerArmor", () -> 50);
uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "currentPlayerAir", IrisExclusiveUniforms::getCurrentAir);
uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "maxPlayerAir", IrisExclusiveUniforms::getMaxAir);
uniforms.uniform1b(UniformUpdateFrequency.PER_FRAME, "firstPersonCamera", IrisExclusiveUniforms::isFirstPersonCamera);
Expand Down Expand Up @@ -92,6 +94,14 @@ private static float getCurrentAir() {
return (float) Minecraft.getInstance().player.getAirSupply() / (float) Minecraft.getInstance().player.getMaxAirSupply();
}

private static float getCurrentArmor() {
if (Minecraft.getInstance().player == null || !Minecraft.getInstance().gameMode.getPlayerMode().isSurvival()) {
return -1;
}

return (float) (Minecraft.getInstance().player.getArmorValue() / 50.0f);
}

private static float getMaxAir() {
if (Minecraft.getInstance().player == null || !Minecraft.getInstance().gameMode.getPlayerMode().isSurvival()) {
return -1;
Expand All @@ -108,6 +118,8 @@ private static float getMaxHealth() {
return Minecraft.getInstance().player.getMaxHealth();
}



private static boolean isFirstPersonCamera() {
// If camera type is not explicitly third-person, assume it's first-person.
switch (Minecraft.getInstance().options.getCameraType()) {
Expand Down

0 comments on commit f7e2b59

Please sign in to comment.