Home | History | Annotate | Download | only in filters
      1 package com.jme3.post.filters;
      2 
      3 import com.jme3.asset.AssetManager;
      4 import com.jme3.material.Material;
      5 import com.jme3.post.Filter;
      6 import com.jme3.renderer.RenderManager;
      7 import com.jme3.renderer.ViewPort;
      8 
      9 /**
     10  * <a href="http://www.geeks3d.com/20110405/fxaa-fast-approximate-anti-aliasing-demo-glsl-opengl-test-radeon-geforce/3/" rel="nofollow">http://www.geeks3d.com/20110405/fxaa-fast-approximate-anti-aliasing-demo-glsl-<span class="domtooltips" title="OpenGL (Open Graphics Library) is a standard specification defining a cross-language, cross-platform API for writing applications that produce 2D and 3D computer graphics." id="domtooltipsspan11">opengl</span>-test-radeon-geforce/3/</a>
     11  * <a href="http://developer.download.nvidia.com/assets/gamedev/files/sdk/11/FXAA_WhitePaper.pdf" rel="nofollow">http://developer.download.nvidia.com/assets/gamedev/files/sdk/11/FXAA_WhitePaper.pdf</a>
     12  *
     13  * @author Phate666 (adapted to jme3)
     14  *
     15  */
     16 public class FXAAFilter extends Filter {
     17 
     18     private float subPixelShift = 1.0f / 4.0f;
     19     private float vxOffset = 0.0f;
     20     private float spanMax = 8.0f;
     21     private float reduceMul = 1.0f / 8.0f;
     22 
     23     public FXAAFilter() {
     24         super("FXAAFilter");
     25     }
     26 
     27     @Override
     28     protected void initFilter(AssetManager manager,
     29             RenderManager renderManager, ViewPort vp, int w, int h) {
     30         material = new Material(manager, "Common/MatDefs/Post/FXAA.j3md");
     31         material.setFloat("SubPixelShift", subPixelShift);
     32         material.setFloat("VxOffset", vxOffset);
     33         material.setFloat("SpanMax", spanMax);
     34         material.setFloat("ReduceMul", reduceMul);
     35     }
     36 
     37     @Override
     38     protected Material getMaterial() {
     39         return material;
     40     }
     41 
     42     public void setSpanMax(float spanMax) {
     43         this.spanMax = spanMax;
     44         if (material != null) {
     45             material.setFloat("SpanMax", this.spanMax);
     46         }
     47     }
     48 
     49     /**
     50      * set to 0.0f for higher quality
     51      *
     52      * @param subPixelShift
     53      */
     54     public void setSubPixelShift(float subPixelShift) {
     55         this.subPixelShift = subPixelShift;
     56         if (material != null) {
     57             material.setFloat("SubPixelShif", this.subPixelShift);
     58         }
     59     }
     60 
     61     /**
     62      * set to 0.0f for higher quality
     63      *
     64      * @param reduceMul
     65      */
     66     public void setReduceMul(float reduceMul) {
     67         this.reduceMul = reduceMul;
     68         if (material != null) {
     69             material.setFloat("ReduceMul", this.reduceMul);
     70         }
     71     }
     72 
     73     public void setVxOffset(float vxOffset) {
     74         this.vxOffset = vxOffset;
     75         if (material != null) {
     76             material.setFloat("VxOffset", this.vxOffset);
     77         }
     78     }
     79 
     80     public float getReduceMul() {
     81         return reduceMul;
     82     }
     83 
     84     public float getSpanMax() {
     85         return spanMax;
     86     }
     87 
     88     public float getSubPixelShift() {
     89         return subPixelShift;
     90     }
     91 
     92     public float getVxOffset() {
     93         return vxOffset;
     94     }
     95 }