Mipmap stuff again (#2300)

This commit is contained in:
Eclipse-Sol authored and GitHub committed 2026-10-25 19:25:54 -07:00
1 parent 17a2ed7f37
commit 1772e9eae2
56 files changed
+1872 -529

No files matched your search

@@ -93,6 +93,7 @@ public class BlockRenderingSettings {
private float ambientOcclusionLevel;
private boolean disableDirectionalShading;
private boolean useSeparateAo;
@Setter private boolean breaksAnisotropy;
private boolean useExtendedVertexFormat;
@Setter
private boolean hasSnowyEntries;
@@ -213,6 +214,10 @@ public class BlockRenderingSettings {
return useSeparateAo;
}
public boolean breaksAnisotropy() {
return breaksAnisotropy;
}
public void setUseSeparateAo(boolean useSeparateAo) {
if (useSeparateAo == this.useSeparateAo) {
return;
@@ -27,7 +27,7 @@ import java.util.Optional;
import java.util.function.Function;
public class IrisCeleritasChunkProgramOverrides {
private final EnumMap<IrisTerrainPass, GlProgram<IrisCeleritasChunkShaderInterface>> programs = new EnumMap<>(IrisTerrainPass.class);
private final EnumMap<IrisTerrainPass, GlProgram<ChunkShaderInterface>> programs = new EnumMap<>(IrisTerrainPass.class);
private boolean shadersCreated = false;
private int versionCounterForShaderReload = -1;
@@ -80,19 +80,19 @@ public class IrisCeleritasChunkProgramOverrides {
return key;
}
private static final class SavedProgram extends GlProgram<IrisCeleritasChunkShaderInterface> {
SavedProgram(int program, Function<ShaderBindingContext, IrisCeleritasChunkShaderInterface> factory) {
private static final class SavedProgram extends GlProgram<ChunkShaderInterface> {
SavedProgram(int program, Function<ShaderBindingContext, ChunkShaderInterface> factory) {
super(program, factory);
}
}
@Nullable
private GlProgram<IrisCeleritasChunkShaderInterface> createShader(IrisTerrainPass pass, CeleritasTerrainPipeline pipeline, ChunkVertexType vertexType) {
private GlProgram<ChunkShaderInterface> createShader(IrisTerrainPass pass, CeleritasTerrainPipeline pipeline, ChunkVertexType vertexType) {
final CeleritasTerrainPipeline.PassInfo passInfo = pipeline.getPassInfo(pass);
final String name = "iris:celeritas-chunk-" + pass.getName();
final BlendModeOverride blendOverride = passInfo.blendModeOverride();
final List<BufferBlendOverride> bufferOverrides = passInfo.bufferBlendOverrides();
final Function<ShaderBindingContext, IrisCeleritasChunkShaderInterface> factory = context -> new IrisCeleritasChunkShaderInterface(
final Function<ShaderBindingContext, ChunkShaderInterface> factory = context -> new IrisCeleritasChunkShaderInterface(
((GlObject) context).handle(), context, pipeline, pass.isShadow(), blendOverride, bufferOverrides, pipeline.getCustomUniforms());
final ProgramBinaryCache.Key cacheKey = cacheKey(passInfo, vertexType);
@@ -130,7 +130,7 @@ public class IrisCeleritasChunkProgramOverrides {
builder.bindAttribute(attr.getName(), attrIndex++);
}
final GlProgram<IrisCeleritasChunkShaderInterface> program = builder.link(factory);
final GlProgram<ChunkShaderInterface> program = builder.link(factory);
if (cacheKey != null) {
ProgramBinaryCache.save(cacheKey, program.handle());
}
@@ -169,7 +169,7 @@ public class IrisCeleritasChunkProgramOverrides {
}
@Nullable
public GlProgram<? extends ChunkShaderInterface> getProgramOverride(TerrainRenderPass pass, RenderPassConfiguration<?> configuration) {
public GlProgram<ChunkShaderInterface> getProgramOverride(TerrainRenderPass pass, RenderPassConfiguration<?> configuration) {
// Check for shader pack reload
if (versionCounterForShaderReload != Iris.getPipelineManager().getVersionCounterForSodiumShaderReload()) {
versionCounterForShaderReload = Iris.getPipelineManager().getVersionCounterForSodiumShaderReload();
@@ -186,23 +186,13 @@ public class IrisCeleritasChunkProgramOverrides {
createShaders(celeritasPipeline, configuration);
}
if (ShadowRenderingState.areShadowsCurrentlyBeingRendered()) {
final boolean isShadow = ShadowRenderingState.areShadowsCurrentlyBeingRendered();
if (isShadow) {
if (celeritasPipeline != null && !celeritasPipeline.hasShadowPass()) {
throw new IllegalStateException("Shadow program requested, but shader pack has no shadow pass");
}
if (pass.isReverseOrder()) {
return programs.get(IrisTerrainPass.SHADOW_TRANSLUCENT);
}
return programs.get(pass.supportsFragmentDiscard() ? IrisTerrainPass.SHADOW_CUTOUT : IrisTerrainPass.SHADOW);
} else {
if (pass.supportsFragmentDiscard()) {
return programs.get(IrisTerrainPass.GBUFFER_CUTOUT);
} else if (pass.isReverseOrder()) {
return programs.get(IrisTerrainPass.GBUFFER_TRANSLUCENT);
} else {
return programs.get(IrisTerrainPass.GBUFFER_SOLID);
}
}
return programs.get(IrisTerrainPass.fromTerrainPass(pass, isShadow));
}
public void deleteShaders() {
@@ -241,20 +241,7 @@ public class IrisCeleritasChunkShaderInterface implements ChunkShaderInterface {
}
final boolean isShadow = ShadowRenderingState.areShadowsCurrentlyBeingRendered();
final IrisTerrainPass irisPass;
if (isShadow) {
if (pass.isReverseOrder()) {
irisPass = IrisTerrainPass.SHADOW_TRANSLUCENT;
} else {
irisPass = pass.supportsFragmentDiscard() ? IrisTerrainPass.SHADOW_CUTOUT : IrisTerrainPass.SHADOW;
}
} else if (pass.isReverseOrder()) {
irisPass = IrisTerrainPass.GBUFFER_TRANSLUCENT;
} else if (pass.supportsFragmentDiscard()) {
irisPass = IrisTerrainPass.GBUFFER_CUTOUT;
} else {
irisPass = IrisTerrainPass.GBUFFER_SOLID;
}
final IrisTerrainPass irisPass = IrisTerrainPass.fromTerrainPass(pass, isShadow);
final GlFramebuffer framebuffer = pipeline.getPassInfo(irisPass).framebuffer();
if (framebuffer != null) {
@@ -40,7 +40,7 @@ public class IrisCeleritasShaderProvider implements IrisShaderProvider {
@Override
@Nullable
public GlProgram<? extends ChunkShaderInterface> getShaderOverride(TerrainRenderPass pass) {
public GlProgram<ChunkShaderInterface> getShaderOverride(TerrainRenderPass pass) {
if (!isShadersEnabled() || renderPassConfiguration == null) {
return null;
}
@@ -41,10 +41,10 @@ public enum IrisTerrainPass {
return SHADOW_TRANSLUCENT;
}
return pass.supportsFragmentDiscard() ? SHADOW_CUTOUT : SHADOW;
} else if (pass.supportsFragmentDiscard()) {
return GBUFFER_CUTOUT;
} else if (pass.isReverseOrder()) {
return GBUFFER_TRANSLUCENT;
} else if (pass.supportsFragmentDiscard()) {
return GBUFFER_CUTOUT;
} else {
return GBUFFER_SOLID;
}
@@ -93,6 +93,7 @@ public final class ComputeProgram extends GlResource {
public static void unbind() {
ProgramUniforms.clearActiveUniforms();
ProgramSamplers.clearActiveSamplers();
GLStateManager.glUseProgram(0);
}
@@ -18,6 +18,7 @@ import com.gtnewhorizons.angelica.glsm.texture.TextureType;
import org.jetbrains.annotations.Nullable;
import java.util.function.IntSupplier;
import java.util.function.Supplier;
public class ProgramBuilder extends ProgramUniforms.Builder implements SamplerHolder, ImageHolder {
private final int program;
@@ -196,17 +197,17 @@ public class ProgramBuilder extends ProgramUniforms.Builder implements SamplerHo
}
@Override
public boolean addDefaultSampler(TextureType type, IntSupplier texture, ValueUpdateNotifier notifier, GlSampler sampler, String... names) {
public boolean addDefaultSampler(TextureType type, IntSupplier texture, ValueUpdateNotifier notifier, Supplier<GlSampler> sampler, String... names) {
return samplers.addDefaultSampler(type, texture, notifier, sampler, names);
}
@Override
public boolean addDynamicSampler(TextureType type, IntSupplier texture, GlSampler sampler, String... names) {
public boolean addDynamicSampler(TextureType type, IntSupplier texture, Supplier<GlSampler> sampler, String... names) {
return samplers.addDynamicSampler(type, texture, sampler, names);
}
@Override
public boolean addDynamicSampler(TextureType type, IntSupplier texture, ValueUpdateNotifier notifier, GlSampler sampler, String... names) {
public boolean addDynamicSampler(TextureType type, IntSupplier texture, ValueUpdateNotifier notifier, Supplier<GlSampler> sampler, String... names) {
return samplers.addDynamicSampler(type, texture, notifier, sampler, names);
}
@@ -19,6 +19,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.function.IntSupplier;
import java.util.function.Supplier;
public class ProgramSamplers {
private static ProgramSamplers active;
@@ -39,23 +40,25 @@ public class ProgramSamplers {
active = this;
if (initializer != null) {
for (GlUniform1iCall call : initializer) {
RenderSystem.uniform1i(call.getLocation(), call.getValue());
int activeTexture = GLStateManager.getActiveTextureUnit();
try {
if (initializer != null) {
for (GlUniform1iCall call : initializer) {
RenderSystem.uniform1i(call.getLocation(), call.getValue());
}
initializer = null;
}
initializer = null;
for (int i = 0, n = samplerBindings.size(); i < n; i++) {
samplerBindings.get(i).update();
}
} catch (RuntimeException | Error e) {
clearActiveSamplers();
throw e;
} finally {
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0 + activeTexture);
}
// We need to keep the active texture intact, since if we mess it up
// in the middle of RenderType setup, bad things will happen.
int activeTexture = GLStateManager.getActiveTextureUnit();
for (int i = 0, n = samplerBindings.size(); i < n; i++) {
samplerBindings.get(i).update();
}
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0 + activeTexture);
}
public void removeListeners() {
@@ -70,6 +73,7 @@ public class ProgramSamplers {
if (active != null) {
active.removeListeners();
}
RenderSystem.unbindAllSamplers();
}
public static Builder builder(int program, Set<Integer> reservedTextureUnits) {
@@ -148,31 +152,30 @@ public class ProgramSamplers {
}
@Override
public boolean addDefaultSampler(TextureType type, IntSupplier texture, ValueUpdateNotifier notifier, GlSampler sampler, String... names) {
public boolean addDefaultSampler(TextureType type, IntSupplier texture, ValueUpdateNotifier notifier, Supplier<GlSampler> sampler, String... names) {
if (nextUnit != 0) {
// TODO: Relax this restriction!
throw new IllegalStateException("Texture unit 0 is already used.");
}
if (notifier != null) {
notifiersToReset.add(notifier);
}
return addDynamicSampler(type, texture, sampler, true, notifier, names);
}
@Override
public boolean addDynamicSampler(TextureType type, IntSupplier texture, GlSampler sampler, String... names) {
public boolean addDynamicSampler(TextureType type, IntSupplier texture, Supplier<GlSampler> sampler, String... names) {
return addDynamicSampler(type, texture, sampler, false, null, names);
}
@Override
public boolean addDynamicSampler(TextureType type, IntSupplier texture, ValueUpdateNotifier notifier, GlSampler sampler, String... names) {
notifiersToReset.add(notifier);
public boolean addDynamicSampler(TextureType type, IntSupplier texture, ValueUpdateNotifier notifier, Supplier<GlSampler> sampler, String... names) {
return addDynamicSampler(type, texture, sampler, false, notifier, names);
}
private boolean addDynamicSampler(TextureType type, IntSupplier texture, GlSampler sampler, boolean used, ValueUpdateNotifier notifier, String... names) {
private boolean addDynamicSampler(TextureType type, IntSupplier texture, Supplier<GlSampler> sampler, boolean used, ValueUpdateNotifier notifier, String... names) {
if (notifier != null) {
notifiersToReset.add(notifier);
}
for (String name : names) {
int location = RenderSystem.getUniformLocation(program, name);
@@ -236,26 +239,22 @@ public class ProgramSamplers {
this.deactivatedOverrides = deactivatedOverrides.build();
}
private IntSupplier getOverride(IntSupplier existing, String... names) {
private TextureAccess getOverride(String... names) {
for (String name : names) {
if (customTextureIds.containsKey(name) && !deactivatedOverrides.contains(name)) {
return customTextureIds.get(name).getTextureId();
return customTextureIds.get(name);
}
}
return existing;
return null;
}
@Override
public void addExternalSampler(int textureUnit, String... names) {
IntSupplier override = getOverride(null, names);
TextureAccess override = getOverride(names);
if (override != null) {
if (textureUnit == 0) {
samplerHolder.addDefaultSampler(override, names);
} else {
samplerHolder.addDynamicSampler(override, names);
}
addOverride(override, textureUnit == 0, names);
} else {
samplerHolder.addExternalSampler(textureUnit, names);
}
@@ -267,21 +266,34 @@ public class ProgramSamplers {
}
@Override
public boolean addDefaultSampler(TextureType type, IntSupplier texture, ValueUpdateNotifier notifier, GlSampler sampler, String... names) {
texture = getOverride(texture, names);
return samplerHolder.addDefaultSampler(type, texture, notifier, sampler, names);
public boolean addDefaultSampler(TextureType type, IntSupplier texture, ValueUpdateNotifier notifier, Supplier<GlSampler> sampler, String... names) {
return addSampler(type, texture, notifier, sampler, true, names);
}
@Override
public boolean addDynamicSampler(TextureType type, IntSupplier texture, GlSampler sampler, String... names) {
texture = getOverride(texture, names);
return samplerHolder.addDynamicSampler(type, texture, sampler, names);
public boolean addDynamicSampler(TextureType type, IntSupplier texture, Supplier<GlSampler> sampler, String... names) {
return addSampler(type, texture, null, sampler, false, names);
}
@Override
public boolean addDynamicSampler(TextureType type, IntSupplier texture, ValueUpdateNotifier notifier, GlSampler sampler, String... names) {
texture = getOverride(texture, names);
return samplerHolder.addDynamicSampler(type, texture, notifier, sampler, names);
public boolean addDynamicSampler(TextureType type, IntSupplier texture, ValueUpdateNotifier notifier, Supplier<GlSampler> sampler, String... names) {
return addSampler(type, texture, notifier, sampler, false, names);
}
private boolean addSampler(TextureType type, IntSupplier texture, ValueUpdateNotifier notifier, Supplier<GlSampler> sampler, boolean defaultSampler, String... names) {
final TextureAccess override = getOverride(names);
if (override != null) {
return addOverride(override, defaultSampler, names);
}
return defaultSampler
? samplerHolder.addDefaultSampler(type, texture, notifier, sampler, names)
: samplerHolder.addDynamicSampler(type, texture, notifier, sampler, names);
}
private boolean addOverride(TextureAccess override, boolean defaultSampler, String... names) {
return defaultSampler
? samplerHolder.addDefaultSampler(override.getType(), override.getTextureId(), null, null, names)
: samplerHolder.addDynamicSampler(override.getType(), override.getTextureId(), null, names);
}
}
}
@@ -7,8 +7,10 @@ import org.lwjgl.opengl.GL12;
import org.lwjgl.opengl.GL14;
import org.lwjgl.opengl.GL30;
import java.util.function.Supplier;
public class GlSampler extends GlObject {
public GlSampler(boolean linear, boolean mipmapped, boolean shadow, boolean hardwareShadow) {
public GlSampler(boolean linear, boolean linearMips, boolean mipmapped, boolean shadow, boolean hardwareShadow, boolean clamp) {
if (!RenderSystem.supportsSamplerObjects()) {
this.setHandle(0);
return;
@@ -16,13 +18,16 @@ public class GlSampler extends GlObject {
this.setHandle(RenderSystem.genSampler());
RenderSystem.samplerParameteri(getId(), GL11.GL_TEXTURE_MIN_FILTER, linear ? GL11.GL_LINEAR : GL11.GL_NEAREST);
RenderSystem.samplerParameteri(getId(), GL11.GL_TEXTURE_MAG_FILTER, linear ? GL11.GL_LINEAR : GL11.GL_NEAREST);
RenderSystem.samplerParameteri(getId(), GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
RenderSystem.samplerParameteri(getId(), GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
RenderSystem.samplerParameteri(getId(), GL11.GL_TEXTURE_WRAP_S, clamp ? GL12.GL_CLAMP_TO_EDGE : GL11.GL_REPEAT);
RenderSystem.samplerParameteri(getId(), GL11.GL_TEXTURE_WRAP_T, clamp ? GL12.GL_CLAMP_TO_EDGE : GL11.GL_REPEAT);
if (mipmapped) {
RenderSystem.samplerParameteri(getId(), GL11.GL_TEXTURE_MIN_FILTER, linear ? GL11.GL_LINEAR_MIPMAP_LINEAR : GL11.GL_NEAREST_MIPMAP_NEAREST);
RenderSystem.samplerParameteri(getId(), GL11.GL_TEXTURE_MIN_FILTER, linearMips
? (linear ? GL11.GL_LINEAR_MIPMAP_LINEAR : GL11.GL_NEAREST_MIPMAP_LINEAR)
: (linear ? GL11.GL_LINEAR_MIPMAP_NEAREST : GL11.GL_NEAREST_MIPMAP_NEAREST));
} else {
RenderSystem.samplerParameteri(getId(), GL11.GL_TEXTURE_MIN_FILTER, linear ? GL11.GL_LINEAR : GL11.GL_NEAREST);
}
if (hardwareShadow) {
@@ -38,4 +43,9 @@ public class GlSampler extends GlObject {
public int getId() {
return handle();
}
public static int idOf(Supplier<GlSampler> supplier) {
final GlSampler sampler = supplier == null ? null : supplier.get();
return sampler == null ? 0 : sampler.getId();
}
}
@@ -5,20 +5,21 @@ import net.coderbot.iris.gl.state.ValueUpdateNotifier;
import com.gtnewhorizons.angelica.glsm.texture.TextureType;
import java.util.function.IntSupplier;
import java.util.function.Supplier;
public class SamplerBinding {
private final Runnable updateListener = this::updateSampler;
private final TextureType textureType;
private final int textureUnit;
private final IntSupplier texture;
private final int sampler;
private final Supplier<GlSampler> sampler;
private final ValueUpdateNotifier notifier;
public SamplerBinding(TextureType type, int textureUnit, IntSupplier texture, GlSampler sampler, ValueUpdateNotifier notifier) {
public SamplerBinding(TextureType type, int textureUnit, IntSupplier texture, Supplier<GlSampler> sampler, ValueUpdateNotifier notifier) {
this.textureType = type;
this.textureUnit = textureUnit;
this.texture = texture;
this.sampler = sampler == null ? 0 : sampler.getId();
this.sampler = sampler;
this.notifier = notifier;
}
@@ -31,7 +32,7 @@ public class SamplerBinding {
}
private void updateSampler() {
RenderSystem.bindSamplerToUnit(textureUnit, sampler);
RenderSystem.bindSamplerToUnit(textureUnit, GlSampler.idOf(sampler));
RenderSystem.bindTextureToUnit(textureType.getGlType(), textureUnit, texture.getAsInt());
}
}
@@ -4,6 +4,7 @@ import net.coderbot.iris.gl.state.ValueUpdateNotifier;
import com.gtnewhorizons.angelica.glsm.texture.TextureType;
import java.util.function.IntSupplier;
import java.util.function.Supplier;
public interface SamplerHolder {
void addExternalSampler(int textureUnit, String... names);
@@ -20,7 +21,7 @@ public interface SamplerHolder {
return addDefaultSampler(TextureType.TEXTURE_2D, texture, null, null, names);
}
boolean addDefaultSampler(TextureType type, IntSupplier texture, ValueUpdateNotifier notifier, GlSampler sampler, String... names);
boolean addDefaultSampler(TextureType type, IntSupplier texture, ValueUpdateNotifier notifier, Supplier<GlSampler> sampler, String... names);
default boolean addDynamicSampler(IntSupplier texture, String... names) {
return addDynamicSampler(TextureType.TEXTURE_2D, texture, null, names);
@@ -30,11 +31,11 @@ public interface SamplerHolder {
return addDynamicSampler(type, texture, null, names);
}
boolean addDynamicSampler(TextureType type, IntSupplier texture, GlSampler sampler, String... names);
boolean addDynamicSampler(TextureType type, IntSupplier texture, Supplier<GlSampler> sampler, String... names);
default boolean addDynamicSampler(IntSupplier texture, ValueUpdateNotifier notifier, String... names) {
return addDynamicSampler(TextureType.TEXTURE_2D, texture, notifier, null, names);
}
boolean addDynamicSampler(TextureType type, IntSupplier texture, ValueUpdateNotifier notifier, GlSampler sampler, String... names);
boolean addDynamicSampler(TextureType type, IntSupplier texture, ValueUpdateNotifier notifier, Supplier<GlSampler> sampler, String... names);
}
@@ -9,6 +9,7 @@ import com.google.common.primitives.Ints;
import com.gtnewhorizons.angelica.compat.mojang.Camera;
import com.gtnewhorizons.angelica.config.AngelicaConfig;
import com.gtnewhorizons.angelica.glsm.GLDebug;
import lombok.Getter;
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformMatrix3f;
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformMatrix4f;
import org.joml.Matrix3f;
@@ -25,6 +26,7 @@ import com.gtnewhorizons.angelica.rendering.tesr.BatchEligibility;
import com.gtnewhorizons.angelica.rendering.tesr.TesrInstancingPipeline;
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import me.jellysquid.mods.sodium.client.gui.SodiumGameOptions;
import net.coderbot.iris.Iris;
import net.coderbot.iris.block_rendering.BlockMaterialMapping;
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
@@ -52,6 +54,7 @@ import net.coderbot.iris.gl.program.Program;
import net.coderbot.iris.gl.program.ProgramBuilder;
import net.coderbot.iris.gl.program.ProgramImages;
import net.coderbot.iris.gl.program.ProgramSamplers;
import net.coderbot.iris.gl.sampler.GlSampler;
import net.coderbot.iris.gl.sampler.SamplerHolder;
import net.coderbot.iris.gl.state.FogMode;
import com.gtnewhorizons.angelica.glsm.texture.DepthBufferFormat;
@@ -232,6 +235,13 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
private boolean shouldBindPBR;
private int currentNormalTexture;
private int currentSpecularTexture;
@Getter
private GlSampler normalSampler;
@Getter
private GlSampler specularSampler;
private TextureFormat samplerFormat;
private int samplerAnisotropy = -1;
private boolean samplerBreaksAnisotropy;
private PackDirectives packDirectives;
private final Set<FeatureFlags> activeFeatures;
private final ProgramFallbackResolver resolver;
@@ -377,7 +387,9 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
BlockRenderingSettings.INSTANCE.setAmbientOcclusionLevel(programs.getPackDirectives().getAmbientOcclusionLevel());
BlockRenderingSettings.INSTANCE.setDisableDirectionalShading(shouldDisableDirectionalShading());
BlockRenderingSettings.INSTANCE.setUseSeparateAo(programs.getPackDirectives().shouldUseSeparateAo());
BlockRenderingSettings.INSTANCE.setBreaksAnisotropy(programs.getPackDirectives().breaksAnisotropy());
BlockRenderingSettings.INSTANCE.setUseExtendedVertexFormat(true);
updatePbrSamplers(TextureFormatLoader.getFormat(), SodiumGameOptions.resolvedAnisotropicFiltering());
// Don't clobber anything in texture unit 0. It probably won't cause issues, but we're just being cautious here.
GLStateManager.glActiveTexture(GL13.GL_TEXTURE2);
@@ -2293,6 +2305,8 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
return;
}
updatePbrSamplers(TextureFormatLoader.getFormat(), SodiumGameOptions.resolvedAnisotropicFiltering());
isRenderingFullScreenPass = false;
isRenderingWorld = true;
isBeforeTranslucent = true;
@@ -2517,6 +2531,18 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
return currentSpecularTexture;
}
void updatePbrSamplers(TextureFormat format, int anisotropy) {
final boolean breaksAnisotropy = BlockRenderingSettings.INSTANCE.breaksAnisotropy();
if (samplerFormat == format && samplerAnisotropy == anisotropy && samplerBreaksAnisotropy == breaksAnisotropy) {
return;
}
normalSampler = IrisSamplers.getPbrSampler(format, PBRType.NORMAL, anisotropy);
specularSampler = IrisSamplers.getPbrSampler(format, PBRType.SPECULAR, anisotropy);
samplerFormat = format;
samplerAnisotropy = anisotropy;
samplerBreaksAnisotropy = breaksAnisotropy;
}
@Override
public void onBindTexture(int id) {
if (shouldBindPBR && isRenderingWorld) {
@@ -2536,12 +2562,6 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
BatchStateGuard.suspend();
try {
final TextureFormat textureFormat = TextureFormatLoader.getFormat();
if (textureFormat != null) {
textureFormat.setupTextureParameters(PBRType.NORMAL, pbrHolder.getNormalTexture());
textureFormat.setupTextureParameters(PBRType.SPECULAR, pbrHolder.getSpecularTexture());
}
PBRTextureManager.notifyPBRTexturesChanged();
} finally {
BatchStateGuard.resume();
@@ -28,6 +28,7 @@ public class FixedFunctionWorldRenderingPipeline implements WorldRenderingPipeli
public FixedFunctionWorldRenderingPipeline() {
BlockRenderingSettings.INSTANCE.setDisableDirectionalShading(shouldDisableDirectionalShading());
BlockRenderingSettings.INSTANCE.setUseSeparateAo(false);
BlockRenderingSettings.INSTANCE.setBreaksAnisotropy(false);
BlockRenderingSettings.INSTANCE.setAmbientOcclusionLevel(1.0f);
BlockRenderingSettings.INSTANCE.setUseExtendedVertexFormat(false);
BlockRenderingSettings.INSTANCE.setBlockTypeIds(null);
@@ -27,6 +27,7 @@ import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.IntSupplier;
import java.util.function.Supplier;
/**
* SDL-GPU only allows image writes from compute, so a gbuffers/shadow vertex shader that writes images gets a compute
@@ -105,7 +106,7 @@ final class VertexWriteReplays {
final List<String> samplerNames;
final int[] samplerUnits;
final IntSupplier[] samplerTextures;
final int[] samplerObjects;
final IntSupplier[] samplerObjects;
ResourceCollector(List<String> imageNames, List<String> samplerNames) {
this.imageNames = imageNames;
@@ -114,7 +115,7 @@ final class VertexWriteReplays {
this.samplerUnits = new int[samplerNames.size()];
Arrays.fill(samplerUnits, -1);
this.samplerTextures = new IntSupplier[samplerNames.size()];
this.samplerObjects = new int[samplerNames.size()];
this.samplerObjects = new IntSupplier[samplerNames.size()];
}
@Override
@@ -142,17 +143,17 @@ final class VertexWriteReplays {
}
@Override
public boolean addDefaultSampler(TextureType type, IntSupplier texture, ValueUpdateNotifier notifier, GlSampler sampler, String... names) {
public boolean addDefaultSampler(TextureType type, IntSupplier texture, ValueUpdateNotifier notifier, Supplier<GlSampler> sampler, String... names) {
return addDynamicSampler(type, texture, notifier, sampler, names);
}
@Override
public boolean addDynamicSampler(TextureType type, IntSupplier texture, GlSampler sampler, String... names) {
public boolean addDynamicSampler(TextureType type, IntSupplier texture, Supplier<GlSampler> sampler, String... names) {
return addDynamicSampler(type, texture, null, sampler, names);
}
@Override
public boolean addDynamicSampler(TextureType type, IntSupplier texture, ValueUpdateNotifier notifier, GlSampler sampler, String... names) {
public boolean addDynamicSampler(TextureType type, IntSupplier texture, ValueUpdateNotifier notifier, Supplier<GlSampler> sampler, String... names) {
boolean used = false;
for (String name : names) {
final int index = samplerNames.indexOf(name);
@@ -160,7 +161,7 @@ final class VertexWriteReplays {
used = true;
if (unassigned(index)) {
samplerTextures[index] = texture;
samplerObjects[index] = sampler != null ? sampler.getId() : 0;
samplerObjects[index] = () -> GlSampler.idOf(sampler);
}
}
return used;
@@ -3,7 +3,9 @@ package net.coderbot.iris.samplers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.gtnewhorizons.angelica.glsm.RenderSystem;
import com.gtnewhorizons.angelica.rendering.TextureSamplers;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
import net.coderbot.iris.gbuffer_overrides.matching.InputAvailability;
import net.coderbot.iris.gl.image.GlImage;
import net.coderbot.iris.gl.sampler.GlSampler;
@@ -11,12 +13,15 @@ import net.coderbot.iris.gl.sampler.SamplerHolder;
import net.coderbot.iris.gl.state.StateUpdateNotifiers;
import net.coderbot.iris.gl.texture.TextureAccess;
import com.gtnewhorizons.angelica.glsm.texture.TextureType;
import net.coderbot.iris.pipeline.DeferredWorldRenderingPipeline;
import net.coderbot.iris.pipeline.WorldRenderingPipeline;
import net.coderbot.iris.rendertarget.RenderTarget;
import net.coderbot.iris.rendertarget.RenderTargets;
import net.coderbot.iris.shaderpack.PackRenderTargetDirectives;
import net.coderbot.iris.shaderpack.PackShadowDirectives;
import net.coderbot.iris.shadows.ShadowRenderTargets;
import net.coderbot.iris.texture.format.TextureFormat;
import net.coderbot.iris.texture.pbr.PBRType;
import net.minecraft.client.renderer.texture.AbstractTexture;
import java.util.Set;
@@ -39,6 +44,7 @@ public class IrisSamplers {
private static GlSampler SHADOW_SAMPLER_NEAREST;
private static GlSampler SHADOW_SAMPLER_LINEAR;
private static GlSampler MIPPED_NEAREST_NEAREST;
private IrisSamplers() {
// no construction allowed
@@ -49,8 +55,23 @@ public class IrisSamplers {
// Leave as null - callers handle null gracefully
return;
}
SHADOW_SAMPLER_NEAREST = new GlSampler(false, false, true, true);
SHADOW_SAMPLER_LINEAR = new GlSampler(true, false, true, true);
SHADOW_SAMPLER_NEAREST = new GlSampler(false, false, false, true, true, true);
SHADOW_SAMPLER_LINEAR = new GlSampler(true, true, false, true, true, true);
MIPPED_NEAREST_NEAREST = new GlSampler(false, false, true, false, false, true);
}
public static GlSampler getTerrainSampler(int anisotropy) {
if (BlockRenderingSettings.INSTANCE.breaksAnisotropy()) {
anisotropy = 1;
}
return TextureSamplers.getTerrainSampler(false, anisotropy);
}
public static GlSampler getPbrSampler(TextureFormat format, PBRType type, int anisotropy) {
if (format != null && !format.canInterpolateValues(type)) {
return MIPPED_NEAREST_NEAREST;
}
return getTerrainSampler(anisotropy);
}
public static void addRenderTargetSamplers(SamplerHolder samplers, Supplier<ImmutableSet<Integer>> flipped,
@@ -94,8 +115,8 @@ public class IrisSamplers {
// Add the DH depth textures (stub implementation returns 0 until DH is integrated)
if (pipeline != null) {
samplers.addDynamicSampler(TextureType.TEXTURE_2D, () -> pipeline.getDHCompat().getDepthTex(), (GlSampler) null, "dhDepthTex", "dhDepthTex0");
samplers.addDynamicSampler(TextureType.TEXTURE_2D, () -> pipeline.getDHCompat().getDepthTexNoTranslucent(), (GlSampler) null, "dhDepthTex1");
samplers.addDynamicSampler(TextureType.TEXTURE_2D, () -> pipeline.getDHCompat().getDepthTex(), "dhDepthTex", "dhDepthTex0");
samplers.addDynamicSampler(TextureType.TEXTURE_2D, () -> pipeline.getDHCompat().getDepthTexNoTranslucent(), "dhDepthTex1");
}
}
@@ -137,13 +158,13 @@ public class IrisSamplers {
final GlSampler sampler1 = separateHardwareSamplers ? null : (shadowRenderTargets.isHardwareFiltered(1) ? (shadowRenderTargets.isLinearFiltered(1) ? SHADOW_SAMPLER_LINEAR : SHADOW_SAMPLER_NEAREST) : null);
if (waterShadowEnabled) {
samplers.addDynamicSampler(TextureType.TEXTURE_2D, shadowRenderTargets.getDepthTexture()::getTextureId, sampler0, "shadowtex0", "watershadow");
if (samplers.addDynamicSampler(TextureType.TEXTURE_2D, shadowRenderTargets.getDepthTextureNoTranslucents()::getTextureId, sampler1, "shadowtex1", "shadow")) {
samplers.addDynamicSampler(TextureType.TEXTURE_2D, shadowRenderTargets.getDepthTexture()::getTextureId, () -> sampler0, "shadowtex0", "watershadow");
if (samplers.addDynamicSampler(TextureType.TEXTURE_2D, shadowRenderTargets.getDepthTextureNoTranslucents()::getTextureId, () -> sampler1, "shadowtex1", "shadow")) {
usage |= USAGE_SHADOWTEX1;
}
} else {
samplers.addDynamicSampler(TextureType.TEXTURE_2D, shadowRenderTargets.getDepthTexture()::getTextureId, sampler0, "shadowtex0", "shadow");
if (samplers.addDynamicSampler(TextureType.TEXTURE_2D, shadowRenderTargets.getDepthTextureNoTranslucents()::getTextureId, sampler1, "shadowtex1")) {
samplers.addDynamicSampler(TextureType.TEXTURE_2D, shadowRenderTargets.getDepthTexture()::getTextureId, () -> sampler0, "shadowtex0", "shadow");
if (samplers.addDynamicSampler(TextureType.TEXTURE_2D, shadowRenderTargets.getDepthTextureNoTranslucents()::getTextureId, () -> sampler1, "shadowtex1")) {
usage |= USAGE_SHADOWTEX1;
}
}
@@ -176,12 +197,12 @@ public class IrisSamplers {
// Hardware-filtered shadow samplers for separate HW sampler access
if (shadowRenderTargets.isHardwareFiltered(0) && separateHardwareSamplers) {
final GlSampler hwSampler0 = shadowRenderTargets.isLinearFiltered(0) ? SHADOW_SAMPLER_LINEAR : SHADOW_SAMPLER_NEAREST;
samplers.addDynamicSampler(TextureType.TEXTURE_2D, shadowRenderTargets.getDepthTexture()::getTextureId, hwSampler0, "shadowtex0HW");
samplers.addDynamicSampler(TextureType.TEXTURE_2D, shadowRenderTargets.getDepthTexture()::getTextureId, () -> hwSampler0, "shadowtex0HW");
}
if (shadowRenderTargets.isHardwareFiltered(1) && separateHardwareSamplers) {
final GlSampler hwSampler1 = shadowRenderTargets.isLinearFiltered(1) ? SHADOW_SAMPLER_LINEAR : SHADOW_SAMPLER_NEAREST;
if (samplers.addDynamicSampler(TextureType.TEXTURE_2D, shadowRenderTargets.getDepthTextureNoTranslucents()::getTextureId, hwSampler1, "shadowtex1HW")) {
if (samplers.addDynamicSampler(TextureType.TEXTURE_2D, shadowRenderTargets.getDepthTextureNoTranslucents()::getTextureId, () -> hwSampler1, "shadowtex1HW")) {
usage |= USAGE_SHADOWTEX1;
}
}
@@ -207,8 +228,12 @@ public class IrisSamplers {
samplers.addDynamicSampler(whitePixel::getGlTextureId, "lightmap");
}
samplers.addDynamicSampler(pipeline::getCurrentNormalTexture, StateUpdateNotifiers.normalTextureChangeNotifier, "normals");
samplers.addDynamicSampler(pipeline::getCurrentSpecularTexture, StateUpdateNotifiers.specularTextureChangeNotifier, "specular");
if (pipeline instanceof DeferredWorldRenderingPipeline deferred) {
samplers.addDynamicSampler(TextureType.TEXTURE_2D, pipeline::getCurrentNormalTexture,
StateUpdateNotifiers.normalTextureChangeNotifier, deferred::getNormalSampler, "normals");
samplers.addDynamicSampler(TextureType.TEXTURE_2D, pipeline::getCurrentSpecularTexture,
StateUpdateNotifiers.specularTextureChangeNotifier, deferred::getSpecularSampler, "specular");
}
}
public static int addWorldDepthSamplers(SamplerHolder samplers, RenderTargets renderTargets) {
@@ -41,6 +41,7 @@ public class PackDirectives {
private boolean weatherParticles;
private boolean rainDepth;
private boolean separateAo;
private boolean breaksAnisotropy;
private boolean voxelizeLightBlocks;
private boolean separateEntityDraws;
private boolean frustumCulling;
@@ -89,6 +90,7 @@ public class PackDirectives {
weatherParticles = properties.getWeatherParticles().orElse(true);
rainDepth = properties.getRainDepth().orElse(false);
separateAo = properties.getSeparateAo().orElse(false);
breaksAnisotropy = properties.getBreaksAnisotropy().orElse(false);
voxelizeLightBlocks = properties.getVoxelizeLightBlocks().orElse(false);
separateEntityDraws = properties.getSeparateEntityDraws().orElse(false);
frustumCulling = properties.getFrustumCulling().orElse(true);
@@ -111,6 +113,7 @@ public class PackDirectives {
this(supportedRenderTargets, new PackShadowDirectives(directives.getShadowDirectives()));
cloudSetting = directives.cloudSetting;
separateAo = directives.separateAo;
breaksAnisotropy = directives.breaksAnisotropy;
voxelizeLightBlocks = directives.voxelizeLightBlocks;
separateEntityDraws = directives.separateEntityDraws;
frustumCulling = directives.frustumCulling;
@@ -166,6 +169,10 @@ public class PackDirectives {
return separateAo;
}
public boolean breaksAnisotropy() {
return breaksAnisotropy;
}
public boolean shouldVoxelizeLightBlocks() {
return voxelizeLightBlocks;
}
@@ -87,6 +87,7 @@ public class ShaderProperties {
@Getter private OptionalBoolean concurrentCompute = OptionalBoolean.DEFAULT;
@Getter private OptionalBoolean beaconBeamDepth = OptionalBoolean.DEFAULT;
@Getter private OptionalBoolean separateAo = OptionalBoolean.DEFAULT;
@Getter private OptionalBoolean breaksAnisotropy = OptionalBoolean.DEFAULT;
@Getter private OptionalBoolean voxelizeLightBlocks = OptionalBoolean.DEFAULT;
@Getter private OptionalBoolean separateEntityDraws = OptionalBoolean.DEFAULT;
@Getter private OptionalBoolean frustumCulling = OptionalBoolean.DEFAULT;
@@ -221,6 +222,7 @@ public class ShaderProperties {
handleBooleanDirective(key, value, "allowConcurrentCompute", bool -> concurrentCompute = bool);
handleBooleanDirective(key, value, "beacon.beam.depth", bool -> beaconBeamDepth = bool);
handleBooleanDirective(key, value, "separateAo", bool -> separateAo = bool);
handleBooleanDirective(key, value, "breaksAnisotropy", bool -> breaksAnisotropy = bool);
handleBooleanDirective(key, value, "voxelizeLightBlocks", bool -> voxelizeLightBlocks = bool);
handleBooleanDirective(key, value, "separateEntityDraws", bool -> separateEntityDraws = bool);
handleBooleanDirective(key, value, "frustum.culling", bool -> frustumCulling = bool);
@@ -113,7 +113,7 @@ public class PBRAtlasTexture extends AutoClosableAbstractTexture {
protected void uploadSprite(TextureAtlasSprite sprite) {
final int gutter = ((SpriteExtension) sprite).angelica$getGutterWidth();
if (sprite.animationMetadata.getFrameCount() > 1) {
if (sprite.animationMetadata.getFrameCount() > 0) {
final AnimationMetadataSection metadata = sprite.animationMetadata;
final int frameCount = sprite.getFrameCount();
for (int frame = sprite.frameCounter; frame >= 0; frame--) {