Fix MC 1.21.5 rendering and bright glass on sky
This commit is contained in:
+28
-14
@@ -86,22 +86,31 @@ public class FadeRenderer
|
||||
this.fadeFramebuffer = -1;
|
||||
}
|
||||
|
||||
if (this.fadeTexture != -1)
|
||||
{
|
||||
GLMC.glDeleteTextures(this.fadeTexture);
|
||||
this.fadeTexture = -1;
|
||||
}
|
||||
|
||||
this.fadeFramebuffer = GL32.glGenFramebuffers();
|
||||
GLMC.glBindFramebuffer(GL32.GL_FRAMEBUFFER, this.fadeFramebuffer);
|
||||
|
||||
this.fadeTexture = GL32.glGenTextures();
|
||||
GLMC.glBindTexture(this.fadeTexture);
|
||||
GL32.glTexImage2D(GL32.GL_TEXTURE_2D, 0, GL32.GL_RGBA16, width, height, 0, GL32.GL_RGBA, GL32.GL_UNSIGNED_SHORT_4_4_4_4, (ByteBuffer) null);
|
||||
GL32.glTexParameteri(GL32.GL_TEXTURE_2D, GL32.GL_TEXTURE_MIN_FILTER, GL32.GL_LINEAR);
|
||||
GL32.glTexParameteri(GL32.GL_TEXTURE_2D, GL32.GL_TEXTURE_MAG_FILTER, GL32.GL_LINEAR);
|
||||
GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT0, GL32.GL_TEXTURE_2D, this.fadeTexture, 0);
|
||||
|
||||
// Applying the fade texture is only needed if MC is drawing to their own frame buffer,
|
||||
// otherwise we can directly render to their texture
|
||||
if (MC_RENDER.mcRendersToFrameBuffer())
|
||||
{
|
||||
if (this.fadeTexture != -1)
|
||||
{
|
||||
GLMC.glDeleteTextures(this.fadeTexture);
|
||||
this.fadeTexture = -1;
|
||||
}
|
||||
|
||||
this.fadeTexture = GL32.glGenTextures();
|
||||
GLMC.glBindTexture(this.fadeTexture);
|
||||
GL32.glTexImage2D(GL32.GL_TEXTURE_2D, 0, GL32.GL_RGBA16, width, height, 0, GL32.GL_RGBA, GL32.GL_UNSIGNED_SHORT_4_4_4_4, (ByteBuffer) null);
|
||||
GL32.glTexParameteri(GL32.GL_TEXTURE_2D, GL32.GL_TEXTURE_MIN_FILTER, GL32.GL_LINEAR);
|
||||
GL32.glTexParameteri(GL32.GL_TEXTURE_2D, GL32.GL_TEXTURE_MAG_FILTER, GL32.GL_LINEAR);
|
||||
GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT0, GL32.GL_TEXTURE_2D, this.fadeTexture, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT0, GL32.GL_TEXTURE_2D, MC_RENDER.getColorTextureId(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -146,8 +155,13 @@ public class FadeRenderer
|
||||
|
||||
profiler.popPush("Fade Apply");
|
||||
|
||||
FadeApplyShader.INSTANCE.fadeTexture = this.fadeTexture;
|
||||
FadeApplyShader.INSTANCE.render(partialTicks);
|
||||
// Applying the fade texture is only needed if MC is drawing to their own frame buffer,
|
||||
// otherwise we can directly render to their texture
|
||||
if (MC_RENDER.mcRendersToFrameBuffer())
|
||||
{
|
||||
FadeApplyShader.INSTANCE.fadeTexture = this.fadeTexture;
|
||||
FadeApplyShader.INSTANCE.render(partialTicks);
|
||||
}
|
||||
|
||||
profiler.pop();
|
||||
}
|
||||
|
||||
+33
-20
@@ -557,29 +557,15 @@ public class LodRenderer
|
||||
activeFrameBuffer.bind();
|
||||
|
||||
|
||||
boolean clearTextures = !ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeTextureClearEvent.class, renderEventParam);
|
||||
if (clearTextures)
|
||||
{
|
||||
if (this.usingMcFrameBuffer && framebufferOverride == null)
|
||||
{
|
||||
// Due to using MC/Optifine's framebuffer we need to re-bind the depth texture,
|
||||
// otherwise we'll be writing to MC/Optifine's depth texture which causes rendering issues
|
||||
activeFrameBuffer.addDepthAttachment(this.depthTexture.getTextureId(), EDhDepthBufferFormat.DEPTH32F.isCombinedStencil());
|
||||
|
||||
|
||||
// don't clear the color texture, that removes the sky
|
||||
GL32.glClear(GL32.GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
else if (firstPass)
|
||||
{
|
||||
GL32.glClear(GL32.GL_COLOR_BUFFER_BIT | GL32.GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
// by default draw everything as triangles
|
||||
GL32.glPolygonMode(GL32.GL_FRONT_AND_BACK, GL32.GL_FILL);
|
||||
GLMC.enableFaceCulling();
|
||||
|
||||
GLMC.glBlendFunc(GL32.GL_SRC_ALPHA, GL32.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GLMC.glBlendFuncSeparate(GL32.GL_SRC_ALPHA, GL32.GL_ONE_MINUS_SRC_ALPHA, GL32.GL_ONE, GL32.GL_ZERO);
|
||||
|
||||
GL32.glDisable(GL32.GL_SCISSOR_TEST);
|
||||
|
||||
// Enable depth test and depth mask
|
||||
GLMC.enableDepthTest();
|
||||
GLMC.glDepthFunc(GL32.GL_LESS);
|
||||
@@ -605,6 +591,33 @@ public class LodRenderer
|
||||
}
|
||||
|
||||
this.lodRenderProgram.fillUniformData(renderEventParam);
|
||||
|
||||
|
||||
// needs to be fired after all the textures have been created/bound
|
||||
boolean clearTextures = !ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeTextureClearEvent.class, renderEventParam);
|
||||
if (clearTextures)
|
||||
{
|
||||
GL32.glClearDepth(1.0);
|
||||
|
||||
float[] clearColorValues = new float[4];
|
||||
GL32.glGetFloatv(GL32.GL_COLOR_CLEAR_VALUE, clearColorValues);
|
||||
GL32.glClearColor(clearColorValues[0], clearColorValues[1], clearColorValues[2], 1.0f);
|
||||
|
||||
if (this.usingMcFrameBuffer && framebufferOverride == null)
|
||||
{
|
||||
// Due to using MC/Optifine's framebuffer we need to re-bind the depth texture,
|
||||
// otherwise we'll be writing to MC/Optifine's depth texture which causes rendering issues
|
||||
activeFrameBuffer.addDepthAttachment(this.depthTexture.getTextureId(), EDhDepthBufferFormat.DEPTH32F.isCombinedStencil());
|
||||
|
||||
|
||||
// don't clear the color texture, that removes the sky
|
||||
GL32.glClear(GL32.GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
else if (firstPass)
|
||||
{
|
||||
GL32.glClear(GL32.GL_COLOR_BUFFER_BIT | GL32.GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Setup all render objects - MUST be called on the render thread */
|
||||
@@ -656,7 +669,7 @@ public class LodRenderer
|
||||
if(this.framebuffer.getStatus() != GL32.GL_FRAMEBUFFER_COMPLETE)
|
||||
{
|
||||
// This generally means something wasn't bound, IE missing either the color or depth texture
|
||||
SPAM_LOGGER.warn("FrameBuffer ["+this.framebuffer.getId()+"] isn't complete.");
|
||||
EVENT_LOGGER.warn("FrameBuffer ["+this.framebuffer.getId()+"] isn't complete.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
+64
-9
@@ -44,7 +44,6 @@ public class DhApplyShader extends AbstractShaderRenderer
|
||||
|
||||
// uniforms
|
||||
public int gDhColorTextureUniform;
|
||||
public int gDepthMapUniform;
|
||||
|
||||
|
||||
|
||||
@@ -61,7 +60,6 @@ public class DhApplyShader extends AbstractShaderRenderer
|
||||
|
||||
// uniform setup
|
||||
this.gDhColorTextureUniform = this.shader.getUniformLocation("gDhColorTexture");
|
||||
this.gDepthMapUniform = this.shader.getUniformLocation("gDhDepthTexture");
|
||||
|
||||
}
|
||||
|
||||
@@ -75,6 +73,18 @@ public class DhApplyShader extends AbstractShaderRenderer
|
||||
|
||||
@Override
|
||||
protected void onRender()
|
||||
{
|
||||
if (MC_RENDER.mcRendersToFrameBuffer())
|
||||
{
|
||||
this.renderToFrameBuffer();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.renderToMcTexture();
|
||||
}
|
||||
}
|
||||
// TODO merge duplicate code between these to render methods
|
||||
private void renderToFrameBuffer()
|
||||
{
|
||||
int targetFrameBuffer = MC_RENDER.getTargetFrameBuffer();
|
||||
if (targetFrameBuffer == -1)
|
||||
@@ -87,18 +97,13 @@ public class DhApplyShader extends AbstractShaderRenderer
|
||||
|
||||
GLMC.disableDepthTest();
|
||||
|
||||
GLMC.enableBlend();
|
||||
GL32.glBlendEquation(GL32.GL_FUNC_ADD);
|
||||
GLMC.glBlendFunc(GL32.GL_ONE, GL32.GL_ONE_MINUS_SRC_ALPHA);
|
||||
// blending isn't needed, we're just directly merging the MC and DH textures
|
||||
GLMC.disableBlend();
|
||||
|
||||
GLMC.glActiveTexture(GL32.GL_TEXTURE0);
|
||||
GLMC.glBindTexture(LodRenderer.getActiveColorTextureId());
|
||||
GL32.glUniform1i(this.gDhColorTextureUniform, 0);
|
||||
|
||||
GLMC.glActiveTexture(GL32.GL_TEXTURE1);
|
||||
GLMC.glBindTexture(LodRenderer.getActiveDepthTextureId());
|
||||
GL32.glUniform1i(this.gDepthMapUniform, 1);
|
||||
|
||||
// Copy to MC's framebuffer
|
||||
GLMC.glBindFramebuffer(GL32.GL_FRAMEBUFFER, targetFrameBuffer);
|
||||
|
||||
@@ -110,5 +115,55 @@ public class DhApplyShader extends AbstractShaderRenderer
|
||||
GLMC.glBindFramebuffer(GL32.GL_FRAMEBUFFER, targetFrameBuffer);
|
||||
|
||||
}
|
||||
private void renderToMcTexture()
|
||||
{
|
||||
int targetColorTextureId = MC_RENDER.getColorTextureId();
|
||||
if (targetColorTextureId == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int dhFrameBufferId = LodRenderer.getActiveFramebufferId();
|
||||
if (dhFrameBufferId == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int mcFrameBufferId = MC_RENDER.getTargetFrameBuffer();
|
||||
if (mcFrameBufferId == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
GLState state = new GLState();
|
||||
|
||||
GLMC.disableDepthTest();
|
||||
|
||||
// blending isn't needed, we're just directly merging the MC and DH textures
|
||||
GLMC.disableBlend();
|
||||
|
||||
GLMC.glActiveTexture(GL32.GL_TEXTURE0);
|
||||
GLMC.glBindTexture(LodRenderer.getActiveColorTextureId());
|
||||
GL32.glUniform1i(this.gDhColorTextureUniform, 0);
|
||||
|
||||
|
||||
|
||||
GL32.glFramebufferTexture(GL32.GL_DRAW_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT0, targetColorTextureId, 0);
|
||||
|
||||
// Copy to MC's texture via MC's framebuffer
|
||||
GLMC.glBindFramebuffer(GL32.GL_FRAMEBUFFER, dhFrameBufferId);
|
||||
|
||||
ScreenQuad.INSTANCE.render();
|
||||
|
||||
|
||||
// restore everything, except at this point the MC framebuffer should now be used instead
|
||||
state.restore();
|
||||
GLMC.glBindFramebuffer(GL32.GL_FRAMEBUFFER, mcFrameBufferId);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
+10
@@ -20,6 +20,7 @@
|
||||
package com.seibel.distanthorizons.core.render.renderer.shaders;
|
||||
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.render.glObject.GLState;
|
||||
import com.seibel.distanthorizons.core.render.glObject.shader.ShaderProgram;
|
||||
import com.seibel.distanthorizons.core.render.renderer.FadeRenderer;
|
||||
import com.seibel.distanthorizons.core.render.renderer.LodRenderer;
|
||||
@@ -104,6 +105,12 @@ public class FadeApplyShader extends AbstractShaderRenderer
|
||||
@Override
|
||||
protected void onRender()
|
||||
{
|
||||
if (!MC_RENDER.mcRendersToFrameBuffer())
|
||||
{
|
||||
throw new IllegalStateException("If Minecraft is directly rendering to a texture the apply shader isn't needed, just draw the fade directly to the MC color texture.");
|
||||
}
|
||||
|
||||
|
||||
GLMC.disableBlend();
|
||||
|
||||
// Depth testing must be disabled otherwise this application shader won't apply anything.
|
||||
@@ -119,6 +126,9 @@ public class FadeApplyShader extends AbstractShaderRenderer
|
||||
ScreenQuad.INSTANCE.render();
|
||||
|
||||
GLMC.enableDepthTest();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
-6
@@ -45,7 +45,6 @@ public class FogApplyShader extends AbstractShaderRenderer
|
||||
|
||||
// uniforms
|
||||
public int colorTextureUniform;
|
||||
public int depthTextureUniform;
|
||||
|
||||
|
||||
|
||||
@@ -64,7 +63,6 @@ public class FogApplyShader extends AbstractShaderRenderer
|
||||
|
||||
// uniform setup
|
||||
this.colorTextureUniform = this.shader.getUniformLocation("uColorTexture");
|
||||
this.depthTextureUniform = this.shader.getUniformLocation("uDepthTexture");
|
||||
|
||||
}
|
||||
|
||||
@@ -80,10 +78,6 @@ public class FogApplyShader extends AbstractShaderRenderer
|
||||
GLMC.glActiveTexture(GL32.GL_TEXTURE0);
|
||||
GLMC.glBindTexture(this.fogTexture);
|
||||
GL32.glUniform1i(this.colorTextureUniform, 0);
|
||||
|
||||
GLMC.glActiveTexture(GL32.GL_TEXTURE1);
|
||||
GLMC.glBindTexture(LodRenderer.getActiveDepthTextureId());
|
||||
GL32.glUniform1i(this.depthTextureUniform, 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
@@ -60,6 +60,8 @@ public interface IMinecraftRenderWrapper extends IBindable
|
||||
int getScreenWidth();
|
||||
int getScreenHeight();
|
||||
|
||||
boolean mcRendersToFrameBuffer();
|
||||
|
||||
/** @return -1 if no valid framebuffer is available yet */
|
||||
int getTargetFrameBuffer(); // Note: Iris is now hooking onto this for DH + Iris compat, try not to change (unless we wanna deal with some annoyances)
|
||||
// Iris commit: https://github.com/IrisShaders/Iris/commit/a76a240527e93780bbcba57c09bef377419d47a7#diff-7b9ded0c79bbcdb130010373387756a28ee8d3640d522c0a5b7acd0abbfc20aeR16
|
||||
|
||||
@@ -5,20 +5,10 @@ in vec2 TexCoord;
|
||||
out vec4 fragColor;
|
||||
|
||||
uniform sampler2D gDhColorTexture;
|
||||
uniform sampler2D gDhDepthTexture;
|
||||
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
fragColor = vec4(0.0);
|
||||
|
||||
float fragmentDepth = texture(gDhDepthTexture, TexCoord).r;
|
||||
|
||||
// a fragment depth of "1" means the fragment wasn't drawn to,
|
||||
// only update fragments that were drawn to
|
||||
if (fragmentDepth != 1)
|
||||
{
|
||||
fragColor = texture(gDhColorTexture, TexCoord);
|
||||
}
|
||||
fragColor = texture(gDhColorTexture, TexCoord);
|
||||
}
|
||||
|
||||
@@ -5,20 +5,10 @@ in vec2 TexCoord;
|
||||
out vec4 fragColor;
|
||||
|
||||
uniform sampler2D uColorTexture;
|
||||
uniform sampler2D uDepthTexture;
|
||||
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
fragColor = vec4(1.0);
|
||||
|
||||
float fragmentDepth = textureLod(uDepthTexture, TexCoord, 0).r;
|
||||
|
||||
// a fragment depth of "1" means the fragment wasn't drawn to,
|
||||
// only update fragments that were drawn to
|
||||
if (fragmentDepth != 1)
|
||||
{
|
||||
fragColor = texture(uColorTexture, TexCoord);
|
||||
}
|
||||
fragColor = texture(uColorTexture, TexCoord);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user