Skip to content

Commit

Permalink
1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Jun 12, 2024
1 parent 2c4f16f commit ff4e29c
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 105 deletions.
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform

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

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

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

const val IS_SHARED_BETA: Boolean = false
const val ACTIVATE_RENDERDOC: Boolean = true
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"1.21.x"
],
"sodium": [
"0.5.9"
"0.5.x"
]
},
"breaks": {
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,6 +18,7 @@
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.LocalPlayer;
Expand Down Expand Up @@ -62,115 +64,98 @@ 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) {
return;
}

Vec3 color = world.getCloudColor(tickDelta);

float cloudHeight = world.effects().getCloudHeight();

double cloudTime = (ticks + tickDelta) * 0.03F;
double cloudCenterX = (cameraX + cloudTime);
double cloudCenterZ = (cameraZ) + 0.33D;

int renderDistance = Minecraft.getInstance().options.getEffectiveRenderDistance();
int cloudDistance = Math.max(32, (renderDistance * 2) + 9);

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) {
BufferBuilder bufferBuilder = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, IrisVertexFormats.CLOUDS);

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

if (this.vertexBufferWithNormals == null) {
this.vertexBufferWithNormals = new VertexBuffer(VertexBuffer.Usage.DYNAMIC);
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) {
float cloudHeight = level.effects().getCloudHeight();
if (!Float.isNaN(cloudHeight)) {
Vec3 color = level.getCloudColor(tickDelta);
double cloudTime = (double)((ticks + tickDelta) * 0.03F);
double cloudCenterX = cameraX + cloudTime;
double cloudCenterZ = cameraZ + 0.33;
int renderDistance = Minecraft.getInstance().options.getEffectiveRenderDistance();
int cloudDistance = Math.max(32, renderDistance * 2 + 9);
int centerCellX = (int)Math.floor(cloudCenterX / 12.0);
int centerCellZ = (int)Math.floor(cloudCenterZ / 12.0);
if (this.vertexBufferWithNormals == null || this.prevCenterCellXIris != centerCellX || this.prevCenterCellYIris != centerCellZ || this.cachedRenderDistanceIris != renderDistance || this.cloudRenderMode != Minecraft.getInstance().options.getCloudsType()) {
BufferBuilder bufferBuilder = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
this.cloudRenderMode = Minecraft.getInstance().options.getCloudsType();
this.rebuildGeometry(bufferBuilder, cloudDistance, centerCellX, centerCellZ);
if (this.vertexBufferWithNormals == null) {
this.vertexBufferWithNormals = new VertexBuffer(VertexBuffer.Usage.DYNAMIC);
}

this.vertexBufferWithNormals.bind();
this.vertexBufferWithNormals.upload(bufferBuilder.buildOrThrow());
Tesselator.getInstance().clear();
VertexBuffer.unbind();
this.prevCenterCellXIris = centerCellX;
this.prevCenterCellYIris = centerCellZ;
this.cachedRenderDistanceIris = renderDistance;
}

float previousEnd = RenderSystem.getShaderFogEnd();
float previousStart = RenderSystem.getShaderFogStart();
this.fogData.end = (float)(cloudDistance * 8);
this.fogData.start = (float)(cloudDistance * 8 - 16);
this.applyFogModifiers(level, this.fogData, player, cloudDistance * 8, tickDelta);
RenderSystem.setShaderFogEnd(this.fogData.end);
RenderSystem.setShaderFogStart(this.fogData.start);
float translateX = (float)(cloudCenterX - (double)(centerCellX * 12));
float translateZ = (float)(cloudCenterZ - (double)(centerCellZ * 12));
RenderSystem.enableDepthTest();
this.vertexBufferWithNormals.bind();
boolean insideClouds = cameraY < (double)(cloudHeight + 4.5F) && cameraY > (double)(cloudHeight - 0.5F);
boolean fastClouds = this.cloudRenderMode == CloudStatus.FAST;
if (!insideClouds && !fastClouds) {
RenderSystem.enableCull();
} else {
RenderSystem.disableCull();
}

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

RenderSystem.setShaderColor((float)color.x, (float)color.y, (float)color.z, 0.8F);
matrices.pushPose();
Matrix4f modelViewMatrix = matrices.last().pose();
modelViewMatrix.translate(-translateX, cloudHeight - (float)cameraY + 0.33F, -translateZ);
RenderSystem.disableBlend();
RenderSystem.depthMask(true);
RenderSystem.colorMask(false, false, false, false);
this.vertexBufferWithNormals.drawWithShader(modelViewMatrix, projectionMatrix, getClouds());
RenderSystem.enableBlend();
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
RenderSystem.depthMask(false);
RenderSystem.enableDepthTest();
RenderSystem.depthFunc(514);
RenderSystem.colorMask(true, true, true, true);
this.vertexBufferWithNormals.drawWithShader(modelViewMatrix, projectionMatrix, getClouds());
matrices.popPose();
VertexBuffer.unbind();
RenderSystem.disableBlend();
RenderSystem.depthFunc(515);
RenderSystem.enableCull();
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
if (Minecraft.useShaderTransparency()) {
Minecraft.getInstance().getMainRenderTarget().bindWrite(false);
}

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

this.vertexBufferWithNormals.bind();
this.vertexBufferWithNormals.upload(bufferBuilder.build());

VertexBuffer.unbind();

this.prevCenterCellXIris = centerCellX;
this.prevCenterCellYIris = centerCellZ;
this.cachedRenderDistanceIris = renderDistance;
}

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

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


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

float translateX = (float) (cloudCenterX - (centerCellX * 12));
float translateZ = (float) (cloudCenterZ - (centerCellZ * 12));

RenderSystem.enableDepthTest();

this.vertexBufferWithNormals.bind();

boolean insideClouds = cameraY < cloudHeight + 4.5f && cameraY > cloudHeight - 0.5f;

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

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

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

Matrix4f modelViewMatrix = new Matrix4f(poseStack.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());

// PASS 2: Render geometry
RenderSystem.enableBlend();
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
RenderSystem.depthMask(false);
RenderSystem.enableDepthTest();
RenderSystem.depthFunc(GL30C.GL_EQUAL);
RenderSystem.colorMask(true, true, true, true);

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

VertexBuffer.unbind();

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

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

RenderSystem.enableCull();
poseStack.popPose();
RenderSystem.setShaderFogEnd(previousEnd);
RenderSystem.setShaderFogStart(previousStart);
}

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

0 comments on commit ff4e29c

Please sign in to comment.