|
3 | 3 | import com.mojang.blaze3d.platform.GlStateManager; |
4 | 4 | import com.mojang.blaze3d.systems.RenderSystem; |
5 | 5 | import com.mojang.blaze3d.vertex.BufferBuilder; |
| 6 | +import com.mojang.blaze3d.vertex.DefaultVertexFormat; |
6 | 7 | import com.mojang.blaze3d.vertex.PoseStack; |
7 | 8 | import com.mojang.blaze3d.vertex.Tesselator; |
8 | 9 | import com.mojang.blaze3d.vertex.VertexBuffer; |
|
17 | 18 | import net.irisshaders.iris.pipeline.WorldRenderingPipeline; |
18 | 19 | import net.irisshaders.iris.pipeline.programs.ShaderKey; |
19 | 20 | import net.irisshaders.iris.vertices.IrisVertexFormats; |
| 21 | +import net.minecraft.client.CloudStatus; |
20 | 22 | import net.minecraft.client.Minecraft; |
21 | 23 | import net.minecraft.client.multiplayer.ClientLevel; |
22 | 24 | import net.minecraft.client.player.LocalPlayer; |
@@ -62,115 +64,98 @@ private static void writeIrisVertex(long buffer, float x, float y, float z, int |
62 | 64 | @Shadow |
63 | 65 | protected abstract void applyFogModifiers(ClientLevel world, FogRenderer.FogData fogData, LocalPlayer player, int cloudDistance, float tickDelta); |
64 | 66 |
|
| 67 | + @Shadow |
| 68 | + private CloudStatus cloudRenderMode; |
| 69 | + |
65 | 70 | @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) { |
67 | 72 | if (IrisApi.getInstance().isShaderPackInUse()) { |
68 | 73 | 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); |
70 | 75 | } |
71 | 76 | } |
72 | 77 |
|
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); |
100 | 157 | } |
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(); |
136 | 158 | } |
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); |
174 | 159 | } |
175 | 160 |
|
176 | 161 | @ModifyArg(method = "rebuildGeometry", at = @At(value = "INVOKE", target = "Lorg/lwjgl/system/MemoryStack;nmalloc(I)J")) |
|
0 commit comments