Skip to content

Commit

Permalink
Make SodiumTerrainPipeline be attached to the WorldRenderingPipeline
Browse files Browse the repository at this point in the history
This allows for reloading of shaders without reloading chunks when Sodium is installed.
  • Loading branch information
coderbot16 committed Jun 17, 2021
1 parent 5912ff4 commit 515b1cf
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 21 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ minecraft_version=1.16.5
yarn_mappings=1.16.5+build.6
loader_version=0.11.3
# Mod Properties
mod_version=1.0.1
mod_version=1.0.2
maven_group=net.coderbot.iris_mc1_16_5
archives_base_name=iris-mc1.16.5

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/coderbot/iris/Iris.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public void onInitializeClient() {

// A lot of people are reporting visual bugs with Iris + Sodium. This makes it so that if we don't have
// the right fork of Sodium, it will just crash.
if (!versionString.startsWith("0.2.0+IRIS")) {
throw new IllegalStateException("You do not have a compatible version of Sodium installed! You have " + versionString + " but 0.2.0_IRIS-SNAPSHOT is expected");
if (!versionString.startsWith("0.2.0+IRIS2")) {
throw new IllegalStateException("You do not have a compatible version of Sodium installed! You have " + versionString + " but 0.2.0+IRIS2 is expected");
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ public class MixinWorldRenderer {
private void iris$beginWorldRender(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f matrix4f, CallbackInfo callback) {
CapturedRenderingState.INSTANCE.setGbufferModelView(matrices.peek().getModel());
CapturedRenderingState.INSTANCE.setTickDelta(tickDelta);
pipeline = Iris.getPipelineManager().preparePipeline(Iris.getCurrentDimension(), true);
if (pipeline instanceof DeferredWorldRenderingPipeline) {
((DeferredWorldRenderingPipeline) pipeline).getUpdateNotifier().onNewFrame();
}
pipeline = Iris.getPipelineManager().preparePipeline(Iris.getCurrentDimension());

pipeline.beginWorldRendering();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline {
private final ImmutableSet<Integer> flippedBeforeTranslucent;
private final ImmutableSet<Integer> flippedAfterTranslucent;

private final SodiumTerrainPipeline sodiumTerrainPipeline;

private boolean isBeforeTranslucent;

private final int waterId;
Expand Down Expand Up @@ -197,6 +199,8 @@ public DeferredWorldRenderingPipeline(ProgramSet programs) {
} else {
this.shadowMapRenderer = new EmptyShadowMapRenderer(programs.getPackDirectives().getShadowDirectives().getResolution());
}

this.sodiumTerrainPipeline = new SodiumTerrainPipeline(programs);
}

private void checkWorld() {
Expand Down Expand Up @@ -691,6 +695,8 @@ public void beginWorldRendering() {
throw new IllegalStateException("Program stack before the start of rendering, something has gone very wrong!");
}

updateNotifier.onNewFrame();

// Get ready for world rendering
prepareRenderTargets();

Expand Down Expand Up @@ -724,6 +730,11 @@ public void finalizeWorldRendering() {
finalPassRenderer.renderFinalPass(shadowMapRenderer);
}

@Override
public SodiumTerrainPipeline getSodiumTerrainPipeline() {
return sodiumTerrainPipeline;
}

private boolean isRenderingShadow = false;

public void beginShadowRender() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ public void finalizeWorldRendering() {
// stub: nothing to do here
}

@Override
public void destroy() {
// stub: nothing to do here
}

@Override
public SodiumTerrainPipeline getSodiumTerrainPipeline() {
// no shaders to override
return null;
}

@Override
public boolean shouldDisableVanillaEntityShadows() {
return false;
Expand Down
20 changes: 14 additions & 6 deletions src/main/java/net/coderbot/iris/pipeline/PipelineManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ public class PipelineManager {
private static PipelineManager instance;
private final Function<DimensionId, WorldRenderingPipeline> pipelineFactory;
private WorldRenderingPipeline pipeline;
private boolean sodiumShaderReloadNeeded;
private DimensionId lastDimension;

public PipelineManager(Function<DimensionId, WorldRenderingPipeline> pipelineFactory) {
this.pipelineFactory = pipelineFactory;
}

public WorldRenderingPipeline preparePipeline(DimensionId currentDimension, boolean allowReloadRenderer) {
public WorldRenderingPipeline preparePipeline(DimensionId currentDimension) {
if (currentDimension != lastDimension) {
Iris.logger.info("Reloading shaderpack on dimension change (" + lastDimension + " -> " + currentDimension + ")");

Expand All @@ -35,15 +36,15 @@ public WorldRenderingPipeline preparePipeline(DimensionId currentDimension, bool
SystemTimeUniforms.TIMER.reset();

pipeline = pipelineFactory.apply(lastDimension);
sodiumShaderReloadNeeded = true;

// If Sodium is loaded, we need to reload the world renderer to properly recreate the ChunkRenderBackend
// Otherwise, the terrain shaders won't be changed properly.
// We also need to re-render all of the chunks if there is a change in the directional shading setting,
// ID mapping, or separateAo setting.
//
// TODO: Don't trigger a reload if this is the first time the world is being rendered
if (allowReloadRenderer && (FabricLoader.getInstance().isModLoaded("sodium") ||
BlockRenderingSettings.INSTANCE.isReloadRequired())) {
if (BlockRenderingSettings.INSTANCE.isReloadRequired()) {
MinecraftClient.getInstance().worldRenderer.reload();
BlockRenderingSettings.INSTANCE.clearReloadRequired();
}
Expand All @@ -56,6 +57,14 @@ public WorldRenderingPipeline getPipeline() {
return pipeline;
}

public boolean isSodiumShaderReloadNeeded() {
return sodiumShaderReloadNeeded;
}

public void clearSodiumShaderReloadNeeded() {
sodiumShaderReloadNeeded = false;
}

public void setAsInstance() {
if (instance != null) {
throw new IllegalStateException("Multiple pipeline managers active at one time");
Expand Down Expand Up @@ -93,9 +102,8 @@ public void destroyPipeline() {
// Destroy the old world rendering pipeline
//
// This destroys all loaded shader programs and all of the render targets.
if (pipeline instanceof DeferredWorldRenderingPipeline) {
// TODO: Don't cast this to DeferredWorldRenderingPipeline?
((DeferredWorldRenderingPipeline) pipeline).destroy();
if (pipeline != null) {
pipeline.destroy();
}

pipeline = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,6 @@ private static String transformFragmentShader(String base) {
return transformations.toString();
}

public static Optional<SodiumTerrainPipeline> create() {
Iris.getPipelineManager().preparePipeline(Iris.getCurrentDimension(), false);

return Iris.getCurrentPack().map(
pack -> new SodiumTerrainPipeline(Objects.requireNonNull(pack.getProgramSet(Iris.getCurrentDimension())))
);
}

public Optional<String> getTerrainVertexShaderSource() {
return Optional.ofNullable(terrainVertex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public interface WorldRenderingPipeline {
void pushProgram(GbufferProgram program);
void popProgram(GbufferProgram program);
void finalizeWorldRendering();
void destroy();

SodiumTerrainPipeline getSodiumTerrainPipeline();

boolean shouldDisableVanillaEntityShadows();
boolean shouldDisableDirectionalShading();
Expand Down

0 comments on commit 515b1cf

Please sign in to comment.