mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-19 20:09:39 +00:00
Buffer fixes (#1304)
This commit is contained in:
1 parent
08f4c0f9db
commit
d396b611ad
3 files changed
+72
-116
No files matched your search
@@ -14,6 +14,7 @@ import net.coderbot.iris.pipeline.transform.PatchShaderType;
|
||||
import net.coderbot.iris.rendertarget.RenderTargets;
|
||||
import net.coderbot.iris.uniforms.CommonUniforms;
|
||||
import net.coderbot.iris.uniforms.builtin.BuiltinReplacementUniforms;
|
||||
import net.coderbot.iris.shaderpack.ProgramSource;
|
||||
import net.coderbot.iris.uniforms.custom.CustomUniforms;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -60,124 +61,82 @@ public class CeleritasTerrainPipeline {
|
||||
IntFunction<ProgramImages> createTerrainImages,
|
||||
IntFunction<ProgramImages> createShadowImages,
|
||||
CustomUniforms customUniforms,
|
||||
String terrainSourceName,
|
||||
String translucentSourceName,
|
||||
String shadowSourceName,
|
||||
Optional<ProgramSource> terrainSource,
|
||||
Optional<ProgramSource> translucentSource,
|
||||
Optional<ProgramSource> shadowSource,
|
||||
CompletableFuture<Map<PatchShaderType, String>> terrainFuture,
|
||||
CompletableFuture<Map<PatchShaderType, String>> translucentFuture,
|
||||
CompletableFuture<Map<PatchShaderType, String>> shadowFuture,
|
||||
RenderTargets renderTargets,
|
||||
ImmutableSet<Integer> flippedAfterPrepare,
|
||||
ImmutableSet<Integer> flippedAfterTranslucent,
|
||||
@Nullable GlFramebuffer shadowFramebuffer,
|
||||
int[] terrainDrawBuffers
|
||||
@Nullable GlFramebuffer shadowFramebuffer
|
||||
) {
|
||||
this.customUniforms = customUniforms;
|
||||
|
||||
// Initialize PassInfo for each pass
|
||||
for (IrisTerrainPass pass : IrisTerrainPass.VALUES) {
|
||||
passInfoMap.put(pass, new PassInfo());
|
||||
}
|
||||
|
||||
// Process terrain shaders (used for GBUFFER_SOLID and GBUFFER_CUTOUT)
|
||||
if (terrainFuture != null) {
|
||||
try {
|
||||
final Map<PatchShaderType, String> result = terrainFuture.join();
|
||||
final PassInfo solidInfo = passInfoMap.get(IrisTerrainPass.GBUFFER_SOLID);
|
||||
final PassInfo cutoutInfo = passInfoMap.get(IrisTerrainPass.GBUFFER_CUTOUT);
|
||||
|
||||
solidInfo.setSource(PatchShaderType.VERTEX, result.get(PatchShaderType.VERTEX));
|
||||
solidInfo.setSource(PatchShaderType.GEOMETRY, result.get(PatchShaderType.GEOMETRY));
|
||||
solidInfo.setSource(PatchShaderType.FRAGMENT, result.get(PatchShaderType.FRAGMENT));
|
||||
|
||||
cutoutInfo.setSource(PatchShaderType.VERTEX, result.get(PatchShaderType.VERTEX));
|
||||
cutoutInfo.setSource(PatchShaderType.GEOMETRY, result.get(PatchShaderType.GEOMETRY));
|
||||
cutoutInfo.setSource(PatchShaderType.FRAGMENT, result.get(PatchShaderType.FRAGMENT));
|
||||
|
||||
PatchedShaderPrinter.debugPatchedShaders(terrainSourceName + "_celeritas",
|
||||
result.get(PatchShaderType.VERTEX), result.get(PatchShaderType.GEOMETRY), result.get(PatchShaderType.FRAGMENT));
|
||||
} catch (Exception e) {
|
||||
Iris.logger.error("Failed to transform terrain shader for Celeritas: {}", terrainSourceName, e);
|
||||
throw new RuntimeException("Shader transformation failed for " + terrainSourceName, e);
|
||||
}
|
||||
}
|
||||
|
||||
// Process translucent shaders (used for GBUFFER_TRANSLUCENT)
|
||||
if (translucentFuture != null) {
|
||||
try {
|
||||
final Map<PatchShaderType, String> result = translucentFuture.join();
|
||||
final PassInfo translucentInfo = passInfoMap.get(IrisTerrainPass.GBUFFER_TRANSLUCENT);
|
||||
|
||||
translucentInfo.setSource(PatchShaderType.VERTEX, result.get(PatchShaderType.VERTEX));
|
||||
translucentInfo.setSource(PatchShaderType.GEOMETRY, result.get(PatchShaderType.GEOMETRY));
|
||||
translucentInfo.setSource(PatchShaderType.FRAGMENT, result.get(PatchShaderType.FRAGMENT));
|
||||
|
||||
PatchedShaderPrinter.debugPatchedShaders(translucentSourceName + "_celeritas",
|
||||
result.get(PatchShaderType.VERTEX), result.get(PatchShaderType.GEOMETRY), result.get(PatchShaderType.FRAGMENT));
|
||||
} catch (Exception e) {
|
||||
Iris.logger.error("Failed to transform translucent shader for Celeritas: {}", translucentSourceName, e);
|
||||
throw new RuntimeException("Shader transformation failed for " + translucentSourceName, e);
|
||||
}
|
||||
}
|
||||
|
||||
// Process shadow shaders (used for SHADOW and SHADOW_CUTOUT)
|
||||
if (shadowFuture != null) {
|
||||
try {
|
||||
final Map<PatchShaderType, String> result = shadowFuture.join();
|
||||
final PassInfo shadowInfo = passInfoMap.get(IrisTerrainPass.SHADOW);
|
||||
final PassInfo shadowCutoutInfo = passInfoMap.get(IrisTerrainPass.SHADOW_CUTOUT);
|
||||
|
||||
shadowInfo.setSource(PatchShaderType.VERTEX, result.get(PatchShaderType.VERTEX));
|
||||
shadowInfo.setSource(PatchShaderType.GEOMETRY, result.get(PatchShaderType.GEOMETRY));
|
||||
shadowInfo.setSource(PatchShaderType.FRAGMENT, result.get(PatchShaderType.FRAGMENT));
|
||||
|
||||
shadowCutoutInfo.setSource(PatchShaderType.VERTEX, result.get(PatchShaderType.VERTEX));
|
||||
shadowCutoutInfo.setSource(PatchShaderType.GEOMETRY, result.get(PatchShaderType.GEOMETRY));
|
||||
shadowCutoutInfo.setSource(PatchShaderType.FRAGMENT, result.get(PatchShaderType.FRAGMENT));
|
||||
|
||||
PatchedShaderPrinter.debugPatchedShaders(shadowSourceName + "_celeritas",
|
||||
result.get(PatchShaderType.VERTEX), result.get(PatchShaderType.GEOMETRY), result.get(PatchShaderType.FRAGMENT));
|
||||
} catch (Exception e) {
|
||||
Iris.logger.error("Failed to transform shadow shader for Celeritas: {}", shadowSourceName, e);
|
||||
throw new RuntimeException("Shader transformation failed for " + shadowSourceName, e);
|
||||
}
|
||||
}
|
||||
|
||||
// Set up framebuffers for each pass
|
||||
// Shadow passes use the shadow framebuffer
|
||||
if (shadowFramebuffer != null) {
|
||||
passInfoMap.get(IrisTerrainPass.SHADOW).framebuffer = shadowFramebuffer;
|
||||
passInfoMap.get(IrisTerrainPass.SHADOW_CUTOUT).framebuffer = shadowFramebuffer;
|
||||
}
|
||||
|
||||
// GBuffer passes use render target framebuffers
|
||||
if (renderTargets != null && terrainDrawBuffers != null) {
|
||||
final GlFramebuffer solidFb = renderTargets.createGbufferFramebuffer(flippedAfterPrepare, terrainDrawBuffers);
|
||||
final GlFramebuffer translucentFb = renderTargets.createGbufferFramebuffer(flippedAfterTranslucent, terrainDrawBuffers);
|
||||
|
||||
passInfoMap.get(IrisTerrainPass.GBUFFER_SOLID).framebuffer = solidFb;
|
||||
passInfoMap.get(IrisTerrainPass.GBUFFER_CUTOUT).framebuffer = solidFb;
|
||||
passInfoMap.get(IrisTerrainPass.GBUFFER_TRANSLUCENT).framebuffer = translucentFb;
|
||||
}
|
||||
|
||||
// Set blend mode overrides
|
||||
passInfoMap.get(IrisTerrainPass.GBUFFER_SOLID).blendModeOverride = BlendModeOverride.OFF;
|
||||
passInfoMap.get(IrisTerrainPass.GBUFFER_CUTOUT).blendModeOverride = BlendModeOverride.OFF;
|
||||
passInfoMap.get(IrisTerrainPass.GBUFFER_TRANSLUCENT).blendModeOverride = null; // Default blending
|
||||
passInfoMap.get(IrisTerrainPass.SHADOW).blendModeOverride = BlendModeOverride.OFF;
|
||||
passInfoMap.get(IrisTerrainPass.SHADOW_CUTOUT).blendModeOverride = BlendModeOverride.OFF;
|
||||
|
||||
// Set alpha references
|
||||
passInfoMap.get(IrisTerrainPass.GBUFFER_SOLID).alphaReference = 0.0f;
|
||||
passInfoMap.get(IrisTerrainPass.GBUFFER_CUTOUT).alphaReference = 0.1f;
|
||||
passInfoMap.get(IrisTerrainPass.GBUFFER_TRANSLUCENT).alphaReference = 0.0f;
|
||||
passInfoMap.get(IrisTerrainPass.SHADOW).alphaReference = 0.0f;
|
||||
passInfoMap.get(IrisTerrainPass.SHADOW_CUTOUT).alphaReference = 0.1f;
|
||||
|
||||
this.createTerrainSamplers = createTerrainSamplers;
|
||||
this.createShadowSamplers = createShadowSamplers;
|
||||
this.createTerrainImages = createTerrainImages;
|
||||
this.createShadowImages = createShadowImages;
|
||||
|
||||
// Build program source map (local - only needed during construction)
|
||||
final EnumMap<IrisTerrainPass, Optional<ProgramSource>> gbufferProgramSource = new EnumMap<>(IrisTerrainPass.class);
|
||||
gbufferProgramSource.put(IrisTerrainPass.GBUFFER_SOLID, terrainSource);
|
||||
gbufferProgramSource.put(IrisTerrainPass.GBUFFER_CUTOUT, terrainSource);
|
||||
gbufferProgramSource.put(IrisTerrainPass.GBUFFER_TRANSLUCENT, translucentSource.isPresent() ? translucentSource : terrainSource);
|
||||
gbufferProgramSource.put(IrisTerrainPass.SHADOW, shadowSource);
|
||||
|
||||
// Initialize PassInfo, framebuffers, blend modes, and alpha in single pass
|
||||
for (IrisTerrainPass pass : IrisTerrainPass.VALUES) {
|
||||
PassInfo passInfo = new PassInfo();
|
||||
passInfoMap.put(pass, passInfo);
|
||||
|
||||
// Set up framebuffer
|
||||
if (pass == IrisTerrainPass.SHADOW || pass == IrisTerrainPass.SHADOW_CUTOUT) {
|
||||
passInfo.framebuffer = shadowFramebuffer;
|
||||
} else if (renderTargets != null) {
|
||||
ImmutableSet<Integer> flipped = pass == IrisTerrainPass.GBUFFER_TRANSLUCENT ? flippedAfterTranslucent : flippedAfterPrepare;
|
||||
|
||||
Optional<ProgramSource> programSource = gbufferProgramSource.get(pass);
|
||||
programSource.ifPresentOrElse(source -> passInfo.framebuffer = renderTargets.createGbufferFramebuffer(flipped, source.getDirectives().getDrawBuffers()), () -> passInfo.framebuffer = renderTargets.createGbufferFramebuffer(flipped, new int[] {0}));
|
||||
}
|
||||
|
||||
// Set blend mode override
|
||||
passInfo.blendModeOverride = switch (pass) {
|
||||
case GBUFFER_TRANSLUCENT -> null; // Default blending
|
||||
default -> BlendModeOverride.OFF;
|
||||
};
|
||||
|
||||
// Set alpha reference
|
||||
passInfo.alphaReference = switch (pass) {
|
||||
case GBUFFER_CUTOUT, SHADOW_CUTOUT -> 0.1f;
|
||||
default -> 0.0f;
|
||||
};
|
||||
}
|
||||
|
||||
// Process and apply shader sources
|
||||
processShaderFuture(terrainFuture, terrainSource, passInfoMap.get(IrisTerrainPass.GBUFFER_SOLID), passInfoMap.get(IrisTerrainPass.GBUFFER_CUTOUT));
|
||||
processShaderFuture(translucentFuture, translucentSource, passInfoMap.get(IrisTerrainPass.GBUFFER_TRANSLUCENT));
|
||||
processShaderFuture(shadowFuture, shadowSource, passInfoMap.get(IrisTerrainPass.SHADOW), passInfoMap.get(IrisTerrainPass.SHADOW_CUTOUT));
|
||||
}
|
||||
|
||||
private void processShaderFuture(@Nullable CompletableFuture<Map<PatchShaderType, String>> future, Optional<ProgramSource> source, PassInfo... targets) {
|
||||
if (future == null || source.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
final String sourceName = source.get().getName();
|
||||
try {
|
||||
final Map<PatchShaderType, String> result = future.join();
|
||||
for (PassInfo target : targets) {
|
||||
target.setSource(PatchShaderType.VERTEX, result.get(PatchShaderType.VERTEX));
|
||||
target.setSource(PatchShaderType.GEOMETRY, result.get(PatchShaderType.GEOMETRY));
|
||||
target.setSource(PatchShaderType.FRAGMENT, result.get(PatchShaderType.FRAGMENT));
|
||||
}
|
||||
PatchedShaderPrinter.debugPatchedShaders(sourceName + "_celeritas",
|
||||
result.get(PatchShaderType.VERTEX), result.get(PatchShaderType.GEOMETRY), result.get(PatchShaderType.FRAGMENT));
|
||||
} catch (Exception e) {
|
||||
Iris.logger.error("Failed to transform shader for Celeritas: {}", sourceName, e);
|
||||
throw new RuntimeException("Shader transformation failed for " + sourceName, e);
|
||||
}
|
||||
}
|
||||
|
||||
public PassInfo getPassInfo(IrisTerrainPass pass) {
|
||||
|
||||
@@ -96,7 +96,7 @@ public class ShaderPackScreen extends GuiScreen implements HudHideable {
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float delta) {
|
||||
GLStateManager.glPushAttrib(GL11.GL_COLOR_BUFFER_BIT);
|
||||
|
||||
|
||||
if(dirty) {
|
||||
dirty = false;
|
||||
this.initGui();
|
||||
@@ -174,7 +174,7 @@ public class ShaderPackScreen extends GuiScreen implements HudHideable {
|
||||
} else {
|
||||
this.fontRendererObj.drawStringWithShadow(irisTextComponent, 2, this.height - 10, 0xFFFFFF);
|
||||
}
|
||||
|
||||
|
||||
GLStateManager.glPopAttrib();
|
||||
}
|
||||
|
||||
@@ -507,7 +507,7 @@ public class ShaderPackScreen extends GuiScreen implements HudHideable {
|
||||
}
|
||||
|
||||
public boolean isDisplayingComment() {
|
||||
return this.hoveredElementCommentTimer > 20 &&
|
||||
return this.hoveredElementCommentTimer > 10 &&
|
||||
this.hoveredElementCommentTitle.isPresent() &&
|
||||
!this.hoveredElementCommentBody.isEmpty();
|
||||
}
|
||||
|
||||
@@ -524,19 +524,16 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
final GlFramebuffer celeritasShadowFb = (shadowRenderTargets != null && shadowRenderer != null)
|
||||
? shadowRenderTargets.createShadowFramebuffer(shadowRenderTargets.snapshot(), new int[] {0, 1})
|
||||
: null;
|
||||
final int[] celeritasTerrainDrawBuffers = terrainSource
|
||||
.map(source -> source.getDirectives().getDrawBuffers())
|
||||
.orElse(new int[] {0});
|
||||
|
||||
this.celeritasTerrainPipeline = new CeleritasTerrainPipeline(createTerrainSamplers,
|
||||
shadowRenderer == null ? null : createShadowTerrainSamplers, createTerrainImages,
|
||||
shadowRenderer == null ? null : createShadowTerrainImages, this.customUniforms,
|
||||
terrainSource.map(ProgramSource::getName).orElse(null),
|
||||
translucentSource.map(ProgramSource::getName).orElse(null),
|
||||
shadowSource.map(ProgramSource::getName).orElse(null),
|
||||
terrainSource,
|
||||
translucentSource,
|
||||
shadowSource,
|
||||
celeritasTerrainFuture, celeritasTranslucentFuture, celeritasShadowFuture,
|
||||
renderTargets, flippedAfterPrepare, flippedAfterTranslucent,
|
||||
celeritasShadowFb, celeritasTerrainDrawBuffers);
|
||||
celeritasShadowFb);
|
||||
|
||||
this.dhCompat = new DHCompat();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user