Support render scaling factor in shaders

This commit is contained in:
mcrcortex
2025-09-03 14:51:42 +10:00
parent c268306bd6
commit 75a9df969b
5 changed files with 31 additions and 6 deletions

View File

@@ -215,4 +215,7 @@ public abstract class AbstractRenderPipeline extends TrackedObject {
return null; return null;
} }
//Null means no scaling factor
public float[] getRenderScalingFactor() {return null;}
} }

View File

@@ -227,8 +227,13 @@ public class IrisVoxyRenderPipeline extends AbstractRenderPipeline {
} }
builder.append("vec2 ").append(functionName).append("()\n"); builder.append("vec2 ").append(functionName).append("()\n");
builder.append(this.data.getTAAOffset()); builder.append(this.data.TAA);
builder.append("\n"); builder.append("\n");
return builder.toString(); return builder.toString();
} }
@Override
public float[] getRenderScalingFactor() {
return this.data.resolutionScale;
}
} }

View File

@@ -174,6 +174,14 @@ public class VoxyRenderSystem {
int width = dims[2]; int width = dims[2];
int height = dims[3]; int height = dims[3];
{//Apply render scaling factor
var factor = this.pipeline.getRenderScalingFactor();
if (factor != null) {
width = (int) (width*factor[0]);
height = (int) (height*factor[1]);
}
}
viewport viewport
.setVanillaProjection(matrices.projection()) .setVanillaProjection(matrices.projection())
.setProjection(projection) .setProjection(projection)

View File

@@ -156,6 +156,7 @@ public class IrisShaderPatch {
public Int2ObjectOpenHashMap<BlendState> blending; public Int2ObjectOpenHashMap<BlendState> blending;
public String taaOffset; public String taaOffset;
public boolean excludeLodsFromVanillaDepth; public boolean excludeLodsFromVanillaDepth;
public float[] renderScale;
public boolean checkValid() { public boolean checkValid() {
return this.opaqueDrawBuffers != null && this.translucentDrawBuffers != null && this.uniforms != null && this.opaquePatchData != null; return this.opaqueDrawBuffers != null && this.translucentDrawBuffers != null && this.uniforms != null && this.opaquePatchData != null;
} }
@@ -209,6 +210,16 @@ public class IrisShaderPatch {
return !this.patchData.excludeLodsFromVanillaDepth; return !this.patchData.excludeLodsFromVanillaDepth;
} }
public float[] getRenderScale() {
if (this.patchData.renderScale == null || this.patchData.renderScale.length==0) {
return new float[]{1,1};
}
if (this.patchData.renderScale.length == 1) {
return new float[]{this.patchData.renderScale[0],this.patchData.renderScale[0]};
}
return new float[]{Math.max(0.01f,this.patchData.renderScale[0]),Math.max(0.01f,this.patchData.renderScale[1])};
}
public Runnable createBlendSetup() { public Runnable createBlendSetup() {
if (this.patchData.blending == null || this.patchData.blending.isEmpty()) { if (this.patchData.blending == null || this.patchData.blending.isEmpty()) {
return ()->{};//No blending change return ()->{};//No blending change

View File

@@ -47,7 +47,8 @@ public class IrisVoxyRenderPipelineData {
private final ImageSet imageSet; private final ImageSet imageSet;
private final SSBOSet ssboSet; private final SSBOSet ssboSet;
public final boolean renderToVanillaDepth; public final boolean renderToVanillaDepth;
private final String TAA; public final float[] resolutionScale;
public final String TAA;
private IrisVoxyRenderPipelineData(IrisShaderPatch patch, int[] opaqueDrawTargets, int[] translucentDrawTargets, StructLayout uniformSet, Runnable blendingSetup, ImageSet imageSet, SSBOSet ssboSet) { private IrisVoxyRenderPipelineData(IrisShaderPatch patch, int[] opaqueDrawTargets, int[] translucentDrawTargets, StructLayout uniformSet, Runnable blendingSetup, ImageSet imageSet, SSBOSet ssboSet) {
this.opaqueDrawTargets = opaqueDrawTargets; this.opaqueDrawTargets = opaqueDrawTargets;
this.translucentDrawTargets = translucentDrawTargets; this.translucentDrawTargets = translucentDrawTargets;
@@ -59,6 +60,7 @@ public class IrisVoxyRenderPipelineData {
this.ssboSet = ssboSet; this.ssboSet = ssboSet;
this.renderToVanillaDepth = patch.emitToVanillaDepth(); this.renderToVanillaDepth = patch.emitToVanillaDepth();
this.TAA = patch.getTAAShift(); this.TAA = patch.getTAAShift();
this.resolutionScale = patch.getRenderScale();
} }
public SSBOSet getSsboSet() { public SSBOSet getSsboSet() {
@@ -109,10 +111,6 @@ public class IrisVoxyRenderPipelineData {
return targetTextures; return targetTextures;
} }
public String getTAAOffset() {
return this.TAA;
}
public record StructLayout(int size, String layout, LongConsumer updater) {} public record StructLayout(int size, String layout, LongConsumer updater) {}
private static StructLayout createUniformLayoutStructAndUpdater(CachedUniform[] uniforms) { private static StructLayout createUniformLayoutStructAndUpdater(CachedUniform[] uniforms) {
if (uniforms.length == 0) { if (uniforms.length == 0) {