Skip to content

Commit ff4e29c

Browse files
committed
1.21
1 parent 2c4f16f commit ff4e29c

File tree

3 files changed

+90
-105
lines changed

3 files changed

+90
-105
lines changed

build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
33

44
object Constants {
55
// https://fabricmc.net/develop/
6-
const val MINECRAFT_VERSION: String = "1.21-pre2"
6+
const val MINECRAFT_VERSION: String = "1.21-rc1"
77
const val FABRIC_LOADER_VERSION: String = "0.15.11"
8-
const val FABRIC_API_VERSION: String = "0.99.1+1.21"
8+
const val FABRIC_API_VERSION: String = "0.100.0+1.21"
99

1010
// https://semver.org/
1111
const val MOD_VERSION: String = "1.7.1"
1212

1313
const val CUSTOM_SODIUM: Boolean = true
14-
const val CUSTOM_SODIUM_NAME: String = "sodium-fabric-0.5.8-snapshotmc1.21-pre1-local.jar"
14+
const val CUSTOM_SODIUM_NAME: String = "sodium-fabric-0.5.9-snapshotmc1.21-pre3-local.jar"
1515

1616
const val IS_SHARED_BETA: Boolean = false
1717
const val ACTIVATE_RENDERDOC: Boolean = true

src/main/resources/fabric.mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"1.21.x"
4242
],
4343
"sodium": [
44-
"0.5.9"
44+
"0.5.x"
4545
]
4646
},
4747
"breaks": {

src/sodiumCompatibility/java/net/irisshaders/iris/compat/sodium/mixin/clouds/MixinCloudRenderer.java

Lines changed: 86 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.mojang.blaze3d.platform.GlStateManager;
44
import com.mojang.blaze3d.systems.RenderSystem;
55
import com.mojang.blaze3d.vertex.BufferBuilder;
6+
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
67
import com.mojang.blaze3d.vertex.PoseStack;
78
import com.mojang.blaze3d.vertex.Tesselator;
89
import com.mojang.blaze3d.vertex.VertexBuffer;
@@ -17,6 +18,7 @@
1718
import net.irisshaders.iris.pipeline.WorldRenderingPipeline;
1819
import net.irisshaders.iris.pipeline.programs.ShaderKey;
1920
import net.irisshaders.iris.vertices.IrisVertexFormats;
21+
import net.minecraft.client.CloudStatus;
2022
import net.minecraft.client.Minecraft;
2123
import net.minecraft.client.multiplayer.ClientLevel;
2224
import net.minecraft.client.player.LocalPlayer;
@@ -62,115 +64,98 @@ private static void writeIrisVertex(long buffer, float x, float y, float z, int
6264
@Shadow
6365
protected abstract void applyFogModifiers(ClientLevel world, FogRenderer.FogData fogData, LocalPlayer player, int cloudDistance, float tickDelta);
6466

67+
@Shadow
68+
private CloudStatus cloudRenderMode;
69+
6570
@Inject(method = "render", at = @At(value = "HEAD"), cancellable = true)
66-
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) {
71+
private void buildIrisVertexBuffer(ClientLevel level, LocalPlayer player, PoseStack matrices, Matrix4f projectionMatrix, float ticks, float tickDelta, double cameraX, double cameraY, double cameraZ, CallbackInfo ci) {
6772
if (IrisApi.getInstance().isShaderPackInUse()) {
6873
ci.cancel();
69-
renderIris(world, player, matrices, modelView, projectionMatrix, ticks, tickDelta, cameraX, cameraY, cameraZ);
74+
renderIris(level, player, matrices, projectionMatrix, ticks, tickDelta, cameraX, cameraY, cameraZ);
7075
}
7176
}
7277

73-
public void renderIris(@Nullable ClientLevel world, LocalPlayer player, PoseStack poseStack, Matrix4f modelMatrix, Matrix4f projectionMatrix, float ticks, float tickDelta, double cameraX, double cameraY, double cameraZ) {
74-
if (world == null) {
75-
return;
76-
}
77-
78-
Vec3 color = world.getCloudColor(tickDelta);
79-
80-
float cloudHeight = world.effects().getCloudHeight();
81-
82-
double cloudTime = (ticks + tickDelta) * 0.03F;
83-
double cloudCenterX = (cameraX + cloudTime);
84-
double cloudCenterZ = (cameraZ) + 0.33D;
85-
86-
int renderDistance = Minecraft.getInstance().options.getEffectiveRenderDistance();
87-
int cloudDistance = Math.max(32, (renderDistance * 2) + 9);
88-
89-
int centerCellX = (int) (Math.floor(cloudCenterX / 12));
90-
int centerCellZ = (int) (Math.floor(cloudCenterZ / 12));
91-
92-
if (this.vertexBufferWithNormals == null || this.prevCenterCellXIris != centerCellX || this.prevCenterCellYIris != centerCellZ || this.cachedRenderDistanceIris != renderDistance) {
93-
BufferBuilder bufferBuilder = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, IrisVertexFormats.CLOUDS);
94-
95-
// Give some space for shaders
96-
this.rebuildGeometry(bufferBuilder, cloudDistance + 4, centerCellX, centerCellZ);
97-
98-
if (this.vertexBufferWithNormals == null) {
99-
this.vertexBufferWithNormals = new VertexBuffer(VertexBuffer.Usage.DYNAMIC);
78+
public void renderIris(@Nullable ClientLevel level, LocalPlayer player, PoseStack matrices, Matrix4f projectionMatrix, float ticks, float tickDelta, double cameraX, double cameraY, double cameraZ) {
79+
if (level != null) {
80+
float cloudHeight = level.effects().getCloudHeight();
81+
if (!Float.isNaN(cloudHeight)) {
82+
Vec3 color = level.getCloudColor(tickDelta);
83+
double cloudTime = (double)((ticks + tickDelta) * 0.03F);
84+
double cloudCenterX = cameraX + cloudTime;
85+
double cloudCenterZ = cameraZ + 0.33;
86+
int renderDistance = Minecraft.getInstance().options.getEffectiveRenderDistance();
87+
int cloudDistance = Math.max(32, renderDistance * 2 + 9);
88+
int centerCellX = (int)Math.floor(cloudCenterX / 12.0);
89+
int centerCellZ = (int)Math.floor(cloudCenterZ / 12.0);
90+
if (this.vertexBufferWithNormals == null || this.prevCenterCellXIris != centerCellX || this.prevCenterCellYIris != centerCellZ || this.cachedRenderDistanceIris != renderDistance || this.cloudRenderMode != Minecraft.getInstance().options.getCloudsType()) {
91+
BufferBuilder bufferBuilder = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
92+
this.cloudRenderMode = Minecraft.getInstance().options.getCloudsType();
93+
this.rebuildGeometry(bufferBuilder, cloudDistance, centerCellX, centerCellZ);
94+
if (this.vertexBufferWithNormals == null) {
95+
this.vertexBufferWithNormals = new VertexBuffer(VertexBuffer.Usage.DYNAMIC);
96+
}
97+
98+
this.vertexBufferWithNormals.bind();
99+
this.vertexBufferWithNormals.upload(bufferBuilder.buildOrThrow());
100+
Tesselator.getInstance().clear();
101+
VertexBuffer.unbind();
102+
this.prevCenterCellXIris = centerCellX;
103+
this.prevCenterCellYIris = centerCellZ;
104+
this.cachedRenderDistanceIris = renderDistance;
105+
}
106+
107+
float previousEnd = RenderSystem.getShaderFogEnd();
108+
float previousStart = RenderSystem.getShaderFogStart();
109+
this.fogData.end = (float)(cloudDistance * 8);
110+
this.fogData.start = (float)(cloudDistance * 8 - 16);
111+
this.applyFogModifiers(level, this.fogData, player, cloudDistance * 8, tickDelta);
112+
RenderSystem.setShaderFogEnd(this.fogData.end);
113+
RenderSystem.setShaderFogStart(this.fogData.start);
114+
float translateX = (float)(cloudCenterX - (double)(centerCellX * 12));
115+
float translateZ = (float)(cloudCenterZ - (double)(centerCellZ * 12));
116+
RenderSystem.enableDepthTest();
117+
this.vertexBufferWithNormals.bind();
118+
boolean insideClouds = cameraY < (double)(cloudHeight + 4.5F) && cameraY > (double)(cloudHeight - 0.5F);
119+
boolean fastClouds = this.cloudRenderMode == CloudStatus.FAST;
120+
if (!insideClouds && !fastClouds) {
121+
RenderSystem.enableCull();
122+
} else {
123+
RenderSystem.disableCull();
124+
}
125+
126+
if (Minecraft.useShaderTransparency()) {
127+
Minecraft.getInstance().levelRenderer.getCloudsTarget().bindWrite(false);
128+
}
129+
130+
RenderSystem.setShaderColor((float)color.x, (float)color.y, (float)color.z, 0.8F);
131+
matrices.pushPose();
132+
Matrix4f modelViewMatrix = matrices.last().pose();
133+
modelViewMatrix.translate(-translateX, cloudHeight - (float)cameraY + 0.33F, -translateZ);
134+
RenderSystem.disableBlend();
135+
RenderSystem.depthMask(true);
136+
RenderSystem.colorMask(false, false, false, false);
137+
this.vertexBufferWithNormals.drawWithShader(modelViewMatrix, projectionMatrix, getClouds());
138+
RenderSystem.enableBlend();
139+
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
140+
RenderSystem.depthMask(false);
141+
RenderSystem.enableDepthTest();
142+
RenderSystem.depthFunc(514);
143+
RenderSystem.colorMask(true, true, true, true);
144+
this.vertexBufferWithNormals.drawWithShader(modelViewMatrix, projectionMatrix, getClouds());
145+
matrices.popPose();
146+
VertexBuffer.unbind();
147+
RenderSystem.disableBlend();
148+
RenderSystem.depthFunc(515);
149+
RenderSystem.enableCull();
150+
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
151+
if (Minecraft.useShaderTransparency()) {
152+
Minecraft.getInstance().getMainRenderTarget().bindWrite(false);
153+
}
154+
155+
RenderSystem.setShaderFogEnd(previousEnd);
156+
RenderSystem.setShaderFogStart(previousStart);
100157
}
101-
102-
this.vertexBufferWithNormals.bind();
103-
this.vertexBufferWithNormals.upload(bufferBuilder.build());
104-
105-
VertexBuffer.unbind();
106-
107-
this.prevCenterCellXIris = centerCellX;
108-
this.prevCenterCellYIris = centerCellZ;
109-
this.cachedRenderDistanceIris = renderDistance;
110-
}
111-
112-
float previousEnd = RenderSystem.getShaderFogEnd();
113-
float previousStart = RenderSystem.getShaderFogStart();
114-
fogData.end = cloudDistance * 8;
115-
fogData.start = (cloudDistance * 8) - 16;
116-
117-
applyFogModifiers(world, fogData, player, cloudDistance * 8, tickDelta);
118-
119-
120-
RenderSystem.setShaderFogEnd(fogData.end);
121-
RenderSystem.setShaderFogStart(fogData.start);
122-
123-
float translateX = (float) (cloudCenterX - (centerCellX * 12));
124-
float translateZ = (float) (cloudCenterZ - (centerCellZ * 12));
125-
126-
RenderSystem.enableDepthTest();
127-
128-
this.vertexBufferWithNormals.bind();
129-
130-
boolean insideClouds = cameraY < cloudHeight + 4.5f && cameraY > cloudHeight - 0.5f;
131-
132-
if (insideClouds) {
133-
RenderSystem.disableCull();
134-
} else {
135-
RenderSystem.enableCull();
136158
}
137-
138-
RenderSystem.setShaderColor((float) color.x, (float) color.y, (float) color.z, 0.8f);
139-
140-
poseStack.pushPose();
141-
poseStack.mulPose(modelMatrix);
142-
143-
Matrix4f modelViewMatrix = new Matrix4f(poseStack.last().pose());
144-
modelViewMatrix.translate(-translateX, cloudHeight - (float) cameraY + 0.33F, -translateZ);
145-
146-
// PASS 1: Set up depth buffer
147-
RenderSystem.disableBlend();
148-
RenderSystem.depthMask(true);
149-
RenderSystem.colorMask(false, false, false, false);
150-
151-
this.vertexBufferWithNormals.drawWithShader(modelViewMatrix, projectionMatrix, getClouds());
152-
153-
// PASS 2: Render geometry
154-
RenderSystem.enableBlend();
155-
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
156-
RenderSystem.depthMask(false);
157-
RenderSystem.enableDepthTest();
158-
RenderSystem.depthFunc(GL30C.GL_EQUAL);
159-
RenderSystem.colorMask(true, true, true, true);
160-
161-
this.vertexBufferWithNormals.drawWithShader(modelViewMatrix, projectionMatrix, getClouds());
162-
163-
VertexBuffer.unbind();
164-
165-
RenderSystem.disableBlend();
166-
RenderSystem.depthFunc(GL30C.GL_LEQUAL);
167-
168-
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
169-
170-
RenderSystem.enableCull();
171-
poseStack.popPose();
172-
RenderSystem.setShaderFogEnd(previousEnd);
173-
RenderSystem.setShaderFogStart(previousStart);
174159
}
175160

176161
@ModifyArg(method = "rebuildGeometry", at = @At(value = "INVOKE", target = "Lorg/lwjgl/system/MemoryStack;nmalloc(I)J"))

0 commit comments

Comments
 (0)