Common Shaders #14

Merged
embeddedt merged 4 commits from mitchej123/celeritas:forge170-shaders into stonecutter 2025-07-02 19:39:08 -04:00
8 changed files with 541 additions and 365 deletions
Showing only changes of commit 47407a19d7 - Show all commits

No files matched your search

@@ -55,6 +55,8 @@ public interface RenderSystemService {
Matrix4f getProjectionMatrix();
void setProjectionMatrixOrth(Matrix4f projectionMatrix);
void setProjectionMatrixOrigin(Matrix4f projectionMatrix);
default void setPositionShader() {};
// TODO: Figure out VertexSorting type
// void setProjectionMatrix(Matrix4f projectionMatrix, VertexSorting vertexSorting)
@@ -60,6 +60,11 @@ import net.irisshaders.iris.targets.RenderTargetStateListener;
import net.irisshaders.iris.targets.RenderTargets;
import net.irisshaders.iris.targets.backed.NativeImageBackedSingleColorTexture;
import net.irisshaders.iris.texture.TextureInfoCache;
import net.irisshaders.iris.texture.format.TextureFormat;
import net.irisshaders.iris.texture.format.TextureFormatLoader;
import net.irisshaders.iris.texture.pbr.PBRTextureHolder;
import net.irisshaders.iris.texture.pbr.PBRTextureManager;
import net.irisshaders.iris.texture.pbr.PBRType;
import net.irisshaders.iris.uniforms.CapturedRenderingState;
import net.irisshaders.iris.uniforms.CommonUniforms;
import net.irisshaders.iris.uniforms.FrameUpdateNotifier;
@@ -75,7 +80,10 @@ import org.embeddedt.embeddium.impl.gl.debug.GLDebug;
import org.jetbrains.annotations.Nullable;
import org.joml.Vector3d;
import org.joml.Vector4f;
import org.lwjgl.opengl.ARBClearTexture;
import org.lwjgl.opengl.GL15C;
import org.lwjgl.opengl.GL20C;
import org.lwjgl.opengl.GL21C;
import org.lwjgl.opengl.GL30C;
import org.lwjgl.opengl.GL43C;
@@ -351,8 +359,7 @@ public abstract class CommonIrisRenderingPipeline implements WorldRenderingPipel
}
public GlFramebuffer createDHFramebuffer(ProgramSource sources, boolean trans) {
return renderTargets.createDHFramebuffer(trans ? flippedAfterTranslucent : flippedAfterPrepare,
sources.getDirectives().getDrawBuffers());
return renderTargets.createDHFramebuffer(trans ? flippedAfterTranslucent : flippedAfterPrepare, sources.getDirectives().getDrawBuffers());
}
public ImmutableSet<Integer> getFlippedBeforeShadow() {
@@ -369,13 +376,232 @@ public abstract class CommonIrisRenderingPipeline implements WorldRenderingPipel
public GlFramebuffer createDHFramebufferShadow(ProgramSource sources) {
return shadowRenderTargets.createDHFramebuffer(ImmutableSet.of(), new int[]{0, 1});
return shadowRenderTargets.createDHFramebuffer(ImmutableSet.of(), new int[] { 0, 1 });
}
public boolean hasShadowRenderTargets() {
return shadowRenderTargets != null;
}
@Override
public void onSetShaderTexture(int id) {
if (shouldBindPBR && isRenderingWorld) {
PBRTextureHolder pbrHolder = PBRTextureManager.INSTANCE.getOrLoadHolder(id);
currentNormalTexture = pbrHolder.normalTexture().getId();
currentSpecularTexture = pbrHolder.specularTexture().getId();
TextureFormat textureFormat = TextureFormatLoader.getFormat();
if (textureFormat != null) {
int previousBinding = GL_STATE_MANAGER.getActiveBoundTexture();
textureFormat.setupTextureParameters(PBRType.NORMAL, pbrHolder.normalTexture());
textureFormat.setupTextureParameters(PBRType.SPECULAR, pbrHolder.specularTexture());
GL_STATE_MANAGER.bindTexture(previousBinding);
}
PBRTextureManager.notifyPBRTexturesChanged();
}
}
@Override
public void beginTranslucents() {
if (destroyed) {
throw new IllegalStateException("Tried to use a destroyed world rendering pipeline");
}
removePhaseIfNeeded();
isBeforeTranslucent = false;
// We need to copy the current depth texture so that depthtex1 can contain the depth values for
// all non-translucent content, as required.
renderTargets.copyPreTranslucentDepth();
deferredRenderer.renderAll();
RENDER_SYSTEM.enableBlend();
// note: we are careful not to touch the lightmap texture unit or overlay color texture unit here,
// so we don't need to do anything to restore them if needed.
//
// Previous versions of the code tried to "restore" things by enabling the lightmap & overlay color
// but that actually broke rendering of clouds and rain by making them appear red in the case of
// a pack not overriding those shader programs.
//
// Not good!
// Reset shader or whatever...
RENDER_SYSTEM.setPositionShader();
}
@Override
public void beginLevelRendering() {
isRenderingWorld = true;
if (blockIdsNeedPopulation) {
MINECRAFT_SHIM.populateBlockIds(pack);
WorldRenderingSettings.INSTANCE.reloadRendererIfRequired();
blockIdsNeedPopulation = false;
}
// Make sure we're using texture unit 0 for this.
RENDER_SYSTEM.glActiveTexture(GL15C.GL_TEXTURE0);
Vector4f emptyClearColor = new Vector4f(1.0F);
GLDebug.pushGroup(100, "Clear textures");
for (GlImage image : clearImages) {
ARBClearTexture.glClearTexImage(image.getId(), 0, image.getFormat().getGlFormat(), image.getPixelType().getGlFormat(), (int[]) null);
}
if (hasShadowRenderTargets()) {
if (packDirectives.getShadowDirectives().isShadowEnabled() == OptionalBoolean.FALSE) {
if (shadowRenderTargets.isFullClearRequired()) {
this.shadowClearPasses = ClearPassCreator.createShadowClearPasses(shadowRenderTargets, false, shadowDirectives);
this.shadowClearPassesFull = ClearPassCreator.createShadowClearPasses(shadowRenderTargets, true, shadowDirectives);
shadowRenderTargets.onFullClear();
for (ClearPass clearPass : shadowClearPassesFull) {
clearPass.execute(emptyClearColor);
}
}
} else {
// Clear depth first, regardless of any color clearing.
shadowRenderTargets.getDepthSourceFb().bind();
RENDER_SYSTEM.clear(GL21C.GL_DEPTH_BUFFER_BIT, MINECRAFT_SHIM.isOnOSX());
ImmutableList<ClearPass> passes;
for (ComputeProgram computeProgram : shadowComputes) {
if (computeProgram != null) {
computeProgram.use();
getCustomUniforms().push(computeProgram);
computeProgram.dispatch(shadowMapResolution, shadowMapResolution);
}
}
if (shadowRenderTargets.isFullClearRequired()) {
this.shadowClearPasses = ClearPassCreator.createShadowClearPasses(shadowRenderTargets, false, shadowDirectives);
this.shadowClearPassesFull = ClearPassCreator.createShadowClearPasses(shadowRenderTargets, true, shadowDirectives);
passes = shadowClearPassesFull;
shadowRenderTargets.onFullClear();
} else {
passes = shadowClearPasses;
}
for (ClearPass clearPass : passes) {
clearPass.execute(emptyClearColor);
}
}
}
// NB: execute this before resizing / clearing so that the center depth sample is retrieved properly.
getFrameUpdateNotifier().onNewFrame();
// Update custom uniforms
this.getCustomUniforms().update();
this.updateMCFBInfo();
int internalFormat = TextureInfoCache.INSTANCE.getInfo(mainFBDepthTextureId).getInternalFormat();
DepthBufferFormat depthBufferFormat = DepthBufferFormat.fromGlEnumOrDefault(internalFormat);
boolean changed = renderTargets.resizeIfNeeded(mainFBDepthBufferVersion, mainFBDepthTextureId, mainFBWidth, mainFBHeight, depthBufferFormat, packDirectives);
if (changed) {
beginRenderer.recalculateSizes();
prepareRenderer.recalculateSizes();
deferredRenderer.recalculateSizes();
compositeRenderer.recalculateSizes();
finalPassRenderer.recalculateSwapPassSize();
if (shaderStorageBufferHolder != null) {
shaderStorageBufferHolder.hasResizedScreen(mainFBWidth, mainFBHeight);
}
customImages.forEach(image -> image.updateNewSize(mainFBWidth, mainFBHeight));
this.clearPassesFull.forEach(clearPass -> renderTargets.destroyFramebuffer(clearPass.getFramebuffer()));
this.clearPasses.forEach(clearPass -> renderTargets.destroyFramebuffer(clearPass.getFramebuffer()));
this.clearPassesFull = ClearPassCreator.createClearPasses(renderTargets, true, packDirectives.getRenderTargetDirectives());
this.clearPasses = ClearPassCreator.createClearPasses(renderTargets, false, packDirectives.getRenderTargetDirectives());
}
if (changed || IrisVideoSettings.colorSpace != currentColorSpace) {
currentColorSpace = IrisVideoSettings.colorSpace;
colorSpaceConverter.rebuildProgram(mainFBWidth, mainFBHeight, currentColorSpace);
}
final ImmutableList<ClearPass> passes;
if (renderTargets.isFullClearRequired()) {
renderTargets.onFullClear();
passes = clearPassesFull;
} else {
passes = clearPasses;
}
Vector3d fogColor3 = CapturedRenderingState.INSTANCE.getFogColor();
// NB: The alpha value must be 1.0 here, or else you will get a bunch of bugs. Sildur's Vibrant Shaders
// will give you pink reflections and other weirdness if this is zero.
Vector4f fogColor = new Vector4f((float) fogColor3.x, (float) fogColor3.y, (float) fogColor3.z, 1.0F);
for (ClearPass clearPass : passes) {
clearPass.execute(fogColor);
}
GLDebug.popGroup();
// Make sure to switch back to the main framebuffer. If we forget to do this then our alt buffers might be
// cleared to the fog color, which absolutely is not what we want!
//
// If we forget to do this, then weird lines appear at the top of the screen and the right of the screen
// on Sildur's Vibrant Shaders.
MINECRAFT_SHIM.bindMainFramebuffer();
setIsMainBound(true);
if (changed) {
boolean hasRun = false;
for (ComputeProgram program : setup) {
if (program != null) {
hasRun = true;
program.use();
program.dispatch(1, 1);
}
}
if (hasRun) {
ComputeProgram.unbind();
}
}
isBeforeTranslucent = true;
beginRenderer.renderAll();
setPhase(WorldRenderingPhase.SKY);
// Render our horizon box before actual sky rendering to avoid being broken by mods that do weird things
// while rendering the sky.
//
// A lot of dimension mods touch sky rendering, FabricSkyboxes injects at HEAD and cancels, etc.
if (MINECRAFT_SHIM.isSkyTypeNormal()) {
RENDER_SYSTEM.depthMask(false);
RENDER_SYSTEM.setShaderColor(fogColor.x, fogColor.y, fogColor.z, fogColor.w);
renderHorizon();
RENDER_SYSTEM.depthMask(true);
RENDER_SYSTEM.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
}
}
protected abstract void renderHorizon();
/**
* Updates information about the main FB
* - Be sure to call this before using the MC FB info
@@ -414,7 +640,8 @@ public abstract class CommonIrisRenderingPipeline implements WorldRenderingPipel
this.shaderStorageBufferHolder.setupBuffers();
} else {
throw new IllegalStateException("Shader storage buffers/immutable buffer storage is not supported on this graphics card, however the shaderpack requested them? This shouldn't be possible.");
throw new IllegalStateException(
"Shader storage buffers/immutable buffer storage is not supported on this graphics card, however the shaderpack requested them? This shouldn't be possible.");
}
} else {
for (int i = 0; i < Math.min(16, SamplerLimits.get().getMaxShaderStorageUnits()); i++) {
@@ -425,9 +652,29 @@ public abstract class CommonIrisRenderingPipeline implements WorldRenderingPipel
this.customImages = new HashSet<>();
for (ImageInformation information : programSet.getPack().getIrisCustomImages()) {
if (information.isRelative()) {
customImages.add(new GlImage.Relative(information.name(), information.samplerName(), information.format(), information.internalTextureFormat(), information.type(), information.clear(), information.relativeWidth(), information.relativeHeight(), mainFBWidth, mainFBHeight));
customImages.add(new GlImage.Relative(
information.name(),
information.samplerName(),
information.format(),
information.internalTextureFormat(),
information.type(),
information.clear(),
information.relativeWidth(),
information.relativeHeight(),
mainFBWidth,
mainFBHeight));
} else {
customImages.add(new GlImage(information.name(), information.samplerName(), information.target(), information.format(), information.internalTextureFormat(), information.type(), information.clear(), information.width(), information.height(), information.depth()));
customImages.add(new GlImage(
information.name(),
information.samplerName(),
information.target(),
information.format(),
information.internalTextureFormat(),
information.type(),
information.clear(),
information.width(),
information.height(),
information.depth()));
}
}
this.clearImages = customImages.stream().filter(GlImage::shouldClear).toArray(GlImage[]::new);
@@ -440,9 +687,14 @@ public abstract class CommonIrisRenderingPipeline implements WorldRenderingPipel
}
});
this.renderTargets = new RenderTargets(mainFBWidth, mainFBHeight,
this.renderTargets = new RenderTargets(
mainFBWidth,
mainFBHeight,
mainFBDepthTextureId,
mainFBDepthBufferVersion, depthBufferFormat, programSet.getPackDirectives().getRenderTargetDirectives().getRenderTargetSettings(), programSet.getPackDirectives());
mainFBDepthBufferVersion,
depthBufferFormat,
programSet.getPackDirectives().getRenderTargetDirectives().getRenderTargetSettings(),
programSet.getPackDirectives());
this.sunPathRotation = programSet.getPackDirectives().getSunPathRotation();
PackShadowDirectives shadowDirectives = programSet.getPackDirectives().getShadowDirectives();
@@ -450,8 +702,7 @@ public abstract class CommonIrisRenderingPipeline implements WorldRenderingPipel
if (shadowDirectives.isDistanceRenderMulExplicit()) {
if (shadowDirectives.getDistanceRenderMul() >= 0.0) {
// add 15 and then divide by 16 to ensure we're rounding up
forcedShadowRenderDistanceChunks =
OptionalInt.of(((int) (shadowDirectives.getDistance() * shadowDirectives.getDistanceRenderMul()) + 15) / 16);
forcedShadowRenderDistanceChunks = OptionalInt.of(((int) (shadowDirectives.getDistance() * shadowDirectives.getDistanceRenderMul()) + 15) / 16);
} else {
forcedShadowRenderDistanceChunks = OptionalInt.of(-1);
}
@@ -459,14 +710,20 @@ public abstract class CommonIrisRenderingPipeline implements WorldRenderingPipel
forcedShadowRenderDistanceChunks = OptionalInt.empty();
}
this.customUniforms = programSet.getPack().customUniforms.build(
holder -> CommonUniforms.addNonDynamicUniforms(holder, programSet.getPack().getIdMap(), programSet.getPackDirectives(), this.updateNotifier)
);
this.customUniforms = programSet.getPack().customUniforms.build(holder -> CommonUniforms.addNonDynamicUniforms(
holder,
programSet.getPack().getIdMap(),
programSet.getPackDirectives(),
this.updateNotifier));
// Don't clobber anything in texture unit 0. It probably won't cause issues, but we're just being cautious here.
GL_STATE_MANAGER.glActiveTexture(GL20C.GL_TEXTURE2);
this.customTextureManager = new CustomTextureManager(programSet.getPackDirectives(), programSet.getPack().getCustomTextureDataMap(), programSet.getPack().getIrisCustomTextureDataMap(), programSet.getPack().getCustomNoiseTexture());
this.customTextureManager = new CustomTextureManager(
programSet.getPackDirectives(),
programSet.getPack().getCustomTextureDataMap(),
programSet.getPack().getIrisCustomTextureDataMap(),
programSet.getPack().getCustomNoiseTexture());
this.whitePixel = new NativeImageBackedSingleColorTexture(255, 255, 255, 255);
GL_STATE_MANAGER.glActiveTexture(GL20C.GL_TEXTURE0);
@@ -488,45 +745,112 @@ public abstract class CommonIrisRenderingPipeline implements WorldRenderingPipel
this.shadowComputes = createShadowComputes(programSet.getShadowCompute(), programSet);
this.beginRenderer = new CompositeRenderer(this, programSet.getPackDirectives(), programSet.getBegin(), programSet.getBeginCompute(), renderTargets, shaderStorageBufferHolder,
customTextureManager.getNoiseTexture(), updateNotifier, centerDepthSampler, flipper, shadowTargetsSupplier, TextureStage.BEGIN,
customTextureManager.getCustomTextureIdMap().getOrDefault(TextureStage.BEGIN, Object2ObjectMaps.emptyMap()), customTextureManager.getIrisCustomTextures(), customImages,
programSet.getPackDirectives().getExplicitFlips("begin_pre"), customUniforms);
this.beginRenderer = new CompositeRenderer(
this,
programSet.getPackDirectives(),
programSet.getBegin(),
programSet.getBeginCompute(),
renderTargets,
shaderStorageBufferHolder,
customTextureManager.getNoiseTexture(),
updateNotifier,
centerDepthSampler,
flipper,
shadowTargetsSupplier,
TextureStage.BEGIN,
customTextureManager.getCustomTextureIdMap().getOrDefault(TextureStage.BEGIN, Object2ObjectMaps.emptyMap()),
customTextureManager.getIrisCustomTextures(),
customImages,
programSet.getPackDirectives().getExplicitFlips("begin_pre"),
customUniforms);
flippedBeforeShadow = flipper.snapshot();
this.prepareRenderer = new CompositeRenderer(this, programSet.getPackDirectives(), programSet.getPrepare(), programSet.getPrepareCompute(), renderTargets, shaderStorageBufferHolder,
customTextureManager.getNoiseTexture(), updateNotifier, centerDepthSampler, flipper, shadowTargetsSupplier, TextureStage.PREPARE,
customTextureManager.getCustomTextureIdMap().getOrDefault(TextureStage.PREPARE, Object2ObjectMaps.emptyMap()), customTextureManager.getIrisCustomTextures(), customImages,
programSet.getPackDirectives().getExplicitFlips("prepare_pre"), customUniforms);
this.prepareRenderer = new CompositeRenderer(
this,
programSet.getPackDirectives(),
programSet.getPrepare(),
programSet.getPrepareCompute(),
renderTargets,
shaderStorageBufferHolder,
customTextureManager.getNoiseTexture(),
updateNotifier,
centerDepthSampler,
flipper,
shadowTargetsSupplier,
TextureStage.PREPARE,
customTextureManager.getCustomTextureIdMap().getOrDefault(TextureStage.PREPARE, Object2ObjectMaps.emptyMap()),
customTextureManager.getIrisCustomTextures(),
customImages,
programSet.getPackDirectives().getExplicitFlips("prepare_pre"),
customUniforms);
flippedAfterPrepare = flipper.snapshot();
this.deferredRenderer = new CompositeRenderer(this, programSet.getPackDirectives(), programSet.getDeferred(), programSet.getDeferredCompute(), renderTargets, shaderStorageBufferHolder,
customTextureManager.getNoiseTexture(), updateNotifier, centerDepthSampler, flipper, shadowTargetsSupplier, TextureStage.DEFERRED,
customTextureManager.getCustomTextureIdMap().getOrDefault(TextureStage.DEFERRED, Object2ObjectMaps.emptyMap()), customTextureManager.getIrisCustomTextures(), customImages,
programSet.getPackDirectives().getExplicitFlips("deferred_pre"), customUniforms);
this.deferredRenderer = new CompositeRenderer(
this,
programSet.getPackDirectives(),
programSet.getDeferred(),
programSet.getDeferredCompute(),
renderTargets,
shaderStorageBufferHolder,
customTextureManager.getNoiseTexture(),
updateNotifier,
centerDepthSampler,
flipper,
shadowTargetsSupplier,
TextureStage.DEFERRED,
customTextureManager.getCustomTextureIdMap().getOrDefault(TextureStage.DEFERRED, Object2ObjectMaps.emptyMap()),
customTextureManager.getIrisCustomTextures(),
customImages,
programSet.getPackDirectives().getExplicitFlips("deferred_pre"),
customUniforms);
flippedAfterTranslucent = flipper.snapshot();
this.compositeRenderer = new CompositeRenderer(this, programSet.getPackDirectives(), programSet.getComposite(), programSet.getCompositeCompute(), renderTargets, shaderStorageBufferHolder,
customTextureManager.getNoiseTexture(), updateNotifier, centerDepthSampler, flipper, shadowTargetsSupplier, TextureStage.COMPOSITE_AND_FINAL,
customTextureManager.getCustomTextureIdMap().getOrDefault(TextureStage.COMPOSITE_AND_FINAL, Object2ObjectMaps.emptyMap()), customTextureManager.getIrisCustomTextures(), customImages,
programSet.getPackDirectives().getExplicitFlips("composite_pre"), customUniforms);
this.compositeRenderer = new CompositeRenderer(
this,
programSet.getPackDirectives(),
programSet.getComposite(),
programSet.getCompositeCompute(),
renderTargets,
shaderStorageBufferHolder,
customTextureManager.getNoiseTexture(),
updateNotifier,
centerDepthSampler,
flipper,
shadowTargetsSupplier,
TextureStage.COMPOSITE_AND_FINAL,
customTextureManager.getCustomTextureIdMap().getOrDefault(TextureStage.COMPOSITE_AND_FINAL, Object2ObjectMaps.emptyMap()),
customTextureManager.getIrisCustomTextures(),
customImages,
programSet.getPackDirectives().getExplicitFlips("composite_pre"),
customUniforms);
this.finalPassRenderer = new FinalPassRenderer(this, programSet, renderTargets, customTextureManager.getNoiseTexture(), shaderStorageBufferHolder, updateNotifier, flipper.snapshot(),
centerDepthSampler, shadowTargetsSupplier,
customTextureManager.getCustomTextureIdMap().getOrDefault(TextureStage.COMPOSITE_AND_FINAL, Object2ObjectMaps.emptyMap()), customTextureManager.getIrisCustomTextures(), customImages,
this.compositeRenderer.getFlippedAtLeastOnceFinal(), customUniforms);
Supplier<ImmutableSet<Integer>> flipped =
() -> isBeforeTranslucent ? flippedAfterPrepare : flippedAfterTranslucent;
this.finalPassRenderer = new FinalPassRenderer(
this,
programSet,
renderTargets,
customTextureManager.getNoiseTexture(),
shaderStorageBufferHolder,
updateNotifier,
flipper.snapshot(),
centerDepthSampler,
shadowTargetsSupplier,
customTextureManager.getCustomTextureIdMap().getOrDefault(TextureStage.COMPOSITE_AND_FINAL, Object2ObjectMaps.emptyMap()),
customTextureManager.getIrisCustomTextures(),
customImages,
this.compositeRenderer.getFlippedAtLeastOnceFinal(),
customUniforms);
Supplier<ImmutableSet<Integer>> flipped = () -> isBeforeTranslucent ? flippedAfterPrepare : flippedAfterTranslucent;
IntFunction<ProgramSamplers> createTerrainSamplers = (programId) -> {
ProgramSamplers.Builder builder = ProgramSamplers.builder(programId, IrisSamplers.WORLD_RESERVED_TEXTURE_UNITS);
ProgramSamplers.CustomTextureSamplerInterceptor customTextureSamplerInterceptor = ProgramSamplers.customTextureSamplerInterceptor(builder, customTextureManager.getCustomTextureIdMap().getOrDefault(TextureStage.GBUFFERS_AND_SHADOW, Object2ObjectMaps.emptyMap()));
ProgramSamplers.CustomTextureSamplerInterceptor customTextureSamplerInterceptor = ProgramSamplers.customTextureSamplerInterceptor(
builder,
customTextureManager.getCustomTextureIdMap().getOrDefault(TextureStage.GBUFFERS_AND_SHADOW, Object2ObjectMaps.emptyMap()));
IrisSamplers.addRenderTargetSamplers(customTextureSamplerInterceptor, flipped, renderTargets, false, this);
IrisSamplers.addCustomTextures(builder, customTextureManager.getIrisCustomTextures());
@@ -569,7 +893,9 @@ public abstract class CommonIrisRenderingPipeline implements WorldRenderingPipel
IntFunction<ProgramSamplers> createShadowTerrainSamplers = (programId) -> {
ProgramSamplers.Builder builder = ProgramSamplers.builder(programId, IrisSamplers.WORLD_RESERVED_TEXTURE_UNITS);
ProgramSamplers.CustomTextureSamplerInterceptor customTextureSamplerInterceptor = ProgramSamplers.customTextureSamplerInterceptor(builder, customTextureManager.getCustomTextureIdMap().getOrDefault(TextureStage.GBUFFERS_AND_SHADOW, Object2ObjectMaps.emptyMap()));
ProgramSamplers.CustomTextureSamplerInterceptor customTextureSamplerInterceptor = ProgramSamplers.customTextureSamplerInterceptor(
builder,
customTextureManager.getCustomTextureIdMap().getOrDefault(TextureStage.GBUFFERS_AND_SHADOW, Object2ObjectMaps.emptyMap()));
IrisSamplers.addRenderTargetSamplers(customTextureSamplerInterceptor, () -> flippedBeforeShadow, renderTargets, false, this);
IrisSamplers.addCustomTextures(builder, customTextureManager.getIrisCustomTextures());
@@ -615,17 +941,18 @@ public abstract class CommonIrisRenderingPipeline implements WorldRenderingPipel
Stopwatch watch = Stopwatch.createStarted();
try {
this.shaderMap = new ShaderMap((key, syncExecutor) -> {
if (key.isShadow()) {
if (shadowRenderTargets != null) {
return createShadowShader(key.getName(), resolver.resolve(key.getProgram()), key, syncExecutor);
} else {
return CompletableFuture.completedFuture(null);
}
} else {
return createShader(key.getName(), resolver.resolve(key.getProgram()), key, syncExecutor);
}
}, getShaderKeyValues());
this.shaderMap = new ShaderMap(
(key, syncExecutor) -> {
if (key.isShadow()) {
if (shadowRenderTargets != null) {
return createShadowShader(key.getName(), resolver.resolve(key.getProgram()), key, syncExecutor);
} else {
return CompletableFuture.completedFuture(null);
}
} else {
return createShader(key.getName(), resolver.resolve(key.getProgram()), key, syncExecutor);
}
}, getShaderKeyValues());
} catch (IOException e) {
destroyShaders();
throw new RuntimeException(e);
@@ -637,7 +964,6 @@ public abstract class CommonIrisRenderingPipeline implements WorldRenderingPipel
watch.stop();
IRIS_LOGGER.info("Loaded shaders in {}", watch);
WorldRenderingSettings.INSTANCE.setEntityIds(programSet.getPack().getIdMap().getEntityIdMap());
WorldRenderingSettings.INSTANCE.setItemIds(programSet.getPack().getIdMap().getItemIdMap());
WorldRenderingSettings.INSTANCE.setAmbientOcclusionLevel(programSet.getPackDirectives().getAmbientOcclusionLevel());
@@ -657,17 +983,35 @@ public abstract class CommonIrisRenderingPipeline implements WorldRenderingPipel
this.shadowClearPasses = ClearPassCreator.createShadowClearPasses(shadowRenderTargets, false, shadowDirectives);
this.shadowClearPassesFull = ClearPassCreator.createShadowClearPasses(shadowRenderTargets, true, shadowDirectives);
this.shadowCompositeRenderer = new ShadowCompositeRenderer(this, programSet.getPackDirectives(), programSet.getShadowComposite(), programSet.getShadowCompCompute(), this.shadowRenderTargets, this.shaderStorageBufferHolder, customTextureManager.getNoiseTexture(), updateNotifier,
customTextureManager.getCustomTextureIdMap(TextureStage.SHADOWCOMP), customImages, programSet.getPackDirectives().getExplicitFlips("shadowcomp_pre"), customTextureManager.getIrisCustomTextures(), customUniforms);
this.shadowCompositeRenderer = new ShadowCompositeRenderer(
this,
programSet.getPackDirectives(),
programSet.getShadowComposite(),
programSet.getShadowCompCompute(),
this.shadowRenderTargets,
this.shaderStorageBufferHolder,
customTextureManager.getNoiseTexture(),
updateNotifier,
customTextureManager.getCustomTextureIdMap(TextureStage.SHADOWCOMP),
customImages,
programSet.getPackDirectives().getExplicitFlips("shadowcomp_pre"),
customTextureManager.getIrisCustomTextures(),
customUniforms);
if (programSet.getPackDirectives().getShadowDirectives().isShadowEnabled().orElse(true)) {
this.shadowRenderer = createShadowRenderer(this, programSet.getShadow().orElse(null),
programSet.getPackDirectives(), shadowRenderTargets, shadowCompositeRenderer, customUniforms, programSet.getPack().hasFeature(FeatureFlags.SEPARATE_HARDWARE_SAMPLERS));
this.shadowRenderer = createShadowRenderer(
this,
programSet.getShadow().orElse(null),
programSet.getPackDirectives(),
shadowRenderTargets,
shadowCompositeRenderer,
customUniforms,
programSet.getPack().hasFeature(FeatureFlags.SEPARATE_HARDWARE_SAMPLERS));
} else {
shadowRenderer = null;
}
defaultFBShadow = shadowRenderTargets.createFramebufferWritingToMain(new int[] {0});
defaultFBShadow = shadowRenderTargets.createFramebufferWritingToMain(new int[] { 0 });
} else {
this.shadowClearPasses = ImmutableList.of();
this.shadowClearPassesFull = ImmutableList.of();
@@ -675,14 +1019,23 @@ public abstract class CommonIrisRenderingPipeline implements WorldRenderingPipel
this.shadowRenderer = null;
}
// TODO: Create fallback Sodium shaders if the pack doesn't provide terrain shaders
// Currently we use Sodium's shaders but they don't support EXP2 fog underwater.
this.sodiumTerrainPipeline = new SodiumTerrainPipeline(this, programSet, createTerrainSamplers,
shadowRenderTargets == null ? null : createShadowTerrainSamplers, createTerrainImages, createShadowTerrainImages, renderTargets, flippedAfterPrepare, flippedAfterTranslucent,
shadowRenderTargets != null ? shadowRenderTargets.createShadowFramebuffer(ImmutableSet.of(), programSet.getShadow().filter(source -> !source.getDirectives().hasUnknownDrawBuffers()).map(source -> source.getDirectives().getDrawBuffers()).orElse(new int[]{0, 1})) : null, customUniforms);
this.sodiumTerrainPipeline = new SodiumTerrainPipeline(
this,
programSet,
createTerrainSamplers,
shadowRenderTargets == null ? null : createShadowTerrainSamplers,
createTerrainImages,
createShadowTerrainImages,
renderTargets,
flippedAfterPrepare,
flippedAfterTranslucent,
shadowRenderTargets != null ? shadowRenderTargets.createShadowFramebuffer(
ImmutableSet.of(),
programSet.getShadow().filter(source -> !source.getDirectives().hasUnknownDrawBuffers())
.map(source -> source.getDirectives().getDrawBuffers()).orElse(new int[] { 0, 1 })) : null,
customUniforms);
this.setup = createSetupComputes(programSet.getSetup(), programSet, TextureStage.SETUP);
@@ -690,11 +1043,9 @@ public abstract class CommonIrisRenderingPipeline implements WorldRenderingPipel
this.customUniforms.optimise();
boolean hasRun = false;
this.clearPassesFull = ClearPassCreator.createClearPasses(renderTargets, true, programSet.getPackDirectives().getRenderTargetDirectives());
this.clearPasses = ClearPassCreator.createClearPasses(renderTargets, false, programSet.getPackDirectives().getRenderTargetDirectives());
for (ComputeProgram program : setup) {
if (program != null) {
if (!hasRun) {
@@ -719,6 +1070,7 @@ public abstract class CommonIrisRenderingPipeline implements WorldRenderingPipel
if (programSet.getPackDirectives().supportsColorCorrection()) {
colorSpaceConverter = new ColorSpaceConverter() {
@Override
public void rebuildProgram(int width, int height, ColorSpace colorSpace) {
@@ -731,19 +1083,22 @@ public abstract class CommonIrisRenderingPipeline implements WorldRenderingPipel
};
} else {
// TODO: Fix grid appearing on some devices with compute converter
//if (IrisRenderSystem.supportsCompute()) {
// if (IrisRenderSystem.supportsCompute()) {
// colorSpaceConverter = new ColorSpaceComputeConverter(mcWidth, mcHeight, IrisVideoSettings.colorSpace);
//} else {
colorSpaceConverter = new ColorSpaceFragmentConverter(mainFBWidth, mainFBWidth, IrisVideoSettings.colorSpace);
//}
}
currentColorSpace = IrisVideoSettings.colorSpace;
int defaultTex = packDirectives.getFallbackTex();
defaultFB = flippedAfterPrepare.contains(defaultTex) ? renderTargets.createFramebufferWritingToAlt(new int[] { defaultTex }) : renderTargets.createFramebufferWritingToMain(new int[] { defaultTex });
defaultFBAlt = flippedAfterTranslucent.contains(defaultTex) ? renderTargets.createFramebufferWritingToAlt(new int[] { defaultTex }) : renderTargets.createFramebufferWritingToMain(new int[] { defaultTex });
defaultFB = flippedAfterPrepare.contains(defaultTex)
? renderTargets.createFramebufferWritingToAlt(new int[] { defaultTex })
: renderTargets.createFramebufferWritingToMain(new int[] { defaultTex });
defaultFBAlt = flippedAfterTranslucent.contains(defaultTex)
? renderTargets.createFramebufferWritingToAlt(new int[] { defaultTex })
: renderTargets.createFramebufferWritingToMain(new int[] { defaultTex });
blockIdsNeedPopulation = true;
}
@@ -817,7 +1172,9 @@ public abstract class CommonIrisRenderingPipeline implements WorldRenderingPipel
protected abstract void destroyHorizonRenderer();
@Nullable
protected abstract CommonShadowRenderer createShadowRenderer(CommonIrisRenderingPipeline commonIrisRenderingPipeline, ProgramSource programSource, PackDirectives packDirectives, ShadowRenderTargets shadowRenderTargets, ShadowCompositeRenderer shadowCompositeRenderer, CustomUniforms customUniforms, boolean b);
protected abstract CommonShadowRenderer createShadowRenderer(CommonIrisRenderingPipeline commonIrisRenderingPipeline, ProgramSource programSource,
PackDirectives packDirectives, ShadowRenderTargets shadowRenderTargets, ShadowCompositeRenderer shadowCompositeRenderer,
CustomUniforms customUniforms, boolean b);
protected abstract ShaderKey[] getShaderKeyValues();
@@ -827,19 +1184,19 @@ public abstract class CommonIrisRenderingPipeline implements WorldRenderingPipel
}
@Override
public WorldRenderingPhase getPhase() {
public WorldRenderingPhase getPhase() {
if (shouldRemovePhase) {
phase = WorldRenderingPhase.NONE;
shouldRemovePhase = false;
GLDebug.popGroup();
}
if (overridePhase != null) {
return overridePhase;
}
if (overridePhase != null) {
return overridePhase;
}
return phase;
}
return phase;
}
public void removePhaseIfNeeded() {
if (shouldRemovePhase) {
@@ -850,7 +1207,7 @@ public abstract class CommonIrisRenderingPipeline implements WorldRenderingPipel
}
@Override
public void setPhase(WorldRenderingPhase phase) {
public void setPhase(WorldRenderingPhase phase) {
if (phase == WorldRenderingPhase.NONE) {
if (shouldRemovePhase) GLDebug.popGroup();
shouldRemovePhase = true;
@@ -862,16 +1219,19 @@ public abstract class CommonIrisRenderingPipeline implements WorldRenderingPipel
}
}
GLDebug.popGroup();
if (phase != WorldRenderingPhase.NONE && phase != WorldRenderingPhase.TERRAIN_CUTOUT && phase != WorldRenderingPhase.TERRAIN_CUTOUT_MIPPED && phase != WorldRenderingPhase.TRIPWIRE) {
GLDebug.popGroup();
if (phase != WorldRenderingPhase.NONE
&& phase != WorldRenderingPhase.TERRAIN_CUTOUT
&& phase != WorldRenderingPhase.TERRAIN_CUTOUT_MIPPED
&& phase != WorldRenderingPhase.TRIPWIRE) {
if (ShadowRenderingState.areShadowsCurrentlyBeingRendered()) {
GLDebug.pushGroup(phase.ordinal(), "Shadow " + StringUtils.capitalize(phase.name().toLowerCase(Locale.ROOT).replace("_", " ")));
} else {
GLDebug.pushGroup(phase.ordinal(), StringUtils.capitalize(phase.name().toLowerCase(Locale.ROOT).replace("_", " ")));
}
}
this.phase = phase;
}
this.phase = phase;
}
protected void destroyShaders() {
// NB: If you forget this, shader reloads won't work!
@@ -882,9 +1242,9 @@ public abstract class CommonIrisRenderingPipeline implements WorldRenderingPipel
}
@Override
public void setOverridePhase(WorldRenderingPhase phase) {
this.overridePhase = phase;
}
public void setOverridePhase(WorldRenderingPhase phase) {
this.overridePhase = phase;
}
@Override
public int getCurrentNormalTexture() {
@@ -926,8 +1286,8 @@ public abstract class CommonIrisRenderingPipeline implements WorldRenderingPipel
TextureStage textureStage = TextureStage.SETUP;
ProgramSamplers.CustomTextureSamplerInterceptor customTextureSamplerInterceptor =
ProgramSamplers.customTextureSamplerInterceptor(builder,
ProgramSamplers.CustomTextureSamplerInterceptor customTextureSamplerInterceptor = ProgramSamplers.customTextureSamplerInterceptor(
builder,
customTextureManager.getCustomTextureIdMap(textureStage));
IrisSamplers.addRenderTargetSamplers(customTextureSamplerInterceptor, flipped, renderTargets, true, this);
@@ -946,16 +1306,17 @@ public abstract class CommonIrisRenderingPipeline implements WorldRenderingPipel
}
}
programs[i] = builder.buildCompute();
this.customUniforms.mapholderToPass(builder, programs[i]);
programs[i].setWorkGroupInfo(source.getWorkGroupRelative(), source.getWorkGroups(), FilledIndirectPointer.basedOff(shaderStorageBufferHolder, source.getIndirectPointer()));
programs[i].setWorkGroupInfo(
source.getWorkGroupRelative(),
source.getWorkGroups(),
FilledIndirectPointer.basedOff(shaderStorageBufferHolder, source.getIndirectPointer()));
}
}
return programs;
}
@@ -973,7 +1334,11 @@ public abstract class CommonIrisRenderingPipeline implements WorldRenderingPipel
ProgramBuilder builder;
try {
String transformed = TransformPatcherBridge.patchCompute(source.getName(), source.getSource().orElse(null), TextureStage.GBUFFERS_AND_SHADOW, getTextureMap());
String transformed = TransformPatcherBridge.patchCompute(
source.getName(),
source.getSource().orElse(null),
TextureStage.GBUFFERS_AND_SHADOW,
getTextureMap());
ShaderPrinter.printProgram(source.getName()).addSource(PatchShaderType.COMPUTE, transformed).print();
@@ -994,8 +1359,8 @@ public abstract class CommonIrisRenderingPipeline implements WorldRenderingPipel
TextureStage textureStage = TextureStage.GBUFFERS_AND_SHADOW;
ProgramSamplers.CustomTextureSamplerInterceptor customTextureSamplerInterceptor =
ProgramSamplers.customTextureSamplerInterceptor(builder,
ProgramSamplers.CustomTextureSamplerInterceptor customTextureSamplerInterceptor = ProgramSamplers.customTextureSamplerInterceptor(
builder,
customTextureManager.getCustomTextureIdMap(textureStage));
IrisSamplers.addRenderTargetSamplers(customTextureSamplerInterceptor, flipped, renderTargets, false, this);
@@ -1019,30 +1384,47 @@ public abstract class CommonIrisRenderingPipeline implements WorldRenderingPipel
this.customUniforms.mapholderToPass(builder, programs[i]);
programs[i].setWorkGroupInfo(source.getWorkGroupRelative(), source.getWorkGroups(), FilledIndirectPointer.basedOff(shaderStorageBufferHolder, source.getIndirectPointer()));
programs[i].setWorkGroupInfo(
source.getWorkGroupRelative(),
source.getWorkGroups(),
FilledIndirectPointer.basedOff(shaderStorageBufferHolder, source.getIndirectPointer()));
}
}
return programs;
}
protected CompletableFuture<MCShaderInstance> createShader(String name, Optional<ProgramSource> source, ShaderKey key, Executor syncExecutor) throws IOException {
protected CompletableFuture<MCShaderInstance> createShader(String name, Optional<ProgramSource> source, ShaderKey key, Executor syncExecutor)
throws IOException {
if (!source.isPresent()) {
return CompletableFuture.completedFuture(createFallbackShader(name, key));
}
return createShader(name, syncExecutor, source.get(), key.getProgram(), key.getAlphaTest(), key.getVertexFormat(), key.getFogMode(),
key.isIntensity(), key.shouldIgnoreLightmap(), key.isGlint(), key.isText());
return createShader(
name,
syncExecutor,
source.get(),
key.getProgram(),
key.getAlphaTest(),
key.getVertexFormat(),
key.getFogMode(),
key.isIntensity(),
key.shouldIgnoreLightmap(),
key.isGlint(),
key.isText());
}
protected abstract CompletableFuture<MCShaderInstance> createShader(String name, Executor syncExecutor, ProgramSource source, ProgramId programId,
AlphaTest fallbackAlpha, MCVertexFormat vertexFormat, FogMode fogMode, boolean isIntensity, boolean isFullbright, boolean isGlint, boolean isText)
throws IOException;
protected abstract CompletableFuture<MCShaderInstance> createShader(String name, Executor syncExecutor, ProgramSource source, ProgramId programId, AlphaTest fallbackAlpha,
MCVertexFormat vertexFormat, FogMode fogMode,
boolean isIntensity, boolean isFullbright, boolean isGlint, boolean isText) throws IOException;
protected abstract MCShaderInstance createFallbackShader(String name, ShaderKey key) throws IOException;
protected abstract CompletableFuture<MCShaderInstance> createShadowShader(String name, Optional<ProgramSource> source, ShaderKey key, Executor syncExecutor) throws IOException;
protected abstract CompletableFuture<MCShaderInstance> createShadowShader(String name, Optional<ProgramSource> source, ShaderKey key, Executor syncExecutor)
throws IOException;
protected abstract MCShaderInstance createFallbackShadowShader(String name, ShaderKey key) throws IOException;
protected abstract CompletableFuture<MCShaderInstance> createShadowShader(String name, Executor syncExecutor, ProgramSource source, ProgramId programId, AlphaTest fallbackAlpha,
MCVertexFormat vertexFormat, boolean isIntensity, boolean isFullbright, boolean isText) throws IOException;
protected abstract CompletableFuture<MCShaderInstance> createShadowShader(String name, Executor syncExecutor, ProgramSource source, ProgramId programId,
AlphaTest fallbackAlpha, MCVertexFormat vertexFormat, boolean isIntensity, boolean isFullbright, boolean isText) throws IOException;
}
@@ -1,5 +1,6 @@
package org.embeddedt.embeddium.compat.mc;
import net.irisshaders.iris.shaderpack.ShaderPack;
import org.joml.Matrix4f;
import org.joml.Vector2i;
import org.joml.Vector3d;
@@ -138,4 +139,10 @@ public interface MinecraftVersionShimService {
MCTextureManager getTextureManager();
MCResourceManager getResourceManager();
void populateBlockIds(ShaderPack pack);
default boolean isSkyTypeNormal() {
return true;
}
}
@@ -103,13 +103,9 @@ public class ArchaicIrisRenderingPipeline extends CommonIrisRenderingPipeline im
}
@Override
public void beginLevelRendering() {
}
@Override
public void renderShadows(MCLevelRenderer worldRenderer, MCCamera camera) {
protected void renderHorizon() {
// TODO
throw new UnsupportedOperationException("renderHorizon");
}
@Override
@@ -2,6 +2,7 @@ package org.embeddedt.embeddium.impl;
import cpw.mods.fml.common.Loader;
import net.irisshaders.iris.IrisCommon;
import net.irisshaders.iris.shaderpack.ShaderPack;
import net.irisshaders.iris.uniforms.CapturedRenderingState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.WorldClient;
@@ -564,6 +565,11 @@ public class MinecraftArchaicVersionShimImpl implements MinecraftVersionShimServ
return (MCResourceManager) Minecraft.getMinecraft().getResourceManager();
}
@Override
public void populateBlockIds(ShaderPack pack) {
// TODO
}
@Override
public boolean isLoadValid() {
return true;
@@ -6,40 +6,23 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.function.Supplier;
import static com.mitchej123.glsm.GLStateManagerService.GL_STATE_MANAGER;
import static com.mitchej123.glsm.RenderSystemService.RENDER_SYSTEM;
import static org.embeddedt.embeddium.compat.mc.MinecraftVersionShimService.MINECRAFT_SHIM;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.mojang.blaze3d.pipeline.RenderTarget;
import com.mojang.blaze3d.systems.RenderSystem;
import it.unimi.dsi.fastutil.objects.Object2ObjectMaps;
import net.irisshaders.iris.IrisCommon;
import net.irisshaders.iris.gl.blending.AlphaTest;
import net.irisshaders.iris.gl.blending.BlendModeOverride;
import net.irisshaders.iris.gl.framebuffer.GlFramebuffer;
import net.irisshaders.iris.gl.image.GlImage;
import net.irisshaders.iris.gl.image.ImageHolder;
import net.irisshaders.iris.gl.program.ComputeProgram;
import net.irisshaders.iris.gl.program.ProgramSamplers;
import net.irisshaders.iris.gl.sampler.SamplerHolder;
import net.irisshaders.iris.gl.state.FogMode;
import net.irisshaders.iris.gl.state.ShaderAttributeInputs;
import net.irisshaders.iris.gl.state.ShaderAttributeInputsBuilder;
import net.irisshaders.iris.gl.texture.DepthBufferFormat;
import net.irisshaders.iris.gui.option.IrisVideoSettings;
import net.irisshaders.iris.helpers.OptionalBoolean;
import net.irisshaders.iris.mixin.GlStateManagerAccessor;
import net.irisshaders.iris.pathways.HorizonRenderer;
import net.irisshaders.iris.pipeline.programs.*;
import net.irisshaders.iris.samplers.IrisImages;
import net.irisshaders.iris.samplers.IrisSamplers;
import net.irisshaders.iris.shaderpack.loading.ProgramId;
import net.irisshaders.iris.shaderpack.materialmap.BlockMaterialMapping;
import net.irisshaders.iris.shaderpack.materialmap.ModelTextureAnalyzer;
import net.irisshaders.iris.shaderpack.materialmap.ModernWorldRenderingSettings;
import net.irisshaders.iris.shaderpack.materialmap.WorldRenderingSettings;
import net.irisshaders.iris.shaderpack.programs.ProgramSet;
import net.irisshaders.iris.shaderpack.programs.ProgramSource;
import net.irisshaders.iris.shaderpack.properties.PackDirectives;
@@ -49,28 +32,27 @@ import net.irisshaders.iris.shadows.ShadowCompositeRenderer;
import net.irisshaders.iris.shadows.ModernShadowRenderer;
import net.irisshaders.iris.shadows.ShadowRenderTargets;
import net.irisshaders.iris.targets.*;
import net.irisshaders.iris.texture.TextureInfoCache;
import net.irisshaders.iris.texture.format.TextureFormat;
import net.irisshaders.iris.texture.format.TextureFormatLoader;
import net.irisshaders.iris.texture.pbr.PBRTextureHolder;
import net.irisshaders.iris.texture.pbr.PBRTextureManager;
import net.irisshaders.iris.texture.pbr.PBRType;
import net.irisshaders.iris.uniforms.CapturedRenderingState;
import net.irisshaders.iris.uniforms.custom.CustomUniforms;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.DimensionSpecialEffects;
import net.minecraft.client.renderer.GameRenderer;
import org.embeddedt.embeddium.compat.mc.*;
import org.embeddedt.embeddium.impl.gl.debug.GLDebug;
import org.jetbrains.annotations.Nullable;
import org.joml.Vector3d;
import org.joml.Vector4f;
import org.lwjgl.opengl.*;
public class ModernIrisRenderingPipeline extends CommonIrisRenderingPipeline implements IrisRenderingPipeline, WorldRenderingPipeline, ShaderRenderingPipeline, RenderTargetStateListener {
private final HorizonRenderer horizonRenderer = new HorizonRenderer();
private final int stackSize = 0;
@Override
protected void renderHorizon() {
// TODO: Pull HorizonRenderer into common-shaders and pull this up
horizonRenderer.renderHorizon(
CapturedRenderingState.INSTANCE.getGbufferModelView(),
CapturedRenderingState.INSTANCE.getGbufferProjection(),
GameRenderer.getPositionShader());
}
@Override
protected void updateMCFBInfo() {
RenderTarget main = Minecraft.getInstance().getMainRenderTarget();
@@ -233,203 +215,6 @@ public class ModernIrisRenderingPipeline extends CommonIrisRenderingPipeline imp
return this;
}
@Override
public void onSetShaderTexture(int id) {
if (shouldBindPBR && isRenderingWorld) {
PBRTextureHolder pbrHolder = PBRTextureManager.INSTANCE.getOrLoadHolder(id);
currentNormalTexture = pbrHolder.normalTexture().getId();
currentSpecularTexture = pbrHolder.specularTexture().getId();
TextureFormat textureFormat = TextureFormatLoader.getFormat();
if (textureFormat != null) {
int previousBinding = GlStateManagerAccessor.getTEXTURES()[GlStateManagerAccessor.getActiveTexture()].binding;
textureFormat.setupTextureParameters(PBRType.NORMAL, pbrHolder.normalTexture());
textureFormat.setupTextureParameters(PBRType.SPECULAR, pbrHolder.specularTexture());
GL_STATE_MANAGER.bindTexture(previousBinding);
}
PBRTextureManager.notifyPBRTexturesChanged();
}
}
@Override
public void beginLevelRendering() {
isRenderingWorld = true;
if (blockIdsNeedPopulation) {
ModernWorldRenderingSettings.INSTANCE.setBlockStateIds(
BlockMaterialMapping.createBlockStateIdMap(pack.getIdMap().getBlockProperties()));
ModernWorldRenderingSettings.INSTANCE.setBlockTypeIds(BlockMaterialMapping.createBlockTypeMap(pack.getIdMap().getBlockRenderTypeMap()));
if (IrisCommon.getIrisConfig().isEnableTextureMaterialFallback()) {
ModernWorldRenderingSettings.INSTANCE.setFallbackTextureMaterialMapping(ModelTextureAnalyzer.runAnalysisSync(ModernWorldRenderingSettings.INSTANCE.getBlockStateIds()));
} else {
ModernWorldRenderingSettings.INSTANCE.setFallbackTextureMaterialMapping(null);
}
WorldRenderingSettings.INSTANCE.reloadRendererIfRequired();
blockIdsNeedPopulation = false;
}
// Make sure we're using texture unit 0 for this.
RENDER_SYSTEM.glActiveTexture(GL15C.GL_TEXTURE0);
Vector4f emptyClearColor = new Vector4f(1.0F);
GLDebug.pushGroup(100, "Clear textures");
for (GlImage image : clearImages) {
ARBClearTexture.glClearTexImage(image.getId(), 0, image.getFormat().getGlFormat(), image.getPixelType().getGlFormat(), (int[]) null);
}
if (hasShadowRenderTargets()) {
if (packDirectives.getShadowDirectives().isShadowEnabled() == OptionalBoolean.FALSE) {
if (shadowRenderTargets.isFullClearRequired()) {
this.shadowClearPasses = ClearPassCreator.createShadowClearPasses(shadowRenderTargets, false, shadowDirectives);
this.shadowClearPassesFull = ClearPassCreator.createShadowClearPasses(shadowRenderTargets, true, shadowDirectives);
shadowRenderTargets.onFullClear();
for (ClearPass clearPass : shadowClearPassesFull) {
clearPass.execute(emptyClearColor);
}
}
} else {
// Clear depth first, regardless of any color clearing.
shadowRenderTargets.getDepthSourceFb().bind();
RENDER_SYSTEM.clear(GL21C.GL_DEPTH_BUFFER_BIT, Minecraft.ON_OSX);
ImmutableList<ClearPass> passes;
for (ComputeProgram computeProgram : shadowComputes) {
if (computeProgram != null) {
computeProgram.use();
getCustomUniforms().push(computeProgram);
computeProgram.dispatch(shadowMapResolution, shadowMapResolution);
}
}
if (shadowRenderTargets.isFullClearRequired()) {
this.shadowClearPasses = ClearPassCreator.createShadowClearPasses(shadowRenderTargets, false, shadowDirectives);
this.shadowClearPassesFull = ClearPassCreator.createShadowClearPasses(shadowRenderTargets, true, shadowDirectives);
passes = shadowClearPassesFull;
shadowRenderTargets.onFullClear();
} else {
passes = shadowClearPasses;
}
for (ClearPass clearPass : passes) {
clearPass.execute(emptyClearColor);
}
}
}
// NB: execute this before resizing / clearing so that the center depth sample is retrieved properly.
getFrameUpdateNotifier().onNewFrame();
// Update custom uniforms
this.getCustomUniforms().update();
this.updateMCFBInfo();
int internalFormat = TextureInfoCache.INSTANCE.getInfo(mainFBDepthTextureId).getInternalFormat();
DepthBufferFormat depthBufferFormat = DepthBufferFormat.fromGlEnumOrDefault(internalFormat);
boolean changed = renderTargets.resizeIfNeeded(
mainFBDepthBufferVersion, mainFBDepthTextureId, mainFBWidth,
mainFBHeight, depthBufferFormat, packDirectives);
if (changed) {
beginRenderer.recalculateSizes();
prepareRenderer.recalculateSizes();
deferredRenderer.recalculateSizes();
compositeRenderer.recalculateSizes();
finalPassRenderer.recalculateSwapPassSize();
if (shaderStorageBufferHolder != null) {
shaderStorageBufferHolder.hasResizedScreen(mainFBWidth, mainFBHeight);
}
customImages.forEach(image -> image.updateNewSize(mainFBWidth, mainFBHeight));
this.clearPassesFull.forEach(clearPass -> renderTargets.destroyFramebuffer(clearPass.getFramebuffer()));
this.clearPasses.forEach(clearPass -> renderTargets.destroyFramebuffer(clearPass.getFramebuffer()));
this.clearPassesFull = ClearPassCreator.createClearPasses(renderTargets, true,
packDirectives.getRenderTargetDirectives());
this.clearPasses = ClearPassCreator.createClearPasses(renderTargets, false,
packDirectives.getRenderTargetDirectives());
}
if (changed || IrisVideoSettings.colorSpace != currentColorSpace) {
currentColorSpace = IrisVideoSettings.colorSpace;
colorSpaceConverter.rebuildProgram(mainFBWidth, mainFBHeight, currentColorSpace);
}
final ImmutableList<ClearPass> passes;
if (renderTargets.isFullClearRequired()) {
renderTargets.onFullClear();
passes = clearPassesFull;
} else {
passes = clearPasses;
}
Vector3d fogColor3 = CapturedRenderingState.INSTANCE.getFogColor();
// NB: The alpha value must be 1.0 here, or else you will get a bunch of bugs. Sildur's Vibrant Shaders
// will give you pink reflections and other weirdness if this is zero.
Vector4f fogColor = new Vector4f((float) fogColor3.x, (float) fogColor3.y, (float) fogColor3.z, 1.0F);
for (ClearPass clearPass : passes) {
clearPass.execute(fogColor);
}
GLDebug.popGroup();
// Make sure to switch back to the main framebuffer. If we forget to do this then our alt buffers might be
// cleared to the fog color, which absolutely is not what we want!
//
// If we forget to do this, then weird lines appear at the top of the screen and the right of the screen
// on Sildur's Vibrant Shaders.
MINECRAFT_SHIM.bindMainFramebuffer();
setIsMainBound(true);
if (changed) {
boolean hasRun = false;
for (ComputeProgram program : setup) {
if (program != null) {
hasRun = true;
program.use();
program.dispatch(1, 1);
}
}
if (hasRun) {
ComputeProgram.unbind();
}
}
isBeforeTranslucent = true;
beginRenderer.renderAll();
setPhase(WorldRenderingPhase.SKY);
// Render our horizon box before actual sky rendering to avoid being broken by mods that do weird things
// while rendering the sky.
//
// A lot of dimension mods touch sky rendering, FabricSkyboxes injects at HEAD and cancels, etc.
DimensionSpecialEffects.SkyType skyType = Minecraft.getInstance().level.effects().skyType();
if (skyType == DimensionSpecialEffects.SkyType.NORMAL) {
RENDER_SYSTEM.depthMask(false);
RENDER_SYSTEM.setShaderColor(fogColor.x, fogColor.y, fogColor.z, fogColor.w);
horizonRenderer.renderHorizon(CapturedRenderingState.INSTANCE.getGbufferModelView(), CapturedRenderingState.INSTANCE.getGbufferProjection(), GameRenderer.getPositionShader());
RENDER_SYSTEM.depthMask(true);
RENDER_SYSTEM.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
}
}
@Override
public void addDebugText(List<String> messages) {
if (this.shadowRenderer != null) {
@@ -441,35 +226,4 @@ public class ModernIrisRenderingPipeline extends CommonIrisRenderingPipeline imp
}
}
@Override
public void beginTranslucents() {
if (destroyed) {
throw new IllegalStateException("Tried to use a destroyed world rendering pipeline");
}
removePhaseIfNeeded();
isBeforeTranslucent = false;
// We need to copy the current depth texture so that depthtex1 can contain the depth values for
// all non-translucent content, as required.
renderTargets.copyPreTranslucentDepth();
deferredRenderer.renderAll();
RENDER_SYSTEM.enableBlend();
// note: we are careful not to touch the lightmap texture unit or overlay color texture unit here,
// so we don't need to do anything to restore them if needed.
//
// Previous versions of the code tried to "restore" things by enabling the lightmap & overlay color
// but that actually broke rendering of clouds and rain by making them appear red in the case of
// a pack not overriding those shader programs.
//
// Not good!
// Reset shader or whatever...
RenderSystem.setShader(GameRenderer::getPositionShader);
}
}
@@ -4,11 +4,16 @@ package org.embeddedt.embeddium.impl;
import com.mojang.blaze3d.platform.NativeImage;
import com.mojang.math.Axis;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.IrisCommon;
import net.irisshaders.iris.helpers.JomlConversions;
import net.irisshaders.iris.mixin.GlStateManagerAccessor;
import net.irisshaders.iris.mixin.LightTextureAccessor;
import net.irisshaders.iris.mixin.texture.TextureAtlasAccessor;
import net.irisshaders.iris.shaderpack.DimensionId;
import net.irisshaders.iris.shaderpack.ShaderPack;
import net.irisshaders.iris.shaderpack.materialmap.BlockMaterialMapping;
import net.irisshaders.iris.shaderpack.materialmap.ModelTextureAnalyzer;
import net.irisshaders.iris.shaderpack.materialmap.ModernWorldRenderingSettings;
import net.irisshaders.iris.shadows.ShadowMatrices;
import net.irisshaders.iris.shadows.ModernShadowRenderer;
import net.irisshaders.iris.targets.Blaze3dRenderTargetExt;
@@ -19,6 +24,7 @@ import net.irisshaders.iris.uniforms.CapturedRenderingState;
import net.minecraft.Util;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.renderer.DimensionSpecialEffects;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.client.renderer.texture.MissingTextureAtlasSprite;
@@ -722,4 +728,21 @@ public class MinecraftModernVersionShimImpl implements MinecraftVersionShimServi
return (MCResourceManager) Minecraft.getInstance().getResourceManager();
}
@Override
public void populateBlockIds(ShaderPack pack) {
ModernWorldRenderingSettings.INSTANCE.setBlockStateIds(BlockMaterialMapping.createBlockStateIdMap(pack.getIdMap().getBlockProperties()));
ModernWorldRenderingSettings.INSTANCE.setBlockTypeIds(BlockMaterialMapping.createBlockTypeMap(pack.getIdMap().getBlockRenderTypeMap()));
if (IrisCommon.getIrisConfig().isEnableTextureMaterialFallback()) {
ModernWorldRenderingSettings.INSTANCE.setFallbackTextureMaterialMapping(ModelTextureAnalyzer.runAnalysisSync(ModernWorldRenderingSettings.INSTANCE.getBlockStateIds()));
} else {
ModernWorldRenderingSettings.INSTANCE.setFallbackTextureMaterialMapping(null);
}
}
@Override
public boolean isSkyTypeNormal() {
DimensionSpecialEffects.SkyType skyType = Minecraft.getInstance().level.effects().skyType();
return skyType == DimensionSpecialEffects.SkyType.NORMAL;
}
}
@@ -6,6 +6,7 @@ import com.mitchej123.glsm.RenderSystemService;
import com.mojang.blaze3d.shaders.FogShape;
import com.mojang.blaze3d.systems.RenderSystem;
import net.irisshaders.iris.mixin.GlStateManagerAccessor;
import net.minecraft.client.renderer.GameRenderer;
import org.embeddedt.embeddium.compat.BooleanStateExtended;
import org.joml.Matrix4f;
@@ -159,4 +160,9 @@ public class RenderSystemImpl implements RenderSystemService {
public void setProjectionMatrixOrigin(Matrix4f projectionMatrix) {
RenderSystem.setProjectionMatrix(projectionMatrix/*? if >=1.20 {*/, com.mojang.blaze3d.vertex.VertexSorting.DISTANCE_TO_ORIGIN/*?}*/);
}
@Override
public void setPositionShader() {
RenderSystem.setShader(GameRenderer::getPositionShader);
}
}