|
64 | 64 | import net.minecraft.tileentity.TileEntity; |
65 | 65 | import net.minecraft.world.WorldProvider; |
66 | 66 | import net.minecraftforge.client.ForgeHooksClient; |
| 67 | +import net.minecraftforge.client.event.RenderWorldLastEvent; |
67 | 68 |
|
68 | 69 | import java.nio.DoubleBuffer; |
69 | 70 | import java.util.ArrayList; |
@@ -783,9 +784,37 @@ public static void beginRenderWorld() { |
783 | 784 | renderShadowMap(); |
784 | 785 | } |
785 | 786 |
|
| 787 | + /** |
| 788 | + * Experimental feature that might either be just left in, or put behind a toggle depending on perf overhead. |
| 789 | + * <p> |
| 790 | + * What we're doing is handing whatever will render in the {@link RenderWorldLastEvent} depth that excludes translucent geometry. |
| 791 | + * <p> |
| 792 | + * This is closer to what vanilla does, but in turn this will cost us an additional 3 full-screen depth blits. |
| 793 | + */ |
| 794 | + private static final boolean COMBINED_DEPTH = true; |
| 795 | + |
| 796 | + public static void preRenderLast() { |
| 797 | + if (COMBINED_DEPTH) { |
| 798 | + DebugMarker.GENERIC.insert("PRE_SAVE_DEPTH_0"); |
| 799 | + blitDepth(buffers.gDepthTex, buffers.depthTex0); |
| 800 | + DebugMarker.GENERIC.insert("POST_SAVE_DEPTH_0"); |
| 801 | + |
| 802 | + DebugMarker.GENERIC.insert("PRE_LOAD_DEPTH_1"); |
| 803 | + GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT); |
| 804 | + blitDepth(buffers.depthTex1, buffers.gDepthTex); |
| 805 | + DebugMarker.GENERIC.insert("POST_LOAD_DEPTH_1"); |
| 806 | + } |
| 807 | + } |
| 808 | + |
786 | 809 | public static void finishRenderFinal() { |
787 | 810 | ShaderState.updateRenderStage(MCRenderStage.NONE); |
788 | 811 |
|
| 812 | + if (COMBINED_DEPTH) { |
| 813 | + DebugMarker.GENERIC.insert("PRE_COMBINE_DEPTH"); |
| 814 | + blitDepth(buffers.depthTex0, buffers.gDepthTex, true); |
| 815 | + DebugMarker.GENERIC.insert("POST_COMBINE_DEPTH"); |
| 816 | + } |
| 817 | + |
789 | 818 | captureLastDepth(); |
790 | 819 | // Composite first |
791 | 820 | renderComposite(); |
@@ -1156,6 +1185,10 @@ public static void blitColors(Int2ObjectMap<Texture2D> src, Int2ObjectMap<Textur |
1156 | 1185 | } |
1157 | 1186 |
|
1158 | 1187 | public static void blitDepth(Texture2D srcTex, Texture2D dstTex) { |
| 1188 | + blitDepth(srcTex, dstTex, false); |
| 1189 | + } |
| 1190 | + |
| 1191 | + public static void blitDepth(Texture2D srcTex, Texture2D dstTex, boolean combine) { |
1159 | 1192 | if (state == null) { |
1160 | 1193 | Share.log.warn("Tried to blit depth with no state"); |
1161 | 1194 | return; |
@@ -1183,10 +1216,12 @@ public static void blitDepth(Texture2D srcTex, Texture2D dstTex) { |
1183 | 1216 | // Bind Destination Texture |
1184 | 1217 | dstTex.attachToFramebufferDepth(); |
1185 | 1218 |
|
1186 | | - GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT); |
| 1219 | + if (!combine) { |
| 1220 | + GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT); |
| 1221 | + } |
1187 | 1222 |
|
1188 | 1223 | // Draw using the regular composite (with depth only) |
1189 | | - ShadersCompositeMesh.drawWithDepth(); |
| 1224 | + ShadersCompositeMesh.drawWithDepth(combine); |
1190 | 1225 |
|
1191 | 1226 | if (DebugMarker.isEnabled()) { |
1192 | 1227 | DebugMarker.TEXTURE_DEPTH_BLIT.insertFormat("{0} -> {1}", srcTex.name(), dstTex.name()); |
|
0 commit comments