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 c54b6dd commit a8def54
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 25 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ object Constants {
const val MOD_VERSION: String = "1.7.1"

const val CUSTOM_SODIUM: Boolean = false
const val CUSTOM_SODIUM_NAME: String = "sodium-fabric-0.5.8-snapshot+mc24w14a-local.jar"
const val CUSTOM_SODIUM_NAME: String = "sodium-fabric-0.5.9-snapshotmc1.20.6-local.jar"

const val IS_SHARED_BETA: Boolean = false
const val ACTIVATE_RENDERDOC: Boolean = false
const val BETA_TAG: String = "DH Support"
const val BETA_VERSION = 4

const val SODIUM_VERSION: String = "mc1.20.6-0.5.8"
const val SODIUM_VERSION: String = "mc1.20.6-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 modelView, 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, modelView, 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 poseStack, Matrix4f modelMatrix, 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();

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

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,27 +141,31 @@ 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);

poseStack.pushPose();
poseStack.mulPose(modelMatrix);
matrices.pushPose();

Matrix4f modelViewMatrix = new Matrix4f(poseStack.last().pose());
Matrix4f modelViewMatrix = matrices.last().pose();
modelViewMatrix.translate(-translateX, cloudHeight - (float) cameraY + 0.33F, -translateZ);

// PASS 1: Set up depth buffer
RenderSystem.disableBlend();
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 @@ -159,17 +175,22 @@ 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();

VertexBuffer.unbind();

RenderSystem.disableBlend();
RenderSystem.depthFunc(GL30C.GL_LEQUAL);

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

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

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

0 comments on commit a8def54

Please sign in to comment.