Skip to content

Commit

Permalink
Update to Sodium 0.5.9
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Jun 13, 2024
1 parent 59cdb36 commit 8d9a6c8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object Constants {
const val BETA_TAG: String = "DH Support"
const val BETA_VERSION = 4

const val SODIUM_VERSION: String = "mc1.20.1-0.5.8"
const val SODIUM_VERSION: String = "mc1.20.1-0.5.9"
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.vertex.VertexBuffer;
Expand All @@ -17,8 +18,10 @@
import net.irisshaders.iris.pipeline.WorldRenderingPipeline;
import net.irisshaders.iris.pipeline.programs.ShaderKey;
import net.irisshaders.iris.vertices.IrisVertexFormats;
import net.minecraft.client.CloudStatus;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.renderer.FogRenderer;
import net.minecraft.client.renderer.ShaderInstance;
Expand Down Expand Up @@ -62,22 +65,30 @@ private static void writeIrisVertex(long buffer, float x, float y, float z, int
@Shadow
protected abstract void applyFogModifiers(ClientLevel world, FogRenderer.FogData fogData, LocalPlayer player, int cloudDistance, float tickDelta);

@Shadow
private CloudStatus cloudRenderMode;

@Inject(method = "render", at = @At(value = "HEAD"), cancellable = true)
private void buildIrisVertexBuffer(ClientLevel world, LocalPlayer player, PoseStack matrices, Matrix4f projectionMatrix, float ticks, float tickDelta, double cameraX, double cameraY, double cameraZ, CallbackInfo ci) {
private void buildIrisVertexBuffer(ClientLevel level, LocalPlayer player, PoseStack matrices, Matrix4f projectionMatrix, float ticks, float tickDelta, double cameraX, double cameraY, double cameraZ, CallbackInfo ci) {
if (IrisApi.getInstance().isShaderPackInUse()) {
ci.cancel();
renderIris(world, player, matrices, projectionMatrix, ticks, tickDelta, cameraX, cameraY, cameraZ);
renderIris(level, player, matrices, projectionMatrix, ticks, tickDelta, cameraX, cameraY, cameraZ);
}
}

public void renderIris(@Nullable ClientLevel world, LocalPlayer player, PoseStack matrices, Matrix4f projectionMatrix, float ticks, float tickDelta, double cameraX, double cameraY, double cameraZ) {
if (world == null) {
public void renderIris(@Nullable ClientLevel level, LocalPlayer player, PoseStack matrices, Matrix4f projectionMatrix, float ticks, float tickDelta, double cameraX, double cameraY, double cameraZ) {
if (level == null) {
return;
}

Vec3 color = world.getCloudColor(tickDelta);
float cloudHeight = level.effects().getCloudHeight();

// Vanilla uses NaN height as a way to disable cloud rendering
if (Float.isNaN(cloudHeight)) {
return;
}

float cloudHeight = world.effects().getCloudHeight();
Vec3 color = level.getCloudColor(tickDelta);

double cloudTime = (ticks + tickDelta) * 0.03F;
double cloudCenterX = (cameraX + cloudTime);
Expand All @@ -89,12 +100,13 @@ public void renderIris(@Nullable ClientLevel world, LocalPlayer player, PoseStac
int centerCellX = (int) (Math.floor(cloudCenterX / 12));
int centerCellZ = (int) (Math.floor(cloudCenterZ / 12));

if (this.vertexBufferWithNormals == null || this.prevCenterCellXIris != centerCellX || this.prevCenterCellYIris != centerCellZ || this.cachedRenderDistanceIris != renderDistance) {
if (this.vertexBufferWithNormals == null || this.prevCenterCellXIris != centerCellX || this.prevCenterCellYIris != centerCellZ || this.cachedRenderDistanceIris != renderDistance || cloudRenderMode != Minecraft.getInstance().options.getCloudsType()) {
BufferBuilder bufferBuilder = Tesselator.getInstance().getBuilder();
bufferBuilder.begin(VertexFormat.Mode.QUADS, IrisVertexFormats.CLOUDS);
bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);

this.cloudRenderMode = Minecraft.getInstance().options.getCloudsType();

// Give some space for shaders
this.rebuildGeometry(bufferBuilder, cloudDistance + 4, centerCellX, centerCellZ);
this.rebuildGeometry(bufferBuilder, cloudDistance, centerCellX, centerCellZ);

if (this.vertexBufferWithNormals == null) {
this.vertexBufferWithNormals = new VertexBuffer(VertexBuffer.Usage.DYNAMIC);
Expand All @@ -112,14 +124,14 @@ public void renderIris(@Nullable ClientLevel world, LocalPlayer player, PoseStac

float previousEnd = RenderSystem.getShaderFogEnd();
float previousStart = RenderSystem.getShaderFogStart();
fogData.end = cloudDistance * 8;
fogData.start = (cloudDistance * 8) - 16;
this.fogData.end = cloudDistance * 8;
this.fogData.start = (cloudDistance * 8) - 16;

applyFogModifiers(world, fogData, player, cloudDistance * 8, tickDelta);
applyFogModifiers(level, this.fogData, player, cloudDistance * 8, tickDelta);


RenderSystem.setShaderFogEnd(fogData.end);
RenderSystem.setShaderFogStart(fogData.start);
RenderSystem.setShaderFogEnd(this.fogData.end);
RenderSystem.setShaderFogStart(this.fogData.start);

float translateX = (float) (cloudCenterX - (centerCellX * 12));
float translateZ = (float) (cloudCenterZ - (centerCellZ * 12));
Expand All @@ -129,13 +141,18 @@ public void renderIris(@Nullable ClientLevel world, LocalPlayer player, PoseStac
this.vertexBufferWithNormals.bind();

boolean insideClouds = cameraY < cloudHeight + 4.5f && cameraY > cloudHeight - 0.5f;
boolean fastClouds = cloudRenderMode == CloudStatus.FAST;

if (insideClouds) {
if (insideClouds || fastClouds) {
RenderSystem.disableCull();
} else {
RenderSystem.enableCull();
}

if (Minecraft.useShaderTransparency()) {
Minecraft.getInstance().levelRenderer.getCloudsTarget().bindWrite(false);
}

RenderSystem.setShaderColor((float) color.x, (float) color.y, (float) color.z, 0.8f);

matrices.pushPose();
Expand All @@ -148,7 +165,7 @@ public void renderIris(@Nullable ClientLevel world, LocalPlayer player, PoseStac
RenderSystem.depthMask(true);
RenderSystem.colorMask(false, false, false, false);

this.vertexBufferWithNormals.drawWithShader(modelViewMatrix, projectionMatrix, getClouds());
this.vertexBufferWithNormals.drawWithShader(modelViewMatrix, projectionMatrix, this.getClouds());

// PASS 2: Render geometry
RenderSystem.enableBlend();
Expand All @@ -158,7 +175,7 @@ public void renderIris(@Nullable ClientLevel world, LocalPlayer player, PoseStac
RenderSystem.depthFunc(GL30C.GL_EQUAL);
RenderSystem.colorMask(true, true, true, true);

this.vertexBufferWithNormals.drawWithShader(modelViewMatrix, projectionMatrix, getClouds());
this.vertexBufferWithNormals.drawWithShader(modelViewMatrix, projectionMatrix, this.getClouds());

matrices.popPose();

Expand All @@ -167,9 +184,12 @@ public void renderIris(@Nullable ClientLevel world, LocalPlayer player, PoseStac
RenderSystem.disableBlend();
RenderSystem.depthFunc(GL30C.GL_LEQUAL);

RenderSystem.enableCull();
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);

RenderSystem.enableCull();
if (Minecraft.useShaderTransparency()) {
Minecraft.getInstance().getMainRenderTarget().bindWrite(false);
}

RenderSystem.setShaderFogEnd(previousEnd);
RenderSystem.setShaderFogStart(previousStart);
Expand Down

0 comments on commit 8d9a6c8

Please sign in to comment.