mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-18 11:29:08 +00:00
Maybe fix TAA (#1047)
This commit is contained in:
1 parent
86edb721da
commit
34b6efde7b
6 files changed
+49
-20
No files matched your search
@@ -49,6 +49,7 @@ public class FinalPassRenderer {
|
||||
@Nullable
|
||||
private final Pass finalPass;
|
||||
private final ImmutableList<SwapPass> swapPasses;
|
||||
private final ImmutableSet<Integer> flippedBuffers;
|
||||
private final GlFramebuffer baseline;
|
||||
private final GlFramebuffer colorHolder;
|
||||
private int lastColorTextureId;
|
||||
@@ -72,6 +73,7 @@ public class FinalPassRenderer {
|
||||
|
||||
this.noiseTexture = noiseTexture;
|
||||
this.renderTargets = renderTargets;
|
||||
this.flippedBuffers = flippedBuffers;
|
||||
this.customUniforms = customUniforms;
|
||||
this.finalPass = pack.getCompositeFinal().map(source -> {
|
||||
Pass pass = new Pass();
|
||||
@@ -101,23 +103,37 @@ public class FinalPassRenderer {
|
||||
// TODO: We don't actually fully swap the content, we merely copy it from alt to main
|
||||
// This works for the most part, but it's not perfect. A better approach would be creating secondary
|
||||
// framebuffers for every other frame, but that would be a lot more complex...
|
||||
ImmutableList.Builder<SwapPass> swapPasses = ImmutableList.builder();
|
||||
final ImmutableList.Builder<SwapPass> swapPasses = ImmutableList.builder();
|
||||
|
||||
flippedBuffers.forEach(i -> {
|
||||
int target = i;
|
||||
// BUG FIX: Swap passes are only needed for NON-flipped buffers that might flip in the future.
|
||||
// Flipped buffers use ping-pong mechanism - no swap needed.
|
||||
// Original code created swaps for ALL flippedAtLeastOnce buffers and copied ALT→MAIN,
|
||||
// which destroyed fresh data in MAIN for currently-flipped buffers (breaking TAA).
|
||||
// Fixed: Only create swaps for buffers that are in flippedAtLeastOnce but NOT currently flipped.
|
||||
flippedAtLeastOnce.forEach(i -> {
|
||||
final int target = i;
|
||||
|
||||
// Skip buffer 6 (material mask) - gbuffers always write to MAIN, never flipped
|
||||
if (target == 6) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Skip buffers that are currently flipped - they use ping-pong, no swap needed
|
||||
if (flippedBuffers.contains(target)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (buffersToBeCleared.contains(target)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SwapPass swap = new SwapPass();
|
||||
RenderTarget target1 = renderTargets.get(target);
|
||||
final SwapPass swap = new SwapPass();
|
||||
final RenderTarget target1 = renderTargets.get(target);
|
||||
swap.target = target;
|
||||
swap.width = target1.getWidth();
|
||||
swap.height = target1.getHeight();
|
||||
// Non-flipped buffers write to ALT, copy ALT→MAIN to preserve data
|
||||
swap.from = renderTargets.createColorFramebuffer(ImmutableSet.of(), new int[] {target});
|
||||
// NB: This is handled in RenderTargets now.
|
||||
//swap.from.readBuffer(target);
|
||||
swap.targetTexture = renderTargets.get(target).getMainTexture();
|
||||
|
||||
swapPasses.add(swap);
|
||||
@@ -264,8 +280,10 @@ public class FinalPassRenderer {
|
||||
|
||||
public void recalculateSwapPassSize() {
|
||||
for (SwapPass swapPass : swapPasses) {
|
||||
RenderTarget target = renderTargets.get(swapPass.target);
|
||||
final RenderTarget target = renderTargets.get(swapPass.target);
|
||||
renderTargets.destroyFramebuffer(swapPass.from);
|
||||
// Match constructor logic - swap passes are only for non-flipped buffers
|
||||
// Copy ALT→MAIN to preserve data written to ALT
|
||||
swapPass.from = renderTargets.createColorFramebuffer(ImmutableSet.of(), new int[] {swapPass.target});
|
||||
swapPass.width = target.getWidth();
|
||||
swapPass.height = target.getHeight();
|
||||
@@ -274,7 +292,7 @@ public class FinalPassRenderer {
|
||||
}
|
||||
|
||||
private static void setupMipmapping(RenderTarget target, boolean readFromAlt) {
|
||||
int texture = readFromAlt ? target.getAltTexture() : target.getMainTexture();
|
||||
final int texture = readFromAlt ? target.getAltTexture() : target.getMainTexture();
|
||||
|
||||
// TODO: Only generate the mipmap if a valid mipmap hasn't been generated or if we've written to the buffer
|
||||
// (since the last mipmap was generated)
|
||||
@@ -319,13 +337,13 @@ public class FinalPassRenderer {
|
||||
source.getVertexSource().orElseThrow(NullPointerException::new),
|
||||
source.getGeometrySource().orElse(null),
|
||||
source.getFragmentSource().orElseThrow(NullPointerException::new));
|
||||
String vertex = transformed.get(PatchShaderType.VERTEX);
|
||||
String geometry = transformed.get(PatchShaderType.GEOMETRY);
|
||||
String fragment = transformed.get(PatchShaderType.FRAGMENT);
|
||||
final String vertex = transformed.get(PatchShaderType.VERTEX);
|
||||
final String geometry = transformed.get(PatchShaderType.GEOMETRY);
|
||||
final String fragment = transformed.get(PatchShaderType.FRAGMENT);
|
||||
PatchedShaderPrinter.debugPatchedShaders(source.getName(), vertex, geometry, fragment);
|
||||
|
||||
Objects.requireNonNull(flipped);
|
||||
ProgramBuilder builder;
|
||||
final ProgramBuilder builder;
|
||||
|
||||
try {
|
||||
builder = ProgramBuilder.begin(source.getName(), vertex, geometry, fragment,
|
||||
@@ -337,7 +355,7 @@ public class FinalPassRenderer {
|
||||
|
||||
this.customUniforms.assignTo(builder);
|
||||
|
||||
ProgramSamplers.CustomTextureSamplerInterceptor customTextureSamplerInterceptor = ProgramSamplers.customTextureSamplerInterceptor(builder, customTextureIds, flippedAtLeastOnceSnapshot);
|
||||
final ProgramSamplers.CustomTextureSamplerInterceptor customTextureSamplerInterceptor = ProgramSamplers.customTextureSamplerInterceptor(builder, customTextureIds, flippedAtLeastOnceSnapshot);
|
||||
|
||||
CommonUniforms.addDynamicUniforms(builder);
|
||||
IrisSamplers.addRenderTargetSamplers(customTextureSamplerInterceptor, () -> flipped, renderTargets, true);
|
||||
@@ -361,15 +379,15 @@ public class FinalPassRenderer {
|
||||
}
|
||||
|
||||
private ComputeProgram[] createComputes(ComputeSource[] compute, ImmutableSet<Integer> flipped, ImmutableSet<Integer> flippedAtLeastOnceSnapshot, Supplier<ShadowRenderTargets> shadowTargetsSupplier) {
|
||||
ComputeProgram[] programs = new ComputeProgram[compute.length];
|
||||
final ComputeProgram[] programs = new ComputeProgram[compute.length];
|
||||
for (int i = 0; i < programs.length; i++) {
|
||||
ComputeSource source = compute[i];
|
||||
final ComputeSource source = compute[i];
|
||||
if (source == null || !source.getSource().isPresent()) {
|
||||
continue;
|
||||
} else {
|
||||
// TODO: Properly handle empty shaders
|
||||
Objects.requireNonNull(flipped);
|
||||
ProgramBuilder builder;
|
||||
final ProgramBuilder builder;
|
||||
|
||||
try {
|
||||
builder = ProgramBuilder.beginCompute(source.getName(), source.getSource().orElse(null), IrisSamplers.COMPOSITE_RESERVED_TEXTURE_UNITS);
|
||||
|
||||
Reference in new issue
Block a user