Skip to content

Commit

Permalink
Add dhClouds setting and multiple fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Jul 30, 2024
1 parent 4829b5e commit 77e3c8e
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.irisshaders.iris.gl.texture.DepthCopyStrategy;
import net.irisshaders.iris.pipeline.IrisRenderingPipeline;
import net.irisshaders.iris.shaderpack.programs.ProgramSource;
import net.irisshaders.iris.shaderpack.properties.CloudSetting;
import net.irisshaders.iris.targets.Blaze3dRenderTargetExt;
import net.irisshaders.iris.targets.DepthTexture;
import net.irisshaders.iris.uniforms.CapturedRenderingState;
Expand Down Expand Up @@ -168,6 +169,9 @@ public void reconnectDHTextures(int depthTex) {
if (dhWaterFramebuffer != null) {
dhWaterFramebuffer.addDepthAttachment(depthTex);
}
if (dhGenericFramebuffer != null) {
dhGenericFramebuffer.addDepthAttachment(depthTex);
}
}
}

Expand Down Expand Up @@ -281,4 +285,8 @@ public int getDepthTexNoTranslucent() {
public IDhApiGenericObjectShaderProgram getGenericShader() {
return genericShader;
}

public boolean avoidRenderingClouds() {
return pipeline.getDHCloudSetting() == CloudSetting.OFF || (pipeline.getDHCloudSetting() == CloudSetting.DEFAULT && pipeline.getCloudSetting() == CloudSetting.OFF);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import net.minecraft.client.Minecraft;
import org.joml.Matrix3f;
import org.joml.Matrix4f;
import org.lwjgl.opengl.GL30C;
import org.lwjgl.opengl.GL32;
import org.lwjgl.opengl.GL32C;
import org.lwjgl.opengl.GL43;
Expand Down Expand Up @@ -69,6 +70,8 @@ public class IrisGenericRenderProgram implements IDhApiGenericObjectShaderProgra
private final int instancedShaderCameraSubChunkPosUniform;
private final int instancedShaderProjectionModelViewMatrixUniform;
private final int va;
private final int uBlockLight;
private final int uSkyLight;

// This will bind AbstractVertexAttribute
private IrisGenericRenderProgram(String name, boolean isShadowPass, boolean translucent, BlendModeOverride override, BufferBlendOverride[] bufferBlendOverrides, String vertex, String tessControl, String tessEval, String geometry, String fragment, CustomUniforms customUniforms, IrisRenderingPipeline pipeline) {
Expand Down Expand Up @@ -151,6 +154,8 @@ private IrisGenericRenderProgram(String name, boolean isShadowPass, boolean tran
this.instancedShaderCameraChunkPosUniform = this.tryGetUniformLocation2("uCameraPosChunk");
this.instancedShaderCameraSubChunkPosUniform = this.tryGetUniformLocation2("uCameraPosSubChunk");
this.instancedShaderProjectionModelViewMatrixUniform = this.tryGetUniformLocation2("uProjectionMvm");
this.uBlockLight = this.tryGetUniformLocation2("uBlockLight");
this.uSkyLight = this.tryGetUniformLocation2("uSkyLight");
}

public static IrisGenericRenderProgram createProgram(String name, boolean isShadowPass, boolean translucent, ProgramSource source, CustomUniforms uniforms, IrisRenderingPipeline pipeline) {
Expand Down Expand Up @@ -278,7 +283,8 @@ public void free() {

public void fillIndirectUniformData(DhApiRenderParam dhApiRenderParam, DhApiRenderableBoxGroupShading dhApiRenderableBoxGroupShading, IDhApiRenderableBoxGroup boxGroup, DhApiVec3d camPos) {
bind(dhApiRenderParam);

RenderSystem.enableDepthTest();
RenderSystem.depthFunc(GL30C.GL_LEQUAL);
this.setUniform(this.instancedShaderOffsetChunkUniform,
new DhApiVec3i(
getChunkPosFromDouble(boxGroup.getOriginBlockPos().x),
Expand All @@ -304,6 +310,11 @@ public void fillIndirectUniformData(DhApiRenderParam dhApiRenderParam, DhApiRend
getSubChunkPosFromDouble(camPos.y),
getSubChunkPosFromDouble(camPos.z)
));
this.setUniform(this.uBlockLight,
boxGroup.getBlockLight());
this.setUniform(this.uSkyLight,
boxGroup.getSkyLight());

}

@Override
Expand All @@ -320,6 +331,10 @@ private Matrix4f toJOML(DhApiMat4f mat4f) {
return new Matrix4f().setTransposed(mat4f.getValuesAsArray());
}

private void setUniform(int index, int value) {
GL43C.glUniform1i(index, value);
}

private void setUniform(int index, float value) {
GL43C.glUniform1f(index, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeApplyShaderRenderEvent;
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeBufferRenderEvent;
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeDeferredRenderEvent;
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeGenericObjectRenderEvent;
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeGenericRenderSetupEvent;
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeRenderCleanupEvent;
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeRenderEvent;
Expand Down Expand Up @@ -116,7 +117,19 @@ public void beforeSetup(DhApiEventParam<DhApiRenderParam> dhApiEventParam) {
}
};

DhApiBeforeGenericObjectRenderEvent beforeDrawEvent = new DhApiBeforeGenericObjectRenderEvent() {
@Override
public void beforeRender(DhApiCancelableEventParam<EventParam> dhApiCancelableEventParam) {
if (dhApiCancelableEventParam.value.resourceLocationPath.equalsIgnoreCase("Clouds")) {
if (getInstance().avoidRenderingClouds()) {
dhApiCancelableEventParam.cancelEvent();
}
}
}
};

DhApi.events.bind(DhApiBeforeGenericRenderSetupEvent.class, beforeRenderEvent);
DhApi.events.bind(DhApiBeforeGenericObjectRenderEvent.class, beforeDrawEvent);
}

private static DHCompatInternal getInstance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ public class IrisRenderingPipeline implements WorldRenderingPipeline, ShaderRend
private final DHCompat dhCompat;
private final int stackSize = 0;
private final boolean skipAllRendering;
private final CloudSetting dhCloudSetting;
private boolean initializedBlockIds;
public boolean isBeforeTranslucent;
private ShaderStorageBufferHolder shaderStorageBufferHolder;
Expand Down Expand Up @@ -198,6 +199,7 @@ public IrisRenderingPipeline(ProgramSet programSet) {
this.separateHardwareSamplers = programSet.getPack().hasFeature(FeatureFlags.SEPARATE_HARDWARE_SAMPLERS);
this.shadowDirectives = packDirectives.getShadowDirectives();
this.cloudSetting = programSet.getPackDirectives().getCloudSetting();
this.dhCloudSetting = programSet.getPackDirectives().getDHCloudSetting();
this.shouldRenderSun = programSet.getPackDirectives().shouldRenderSun();
this.shouldRenderMoon = programSet.getPackDirectives().shouldRenderMoon();
this.allowConcurrentCompute = programSet.getPackDirectives().getConcurrentCompute();
Expand Down Expand Up @@ -1314,4 +1316,8 @@ public boolean hasShadowRenderTargets() {
public boolean skipAllRendering() {
return skipAllRendering;
}

public CloudSetting getDHCloudSetting() {
return dhCloudSetting;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public enum ProgramId {
Water(ProgramGroup.Gbuffers, "water", Terrain),
HandWater(ProgramGroup.Gbuffers, "hand_water", Hand),
DhTerrain(ProgramGroup.Dh, "terrain"),
DhGeneric(ProgramGroup.Dh, "generic", DhTerrain),
DhWater(ProgramGroup.Dh, "water", DhTerrain),
DhGeneric(ProgramGroup.Dh, "generic", DhTerrain),
DhShadow(ProgramGroup.Dh, "shadow"),

Final(ProgramGroup.Final, ""),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class PackDirectives {
private float eyeBrightnessHalfLife;
private float centerDepthHalfLife;
private CloudSetting cloudSetting;
private CloudSetting dhCloudSetting;
private boolean underwaterOverlay;
private boolean vignette;
private boolean sun;
Expand Down Expand Up @@ -68,6 +69,7 @@ private PackDirectives(Set<Integer> supportedRenderTargets, PackShadowDirectives
public PackDirectives(Set<Integer> supportedRenderTargets, ShaderProperties properties) {
this(supportedRenderTargets, new PackShadowDirectives(properties));
cloudSetting = properties.getCloudSetting();
dhCloudSetting = properties.getDHCloudSetting();
underwaterOverlay = properties.getUnderwaterOverlay().orElse(false);
vignette = properties.getVignette().orElse(false);
sun = properties.getSun().orElse(true);
Expand All @@ -94,6 +96,7 @@ public PackDirectives(Set<Integer> supportedRenderTargets, ShaderProperties prop
PackDirectives(Set<Integer> supportedRenderTargets, PackDirectives directives) {
this(supportedRenderTargets, new PackShadowDirectives(directives.getShadowDirectives()));
cloudSetting = directives.cloudSetting;
dhCloudSetting = directives.dhCloudSetting;
separateAo = directives.separateAo;
voxelizeLightBlocks = directives.voxelizeLightBlocks;
separateEntityDraws = directives.separateEntityDraws;
Expand Down Expand Up @@ -144,6 +147,10 @@ public CloudSetting getCloudSetting() {
return cloudSetting;
}

public CloudSetting getDHCloudSetting() {
return dhCloudSetting;
}

public boolean underwaterOverlay() {
return underwaterOverlay;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public class ShaderProperties {
CustomUniforms.Builder customUniforms = new CustomUniforms.Builder();
private int customTexAmount;
private CloudSetting cloudSetting = CloudSetting.DEFAULT;
private CloudSetting dhCloudSetting = CloudSetting.DEFAULT;
private OptionalBoolean oldHandLight = OptionalBoolean.DEFAULT;
private OptionalBoolean dynamicHandLight = OptionalBoolean.DEFAULT;
private OptionalBoolean supportsColorCorrection = OptionalBoolean.DEFAULT;
Expand Down Expand Up @@ -162,6 +163,16 @@ public ShaderProperties(String contents, ShaderPackOptions shaderPackOptions, It
}
}

if ("dhClouds".equals(key)) {
if ("off".equals(value)) {
dhCloudSetting = CloudSetting.OFF;
} else if ("on".equals(value) || "fancy".equals(value)) {
dhCloudSetting = CloudSetting.FANCY;
} else {
Iris.logger.error("Unrecognized DH clouds setting (need off, on): " + value);
}
}

if ("shadow.culling".equals(key)) {
if ("false".equals(value)) {
shadowCulling = ShadowCullState.DISTANCE;
Expand Down Expand Up @@ -720,6 +731,10 @@ public CloudSetting getCloudSetting() {
return cloudSetting;
}

public CloudSetting getDHCloudSetting() {
return dhCloudSetting;
}

public OptionalBoolean getOldHandLight() {
return oldHandLight;
}
Expand Down

0 comments on commit 77e3c8e

Please sign in to comment.