aboutsummaryrefslogtreecommitdiff
path: root/engine/src/core-effects/com/jme3/post/filters/FXAAFilter.java
blob: 8ba3c16bb36653b7aaca057652028c16fa8eb5e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package com.jme3.post.filters;

import com.jme3.asset.AssetManager;
import com.jme3.material.Material;
import com.jme3.post.Filter;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;

/**
 * <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>
 * <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>
 *
 * @author Phate666 (adapted to jme3)
 *
 */
public class FXAAFilter extends Filter {

    private float subPixelShift = 1.0f / 4.0f;
    private float vxOffset = 0.0f;
    private float spanMax = 8.0f;
    private float reduceMul = 1.0f / 8.0f;

    public FXAAFilter() {
        super("FXAAFilter");
    }

    @Override
    protected void initFilter(AssetManager manager,
            RenderManager renderManager, ViewPort vp, int w, int h) {
        material = new Material(manager, "Common/MatDefs/Post/FXAA.j3md");   
        material.setFloat("SubPixelShift", subPixelShift);
        material.setFloat("VxOffset", vxOffset);
        material.setFloat("SpanMax", spanMax);
        material.setFloat("ReduceMul", reduceMul);
    }

    @Override
    protected Material getMaterial() {
        return material;
    }

    public void setSpanMax(float spanMax) {
        this.spanMax = spanMax;
        if (material != null) {
            material.setFloat("SpanMax", this.spanMax);
        }
    }

    /**
     * set to 0.0f for higher quality
     *
     * @param subPixelShift
     */
    public void setSubPixelShift(float subPixelShift) {
        this.subPixelShift = subPixelShift;
        if (material != null) {
            material.setFloat("SubPixelShif", this.subPixelShift);
        }
    }

    /**
     * set to 0.0f for higher quality
     *
     * @param reduceMul
     */
    public void setReduceMul(float reduceMul) {
        this.reduceMul = reduceMul;
        if (material != null) {
            material.setFloat("ReduceMul", this.reduceMul);
        }
    }

    public void setVxOffset(float vxOffset) {
        this.vxOffset = vxOffset;
        if (material != null) {
            material.setFloat("VxOffset", this.vxOffset);
        }
    }

    public float getReduceMul() {
        return reduceMul;
    }

    public float getSpanMax() {
        return spanMax;
    }

    public float getSubPixelShift() {
        return subPixelShift;
    }

    public float getVxOffset() {
        return vxOffset;
    }
}