From 4a37a8f8514c67613c0874ef1ff15825a939e3f1 Mon Sep 17 00:00:00 2001 From: Kirill Vainer Date: Tue, 22 Sep 2015 22:09:38 -0400 Subject: [PATCH] FXAA: quality regression fix FXAA wants input texture to use bilinear filtering so it can be smoothed further, so allow filters to request bilinear filtering. --- jme3-core/src/main/java/com/jme3/post/Filter.java | 13 +++++++++++++ .../java/com/jme3/post/FilterPostProcessor.java | 12 ++++++++++++ .../main/java/com/jme3/post/filters/FXAAFilter.java | 6 ++++++ 3 files changed, 31 insertions(+) diff --git a/jme3-core/src/main/java/com/jme3/post/Filter.java b/jme3-core/src/main/java/com/jme3/post/Filter.java index a6e2e3c01..feaacbe5d 100644 --- a/jme3-core/src/main/java/com/jme3/post/Filter.java +++ b/jme3-core/src/main/java/com/jme3/post/Filter.java @@ -409,6 +409,19 @@ public abstract class Filter implements Savable { return true; } + /** + * Override this method and return true if you want the scene (input) texture + * to use bilinear filtering or false to use nearest filtering. + * + * Typically filters that perform samples in between pixels + * should enable filtering. + * + * @return true to use linear filtering, false to use nearest filtering. + */ + protected boolean isRequiresBilinear() { + return false; + } + /** * returns the list of the postRender passes * @return diff --git a/jme3-core/src/main/java/com/jme3/post/FilterPostProcessor.java b/jme3-core/src/main/java/com/jme3/post/FilterPostProcessor.java index b28aecece..2f52eb425 100644 --- a/jme3-core/src/main/java/com/jme3/post/FilterPostProcessor.java +++ b/jme3-core/src/main/java/com/jme3/post/FilterPostProcessor.java @@ -38,6 +38,7 @@ import com.jme3.renderer.*; import com.jme3.renderer.queue.RenderQueue; import com.jme3.texture.FrameBuffer; import com.jme3.texture.Image.Format; +import com.jme3.texture.Texture; import com.jme3.texture.Texture2D; import com.jme3.ui.Picture; import com.jme3.util.SafeArrayList; @@ -284,6 +285,12 @@ public class FilterPostProcessor implements SceneProcessor, Savable { mat.clearParam("NumSamples"); } } + + boolean wantsBilinear = filter.isRequiresBilinear(); + if (wantsBilinear) { + tex.setMagFilter(Texture.MagFilter.Bilinear); + tex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps); + } buff = outputBuffer; if (i != lastFilterIndex) { @@ -293,6 +300,11 @@ public class FilterPostProcessor implements SceneProcessor, Savable { } renderProcessing(r, buff, mat); filter.postFilter(r, buff); + + if (wantsBilinear) { + tex.setMagFilter(Texture.MagFilter.Nearest); + tex.setMinFilter(Texture.MinFilter.NearestNoMipMaps); + } } } } diff --git a/jme3-effects/src/main/java/com/jme3/post/filters/FXAAFilter.java b/jme3-effects/src/main/java/com/jme3/post/filters/FXAAFilter.java index 7b1dfb37a..37fec3bcd 100644 --- a/jme3-effects/src/main/java/com/jme3/post/filters/FXAAFilter.java +++ b/jme3-effects/src/main/java/com/jme3/post/filters/FXAAFilter.java @@ -69,6 +69,12 @@ public class FXAAFilter extends Filter { protected Material getMaterial() { return material; } + + @Override + protected boolean isRequiresBilinear() { + // FXAA wants the input texture to be filtered. + return true; + } public void setSpanMax(float spanMax) { this.spanMax = spanMax;