aboutsummaryrefslogtreecommitdiff
path: root/engine/src/core-effects/com/jme3/post/filters
diff options
context:
space:
mode:
authorScott Barta <sbarta@google.com>2012-03-01 12:35:35 -0800
committerScott Barta <sbarta@google.com>2012-03-01 12:40:08 -0800
commit59b2e6871c65f58fdad78cd7229c292f6a177578 (patch)
tree2d4e7bfc05b93f40b34675d77e403dd1c25efafd /engine/src/core-effects/com/jme3/post/filters
parentf9b30489e75ac1eabc365064959804e99534f7ab (diff)
downloadjmonkeyengine-59b2e6871c65f58fdad78cd7229c292f6a177578.tar.gz
Adds the jMonkeyEngine library to the build.
Adds the jMonkeyEngine open source 3D game engine to the build. This is built as a static library and is only used by the Finsky client. Change-Id: I06a3f054df7b8a67757267d884854f70c5a16ca0
Diffstat (limited to 'engine/src/core-effects/com/jme3/post/filters')
-rw-r--r--engine/src/core-effects/com/jme3/post/filters/BloomFilter.java309
-rw-r--r--engine/src/core-effects/com/jme3/post/filters/CartoonEdgeFilter.java245
-rw-r--r--engine/src/core-effects/com/jme3/post/filters/ColorOverlayFilter.java111
-rw-r--r--engine/src/core-effects/com/jme3/post/filters/CrossHatchFilter.java305
-rw-r--r--engine/src/core-effects/com/jme3/post/filters/DepthOfFieldFilter.java158
-rw-r--r--engine/src/core-effects/com/jme3/post/filters/FXAAFilter.java95
-rw-r--r--engine/src/core-effects/com/jme3/post/filters/FadeFilter.java177
-rw-r--r--engine/src/core-effects/com/jme3/post/filters/FogFilter.java172
-rw-r--r--engine/src/core-effects/com/jme3/post/filters/GammaCorrectionFilter.java78
-rw-r--r--engine/src/core-effects/com/jme3/post/filters/LightScatteringFilter.java243
-rw-r--r--engine/src/core-effects/com/jme3/post/filters/PosterizationFilter.java147
-rw-r--r--engine/src/core-effects/com/jme3/post/filters/RadialBlurFilter.java156
-rw-r--r--engine/src/core-effects/com/jme3/post/filters/TranslucentBucketFilter.java80
13 files changed, 2276 insertions, 0 deletions
diff --git a/engine/src/core-effects/com/jme3/post/filters/BloomFilter.java b/engine/src/core-effects/com/jme3/post/filters/BloomFilter.java
new file mode 100644
index 0000000..770e7f4
--- /dev/null
+++ b/engine/src/core-effects/com/jme3/post/filters/BloomFilter.java
@@ -0,0 +1,309 @@
+/*
+ * Copyright (c) 2009-2010 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.jme3.post.filters;
+
+import com.jme3.asset.AssetManager;
+import com.jme3.export.InputCapsule;
+import com.jme3.export.JmeExporter;
+import com.jme3.export.JmeImporter;
+import com.jme3.export.OutputCapsule;
+import com.jme3.material.Material;
+import com.jme3.math.ColorRGBA;
+import com.jme3.post.Filter;
+import com.jme3.renderer.RenderManager;
+import com.jme3.renderer.ViewPort;
+import com.jme3.texture.Image.Format;
+import java.io.IOException;
+import java.util.ArrayList;
+
+/**
+ * BloomFilter is used to make objects in the scene have a glow effect.<br>
+ * There are 2 mode : Scene and Objects.<br>
+ * Scene mode extracts the bright parts of the scene to make them glow<br>
+ * Object mode make objects glow according to their material's glowMap or their GlowColor<br>
+ * @see <a href="http://jmonkeyengine.org/wiki/doku.php/jme3:advanced:bloom_and_glow">advanced:bloom_and_glow</a> for more details
+ *
+ * @author Rémy Bouquet aka Nehon
+ */
+public class BloomFilter extends Filter {
+
+ /**
+ * GlowMode specifies if the glow will be applied to the whole scene,or to objects that have aglow color or a glow map
+ */
+ public enum GlowMode {
+
+ /**
+ * Apply bloom filter to bright areas in the scene.
+ */
+ Scene,
+ /**
+ * Apply bloom only to objects that have a glow map or a glow color.
+ */
+ Objects,
+ /**
+ * Apply bloom to both bright parts of the scene and objects with glow map.
+ */
+ SceneAndObjects;
+ }
+
+ private GlowMode glowMode = GlowMode.Scene;
+ //Bloom parameters
+ private float blurScale = 1.5f;
+ private float exposurePower = 5.0f;
+ private float exposureCutOff = 0.0f;
+ private float bloomIntensity = 2.0f;
+ private float downSamplingFactor = 1;
+ private Pass preGlowPass;
+ private Pass extractPass;
+ private Pass horizontalBlur = new Pass();
+ private Pass verticalalBlur = new Pass();
+ private Material extractMat;
+ private Material vBlurMat;
+ private Material hBlurMat;
+ private int screenWidth;
+ private int screenHeight;
+
+ /**
+ * Creates a Bloom filter
+ */
+ public BloomFilter() {
+ super("BloomFilter");
+ }
+
+ /**
+ * Creates the bloom filter with the specific glow mode
+ * @param glowMode
+ */
+ public BloomFilter(GlowMode glowMode) {
+ this();
+ this.glowMode = glowMode;
+ }
+
+ @Override
+ protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
+ screenWidth = (int) Math.max(1, (w / downSamplingFactor));
+ screenHeight = (int) Math.max(1, (h / downSamplingFactor));
+ // System.out.println(screenWidth + " " + screenHeight);
+ if (glowMode != GlowMode.Scene) {
+ preGlowPass = new Pass();
+ preGlowPass.init(renderManager.getRenderer(), screenWidth, screenHeight, Format.RGBA8, Format.Depth);
+ }
+
+ postRenderPasses = new ArrayList<Pass>();
+ //configuring extractPass
+ extractMat = new Material(manager, "Common/MatDefs/Post/BloomExtract.j3md");
+ extractPass = new Pass() {
+
+ @Override
+ public boolean requiresSceneAsTexture() {
+ return true;
+ }
+
+ @Override
+ public void beforeRender() {
+ extractMat.setFloat("ExposurePow", exposurePower);
+ extractMat.setFloat("ExposureCutoff", exposureCutOff);
+ if (glowMode != GlowMode.Scene) {
+ extractMat.setTexture("GlowMap", preGlowPass.getRenderedTexture());
+ }
+ extractMat.setBoolean("Extract", glowMode != GlowMode.Objects);
+ }
+ };
+
+ extractPass.init(renderManager.getRenderer(), screenWidth, screenHeight, Format.RGBA8, Format.Depth, 1, extractMat);
+ postRenderPasses.add(extractPass);
+
+ //configuring horizontal blur pass
+ hBlurMat = new Material(manager, "Common/MatDefs/Blur/HGaussianBlur.j3md");
+ horizontalBlur = new Pass() {
+
+ @Override
+ public void beforeRender() {
+ hBlurMat.setTexture("Texture", extractPass.getRenderedTexture());
+ hBlurMat.setFloat("Size", screenWidth);
+ hBlurMat.setFloat("Scale", blurScale);
+ }
+ };
+
+ horizontalBlur.init(renderManager.getRenderer(), screenWidth, screenHeight, Format.RGBA8, Format.Depth, 1, hBlurMat);
+ postRenderPasses.add(horizontalBlur);
+
+ //configuring vertical blur pass
+ vBlurMat = new Material(manager, "Common/MatDefs/Blur/VGaussianBlur.j3md");
+ verticalalBlur = new Pass() {
+
+ @Override
+ public void beforeRender() {
+ vBlurMat.setTexture("Texture", horizontalBlur.getRenderedTexture());
+ vBlurMat.setFloat("Size", screenHeight);
+ vBlurMat.setFloat("Scale", blurScale);
+ }
+ };
+
+ verticalalBlur.init(renderManager.getRenderer(), screenWidth, screenHeight, Format.RGBA8, Format.Depth, 1, vBlurMat);
+ postRenderPasses.add(verticalalBlur);
+
+
+ //final material
+ material = new Material(manager, "Common/MatDefs/Post/BloomFinal.j3md");
+ material.setTexture("BloomTex", verticalalBlur.getRenderedTexture());
+ }
+
+
+ @Override
+ protected Material getMaterial() {
+ material.setFloat("BloomIntensity", bloomIntensity);
+ return material;
+ }
+
+ @Override
+ protected void postQueue(RenderManager renderManager, ViewPort viewPort) {
+ if (glowMode != GlowMode.Scene) {
+ renderManager.getRenderer().setBackgroundColor(ColorRGBA.BlackNoAlpha);
+ renderManager.getRenderer().setFrameBuffer(preGlowPass.getRenderFrameBuffer());
+ renderManager.getRenderer().clearBuffers(true, true, true);
+ renderManager.setForcedTechnique("Glow");
+ renderManager.renderViewPortQueues(viewPort, false);
+ renderManager.setForcedTechnique(null);
+ renderManager.getRenderer().setFrameBuffer(viewPort.getOutputFrameBuffer());
+ }
+ }
+
+ /**
+ * returns the bloom intensity
+ * @return
+ */
+ public float getBloomIntensity() {
+ return bloomIntensity;
+ }
+
+ /**
+ * intensity of the bloom effect default is 2.0
+ * @param bloomIntensity
+ */
+ public void setBloomIntensity(float bloomIntensity) {
+ this.bloomIntensity = bloomIntensity;
+ }
+
+ /**
+ * returns the blur scale
+ * @return
+ */
+ public float getBlurScale() {
+ return blurScale;
+ }
+
+ /**
+ * sets The spread of the bloom default is 1.5f
+ * @param blurScale
+ */
+ public void setBlurScale(float blurScale) {
+ this.blurScale = blurScale;
+ }
+
+ /**
+ * returns the exposure cutoff<br>
+ * for more details see {@link setExposureCutOff(float exposureCutOff)}
+ * @return
+ */
+ public float getExposureCutOff() {
+ return exposureCutOff;
+ }
+
+ /**
+ * Define the color threshold on which the bloom will be applied (0.0 to 1.0)
+ * @param exposureCutOff
+ */
+ public void setExposureCutOff(float exposureCutOff) {
+ this.exposureCutOff = exposureCutOff;
+ }
+
+ /**
+ * returns the exposure power<br>
+ * form more details see {@link setExposurePower(float exposurePower)}
+ * @return
+ */
+ public float getExposurePower() {
+ return exposurePower;
+ }
+
+ /**
+ * defines how many time the bloom extracted color will be multiplied by itself. default id 5.0<br>
+ * a high value will reduce rough edges in the bloom and somhow the range of the bloom area *
+ * @param exposurePower
+ */
+ public void setExposurePower(float exposurePower) {
+ this.exposurePower = exposurePower;
+ }
+
+ /**
+ * returns the downSampling factor<br>
+ * form more details see {@link setDownSamplingFactor(float downSamplingFactor)}
+ * @return
+ */
+ public float getDownSamplingFactor() {
+ return downSamplingFactor;
+ }
+
+ /**
+ * Sets the downSampling factor : the size of the computed texture will be divided by this factor. default is 1 for no downsampling
+ * A 2 value is a good way of widening the blur
+ * @param downSamplingFactor
+ */
+ public void setDownSamplingFactor(float downSamplingFactor) {
+ this.downSamplingFactor = downSamplingFactor;
+ }
+
+ @Override
+ public void write(JmeExporter ex) throws IOException {
+ super.write(ex);
+ OutputCapsule oc = ex.getCapsule(this);
+ oc.write(glowMode, "glowMode", GlowMode.Scene);
+ oc.write(blurScale, "blurScale", 1.5f);
+ oc.write(exposurePower, "exposurePower", 5.0f);
+ oc.write(exposureCutOff, "exposureCutOff", 0.0f);
+ oc.write(bloomIntensity, "bloomIntensity", 2.0f);
+ oc.write(downSamplingFactor, "downSamplingFactor", 1);
+ }
+
+ @Override
+ public void read(JmeImporter im) throws IOException {
+ super.read(im);
+ InputCapsule ic = im.getCapsule(this);
+ glowMode = ic.readEnum("glowMode", GlowMode.class, GlowMode.Scene);
+ blurScale = ic.readFloat("blurScale", 1.5f);
+ exposurePower = ic.readFloat("exposurePower", 5.0f);
+ exposureCutOff = ic.readFloat("exposureCutOff", 0.0f);
+ bloomIntensity = ic.readFloat("bloomIntensity", 2.0f);
+ downSamplingFactor = ic.readFloat("downSamplingFactor", 1);
+ }
+}
diff --git a/engine/src/core-effects/com/jme3/post/filters/CartoonEdgeFilter.java b/engine/src/core-effects/com/jme3/post/filters/CartoonEdgeFilter.java
new file mode 100644
index 0000000..3e9998b
--- /dev/null
+++ b/engine/src/core-effects/com/jme3/post/filters/CartoonEdgeFilter.java
@@ -0,0 +1,245 @@
+/*
+ * Copyright (c) 2009-2010 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.jme3.post.filters;
+
+import com.jme3.asset.AssetManager;
+import com.jme3.material.Material;
+import com.jme3.math.ColorRGBA;
+import com.jme3.post.Filter;
+import com.jme3.post.Filter.Pass;
+import com.jme3.renderer.RenderManager;
+import com.jme3.renderer.Renderer;
+import com.jme3.renderer.ViewPort;
+import com.jme3.texture.Image.Format;
+
+/**
+ * Applies a cartoon-style edge detection filter to all objects in the scene.
+ *
+ * @author Kirill Vainer
+ */
+public class CartoonEdgeFilter extends Filter {
+
+ private Pass normalPass;
+ private float edgeWidth = 1.0f;
+ private float edgeIntensity = 1.0f;
+ private float normalThreshold = 0.5f;
+ private float depthThreshold = 0.1f;
+ private float normalSensitivity = 1.0f;
+ private float depthSensitivity = 10.0f;
+ private ColorRGBA edgeColor = new ColorRGBA(0, 0, 0, 1);
+
+ /**
+ * Creates a CartoonEdgeFilter
+ */
+ public CartoonEdgeFilter() {
+ super("CartoonEdgeFilter");
+ }
+
+ @Override
+ protected boolean isRequiresDepthTexture() {
+ return true;
+ }
+
+ @Override
+ protected void postQueue(RenderManager renderManager, ViewPort viewPort) {
+ Renderer r = renderManager.getRenderer();
+ r.setFrameBuffer(normalPass.getRenderFrameBuffer());
+ renderManager.getRenderer().clearBuffers(true, true, true);
+ renderManager.setForcedTechnique("PreNormalPass");
+ renderManager.renderViewPortQueues(viewPort, false);
+ renderManager.setForcedTechnique(null);
+ renderManager.getRenderer().setFrameBuffer(viewPort.getOutputFrameBuffer());
+ }
+
+ @Override
+ protected Material getMaterial() {
+ material.setTexture("NormalsTexture", normalPass.getRenderedTexture());
+ return material;
+ }
+
+ @Override
+ protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
+ normalPass = new Pass();
+ normalPass.init(renderManager.getRenderer(), w, h, Format.RGBA8, Format.Depth);
+ material = new Material(manager, "Common/MatDefs/Post/CartoonEdge.j3md");
+ material.setFloat("EdgeWidth", edgeWidth);
+ material.setFloat("EdgeIntensity", edgeIntensity);
+ material.setFloat("NormalThreshold", normalThreshold);
+ material.setFloat("DepthThreshold", depthThreshold);
+ material.setFloat("NormalSensitivity", normalSensitivity);
+ material.setFloat("DepthSensitivity", depthSensitivity);
+ material.setColor("EdgeColor", edgeColor);
+ }
+
+ /**
+ * Return the depth sensitivity<br>
+ * for more details see {@link setDepthSensitivity(float depthSensitivity)}
+ * @return
+ */
+ public float getDepthSensitivity() {
+ return depthSensitivity;
+ }
+
+ /**
+ * sets the depth sensitivity<br>
+ * defines how much depth will influence edges, default is 10
+ * @param depthSensitivity
+ */
+ public void setDepthSensitivity(float depthSensitivity) {
+ this.depthSensitivity = depthSensitivity;
+ if (material != null) {
+ material.setFloat("DepthSensitivity", depthSensitivity);
+ }
+ }
+
+ /**
+ * returns the depth threshold<br>
+ * for more details see {@link setDepthThreshold(float depthThreshold)}
+ * @return
+ */
+ public float getDepthThreshold() {
+ return depthThreshold;
+ }
+
+ /**
+ * sets the depth threshold<br>
+ * Defines at what threshold of difference of depth an edge is outlined default is 0.1f
+ * @param depthThreshold
+ */
+ public void setDepthThreshold(float depthThreshold) {
+ this.depthThreshold = depthThreshold;
+ if (material != null) {
+ material.setFloat("DepthThreshold", depthThreshold);
+ }
+ }
+
+ /**
+ * returns the edge intensity<br>
+ * for more details see {@link setEdgeIntensity(float edgeIntensity) }
+ * @return
+ */
+ public float getEdgeIntensity() {
+ return edgeIntensity;
+ }
+
+ /**
+ * sets the edge intensity<br>
+ * Defineshow visilble will be the outlined edges
+ * @param edgeIntensity
+ */
+ public void setEdgeIntensity(float edgeIntensity) {
+ this.edgeIntensity = edgeIntensity;
+ if (material != null) {
+ material.setFloat("EdgeIntensity", edgeIntensity);
+ }
+ }
+
+ /**
+ * returns the width of the edges
+ * @return
+ */
+ public float getEdgeWidth() {
+ return edgeWidth;
+ }
+
+ /**
+ * sets the witdh of the edge in pixels default is 1
+ * @param edgeWidth
+ */
+ public void setEdgeWidth(float edgeWidth) {
+ this.edgeWidth = edgeWidth;
+ if (material != null) {
+ material.setFloat("EdgeWidth", edgeWidth);
+ }
+
+ }
+
+ /**
+ * returns the normals sensitivity<br>
+ * form more details see {@link setNormalSensitivity(float normalSensitivity)}
+ * @return
+ */
+ public float getNormalSensitivity() {
+ return normalSensitivity;
+ }
+
+ /**
+ * sets the normals sensitivity default is 1
+ * @param normalSensitivity
+ */
+ public void setNormalSensitivity(float normalSensitivity) {
+ this.normalSensitivity = normalSensitivity;
+ if (material != null) {
+ material.setFloat("NormalSensitivity", normalSensitivity);
+ }
+ }
+
+ /**
+ * returns the normal threshold<br>
+ * for more details see {@link setNormalThreshold(float normalThreshold)}
+ *
+ * @return
+ */
+ public float getNormalThreshold() {
+ return normalThreshold;
+ }
+
+ /**
+ * sets the normal threshold default is 0.5
+ * @param normalThreshold
+ */
+ public void setNormalThreshold(float normalThreshold) {
+ this.normalThreshold = normalThreshold;
+ if (material != null) {
+ material.setFloat("NormalThreshold", normalThreshold);
+ }
+ }
+
+ /**
+ * returns the edge color
+ * @return
+ */
+ public ColorRGBA getEdgeColor() {
+ return edgeColor;
+ }
+
+ /**
+ * Sets the edge color, default is black
+ * @param edgeColor
+ */
+ public void setEdgeColor(ColorRGBA edgeColor) {
+ this.edgeColor = edgeColor;
+ if (material != null) {
+ material.setColor("EdgeColor", edgeColor);
+ }
+ }
+}
diff --git a/engine/src/core-effects/com/jme3/post/filters/ColorOverlayFilter.java b/engine/src/core-effects/com/jme3/post/filters/ColorOverlayFilter.java
new file mode 100644
index 0000000..a7f30f8
--- /dev/null
+++ b/engine/src/core-effects/com/jme3/post/filters/ColorOverlayFilter.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2009-2010 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.jme3.post.filters;
+
+import com.jme3.asset.AssetManager;
+import com.jme3.export.InputCapsule;
+import com.jme3.export.JmeExporter;
+import com.jme3.export.JmeImporter;
+import com.jme3.export.OutputCapsule;
+import com.jme3.material.Material;
+import com.jme3.math.ColorRGBA;
+import com.jme3.post.Filter;
+import com.jme3.renderer.RenderManager;
+import com.jme3.renderer.ViewPort;
+import java.io.IOException;
+
+/**
+ * This filter simply multiply the whole scene by a color
+ * @author Rémy Bouquet aka Nehon
+ */
+public class ColorOverlayFilter extends Filter {
+
+ private ColorRGBA color = ColorRGBA.White;
+
+ /**
+ * creates a colorOverlayFilter with a white coor (transparent)
+ */
+ public ColorOverlayFilter() {
+ super("Color Overlay");
+ }
+
+ /**
+ * creates a colorOverlayFilter with the given color
+ * @param color
+ */
+ public ColorOverlayFilter(ColorRGBA color) {
+ this();
+ this.color = color;
+ }
+
+ @Override
+ protected Material getMaterial() {
+
+ material.setColor("Color", color);
+ return material;
+ }
+
+ /**
+ * returns the color
+ * @return color
+ */
+ public ColorRGBA getColor() {
+ return color;
+ }
+
+ /**
+ * sets the color
+ * @param color
+ */
+ public void setColor(ColorRGBA color) {
+ this.color = color;
+ }
+
+ @Override
+ protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
+ material = new Material(manager, "Common/MatDefs/Post/Overlay.j3md");
+ }
+
+ @Override
+ public void write(JmeExporter ex) throws IOException {
+ super.write(ex);
+ OutputCapsule oc = ex.getCapsule(this);
+ oc.write(color, "color", ColorRGBA.White);
+ }
+
+ @Override
+ public void read(JmeImporter im) throws IOException {
+ super.read(im);
+ InputCapsule ic = im.getCapsule(this);
+ color = (ColorRGBA) ic.readSavable("color", ColorRGBA.White);
+ }
+}
diff --git a/engine/src/core-effects/com/jme3/post/filters/CrossHatchFilter.java b/engine/src/core-effects/com/jme3/post/filters/CrossHatchFilter.java
new file mode 100644
index 0000000..699a252
--- /dev/null
+++ b/engine/src/core-effects/com/jme3/post/filters/CrossHatchFilter.java
@@ -0,0 +1,305 @@
+/*
+ * Copyright (c) 2009-2012 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.jme3.post.filters;
+
+import com.jme3.asset.AssetManager;
+import com.jme3.material.Material;
+import com.jme3.math.ColorRGBA;
+import com.jme3.post.Filter;
+import com.jme3.renderer.RenderManager;
+import com.jme3.renderer.ViewPort;
+
+/**
+ * A Post Processing filter that makes the screen look like it was drawn as
+ * diagonal lines with a pen.
+ * Try combining this with a cartoon edge filter to obtain manga style visuals.
+ *
+ * Based on an article from Geeks3D:
+ * <a href="http://www.geeks3d.com/20110219/shader-library-crosshatching-glsl-filter/" rel="nofollow">http://www.geeks3d.com/20110219/shader-library-crosshatching-glsl-filter/</a>
+ *
+ * @author Roy Straver a.k.a. Baal Garnaal
+ */
+public class CrossHatchFilter extends Filter {
+
+ private ColorRGBA lineColor = ColorRGBA.Black.clone();
+ private ColorRGBA paperColor = ColorRGBA.White.clone();
+ private float colorInfluenceLine = 0.8f;
+ private float colorInfluencePaper = 0.1f;
+ private float fillValue = 0.9f;
+ private float luminance1 = 0.9f;
+ private float luminance2 = 0.7f;
+ private float luminance3 = 0.5f;
+ private float luminance4 = 0.3f;
+ private float luminance5 = 0.0f;
+ private float lineThickness = 1.0f;
+ private float lineDistance = 4.0f;
+
+ /**
+ * Creates a crossHatch filter
+ */
+ public CrossHatchFilter() {
+ super("CrossHatchFilter");
+ }
+
+ /**
+ * Creates a crossHatch filter
+ * @param lineColor the colors of the lines
+ * @param paperColor the paper color
+ */
+ public CrossHatchFilter(ColorRGBA lineColor, ColorRGBA paperColor) {
+ this();
+ this.lineColor = lineColor;
+ this.paperColor = paperColor;
+ }
+
+ @Override
+ protected boolean isRequiresDepthTexture() {
+ return false;
+ }
+
+ @Override
+ protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
+ material = new Material(manager, "Common/MatDefs/Post/CrossHatch.j3md");
+ material.setColor("LineColor", lineColor);
+ material.setColor("PaperColor", paperColor);
+
+ material.setFloat("ColorInfluenceLine", colorInfluenceLine);
+ material.setFloat("ColorInfluencePaper", colorInfluencePaper);
+
+ material.setFloat("FillValue", fillValue);
+
+ material.setFloat("Luminance1", luminance1);
+ material.setFloat("Luminance2", luminance2);
+ material.setFloat("Luminance3", luminance3);
+ material.setFloat("Luminance4", luminance4);
+ material.setFloat("Luminance5", luminance5);
+
+ material.setFloat("LineThickness", lineThickness);
+ material.setFloat("LineDistance", lineDistance);
+ }
+
+ @Override
+ protected Material getMaterial() {
+ return material;
+ }
+
+ /**
+ * Sets color used to draw lines
+ * @param lineColor
+ */
+ public void setLineColor(ColorRGBA lineColor) {
+ this.lineColor = lineColor;
+ if (material != null) {
+ material.setColor("LineColor", lineColor);
+ }
+ }
+
+ /**
+ * Sets color used as background
+ * @param paperColor
+ */
+ public void setPaperColor(ColorRGBA paperColor) {
+ this.paperColor = paperColor;
+ if (material != null) {
+ material.setColor("PaperColor", paperColor);
+ }
+ }
+
+ /**
+ * Sets color influence of original image on lines drawn
+ * @param colorInfluenceLine
+ */
+ public void setColorInfluenceLine(float colorInfluenceLine) {
+ this.colorInfluenceLine = colorInfluenceLine;
+ if (material != null) {
+ material.setFloat("ColorInfluenceLine", colorInfluenceLine);
+ }
+ }
+
+ /**
+ * Sets color influence of original image on non-line areas
+ * @param colorInfluencePaper
+ */
+ public void setColorInfluencePaper(float colorInfluencePaper) {
+ this.colorInfluencePaper = colorInfluencePaper;
+ if (material != null) {
+ material.setFloat("ColorInfluencePaper", colorInfluencePaper);
+ }
+ }
+
+ /**
+ * Sets line/paper color ratio for areas with values < luminance5,
+ * really dark areas get no lines but a filled blob instead
+ * @param fillValue
+ */
+ public void setFillValue(float fillValue) {
+ this.fillValue = fillValue;
+ if (material != null) {
+ material.setFloat("FillValue", fillValue);
+ }
+ }
+
+ /**
+ *
+ * Sets minimum luminance levels for lines drawn
+ * @param luminance1 Top-left to down right 1
+ * @param luminance2 Top-right to bottom left 1
+ * @param luminance3 Top-left to down right 2
+ * @param luminance4 Top-right to bottom left 2
+ * @param luminance5 Blobs
+ */
+ public void setLuminanceLevels(float luminance1, float luminance2, float luminance3, float luminance4, float luminance5) {
+ this.luminance1 = luminance1;
+ this.luminance2 = luminance2;
+ this.luminance3 = luminance3;
+ this.luminance4 = luminance4;
+ this.luminance5 = luminance5;
+
+ if (material != null) {
+ material.setFloat("Luminance1", luminance1);
+ material.setFloat("Luminance2", luminance2);
+ material.setFloat("Luminance3", luminance3);
+ material.setFloat("Luminance4", luminance4);
+ material.setFloat("Luminance5", luminance5);
+ }
+ }
+
+ /**
+ * Sets the thickness of lines drawn
+ * @param lineThickness
+ */
+ public void setLineThickness(float lineThickness) {
+ this.lineThickness = lineThickness;
+ if (material != null) {
+ material.setFloat("LineThickness", lineThickness);
+ }
+ }
+
+ /**
+ * Sets minimum distance between lines drawn
+ * Primary lines are drawn at 2*lineDistance
+ * Secondary lines are drawn at lineDistance
+ * @param lineDistance
+ */
+ public void setLineDistance(float lineDistance) {
+ this.lineDistance = lineDistance;
+ if (material != null) {
+ material.setFloat("LineDistance", lineDistance);
+ }
+ }
+
+ /**
+ * Returns line color
+ * @return
+ */
+ public ColorRGBA getLineColor() {
+ return lineColor;
+ }
+
+ /**
+ * Returns paper background color
+ * @return
+ */
+ public ColorRGBA getPaperColor() {
+ return paperColor;
+ }
+
+ /**
+ * Returns current influence of image colors on lines
+ */
+ public float getColorInfluenceLine() {
+ return colorInfluenceLine;
+ }
+
+ /**
+ * Returns current influence of image colors on paper background
+ */
+ public float getColorInfluencePaper() {
+ return colorInfluencePaper;
+ }
+
+ /**
+ * Returns line/paper color ratio for blobs
+ */
+ public float getFillValue() {
+ return fillValue;
+ }
+
+ /**
+ * Returns the thickness of the lines drawn
+ */
+ public float getLineThickness() {
+ return lineThickness;
+ }
+
+ /**
+ * Returns minimum distance between lines
+ */
+ public float getLineDistance() {
+ return lineDistance;
+ }
+
+ /**
+ * Returns treshold for lines 1
+ */
+ public float getLuminance1() {
+ return luminance1;
+ }
+
+ /**
+ * Returns treshold for lines 2
+ */
+ public float getLuminance2() {
+ return luminance2;
+ }
+
+ /**
+ * Returns treshold for lines 3
+ */
+ public float getLuminance3() {
+ return luminance3;
+ }
+
+ /**
+ * Returns treshold for lines 4
+ */
+ public float getLuminance4() {
+ return luminance4;
+ }
+
+ /**
+ * Returns treshold for blobs
+ */
+ public float getLuminance5() {
+ return luminance5;
+ }
+} \ No newline at end of file
diff --git a/engine/src/core-effects/com/jme3/post/filters/DepthOfFieldFilter.java b/engine/src/core-effects/com/jme3/post/filters/DepthOfFieldFilter.java
new file mode 100644
index 0000000..55591c9
--- /dev/null
+++ b/engine/src/core-effects/com/jme3/post/filters/DepthOfFieldFilter.java
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2009-2010 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+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 post-processing filter that performs a depth range
+ * blur using a scaled convolution filter.
+ *
+ * @version $Revision: 779 $
+ * @author Paul Speed
+ */
+public class DepthOfFieldFilter extends Filter {
+
+ private float focusDistance = 50f;
+ private float focusRange = 10f;
+ private float blurScale = 1f;
+ // These values are set internally based on the
+ // viewport size.
+ private float xScale;
+ private float yScale;
+
+ /**
+ * Creates a DepthOfField filter
+ */
+ public DepthOfFieldFilter() {
+ super("Depth Of Field");
+ }
+
+ @Override
+ protected boolean isRequiresDepthTexture() {
+ return true;
+ }
+
+ @Override
+ protected Material getMaterial() {
+
+ return material;
+ }
+
+ @Override
+ protected void initFilter(AssetManager assets, RenderManager renderManager,
+ ViewPort vp, int w, int h) {
+ material = new Material(assets, "Common/MatDefs/Post/DepthOfField.j3md");
+ material.setFloat("FocusDistance", focusDistance);
+ material.setFloat("FocusRange", focusRange);
+
+
+ xScale = 1.0f / w;
+ yScale = 1.0f / h;
+
+ material.setFloat("XScale", blurScale * xScale);
+ material.setFloat("YScale", blurScale * yScale);
+ }
+
+ /**
+ * Sets the distance at which objects are purely in focus.
+ */
+ public void setFocusDistance(float f) {
+
+ this.focusDistance = f;
+ if (material != null) {
+ material.setFloat("FocusDistance", focusDistance);
+ }
+
+ }
+
+ /**
+ * returns the focus distance
+ * @return
+ */
+ public float getFocusDistance() {
+ return focusDistance;
+ }
+
+ /**
+ * Sets the range to either side of focusDistance where the
+ * objects go gradually out of focus. Less than focusDistance - focusRange
+ * and greater than focusDistance + focusRange, objects are maximally "blurred".
+ */
+ public void setFocusRange(float f) {
+ this.focusRange = f;
+ if (material != null) {
+ material.setFloat("FocusRange", focusRange);
+ }
+
+ }
+
+ /**
+ * returns the focus range
+ * @return
+ */
+ public float getFocusRange() {
+ return focusRange;
+ }
+
+ /**
+ * Sets the blur amount by scaling the convolution filter up or
+ * down. A value of 1 (the default) performs a sparse 5x5 evenly
+ * distribubted convolution at pixel level accuracy. Higher values skip
+ * more pixels, and so on until you are no longer blurring the image
+ * but simply hashing it.
+ *
+ * The sparse convolution is as follows:
+ *%MINIFYHTMLc3d0cd9fab65de6875a381fd3f83e1b338%*
+ * Where 'x' is the texel being modified. Setting blur scale higher
+ * than 1 spaces the samples out.
+ */
+ public void setBlurScale(float f) {
+ this.blurScale = f;
+ if (material != null) {
+ material.setFloat("XScale", blurScale * xScale);
+ material.setFloat("YScale", blurScale * yScale);
+ }
+ }
+
+ /**
+ * returns the blur scale
+ * @return
+ */
+ public float getBlurScale() {
+ return blurScale;
+ }
+}
diff --git a/engine/src/core-effects/com/jme3/post/filters/FXAAFilter.java b/engine/src/core-effects/com/jme3/post/filters/FXAAFilter.java
new file mode 100644
index 0000000..8ba3c16
--- /dev/null
+++ b/engine/src/core-effects/com/jme3/post/filters/FXAAFilter.java
@@ -0,0 +1,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;
+ }
+} \ No newline at end of file
diff --git a/engine/src/core-effects/com/jme3/post/filters/FadeFilter.java b/engine/src/core-effects/com/jme3/post/filters/FadeFilter.java
new file mode 100644
index 0000000..1fb2340
--- /dev/null
+++ b/engine/src/core-effects/com/jme3/post/filters/FadeFilter.java
@@ -0,0 +1,177 @@
+/*
+ * Copyright (c) 2009-2010 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.jme3.post.filters;
+
+import com.jme3.asset.AssetManager;
+import com.jme3.export.InputCapsule;
+import com.jme3.export.JmeExporter;
+import com.jme3.export.JmeImporter;
+import com.jme3.export.OutputCapsule;
+import com.jme3.material.Material;
+import com.jme3.post.Filter;
+import com.jme3.renderer.RenderManager;
+import com.jme3.renderer.ViewPort;
+import java.io.IOException;
+
+/**
+ *
+ * Fade Filter allows you to make an animated fade effect on a scene.
+ * @author Rémy Bouquet aka Nehon
+ * implemented from boxjar implementation
+ * @see <a href="http://jmonkeyengine.org/groups/graphics/forum/topic/newbie-question-general-fade-inout-effect/#post-105559">http://jmonkeyengine.org/groups/graphics/forum/topic/newbie-question-general-fade-inout-effect/#post-105559</a>
+ */
+public class FadeFilter extends Filter {
+
+ private float value = 1;
+ private boolean playing = false;
+ private float direction = 1;
+ private float duration = 1;
+
+ /**
+ * Creates a FadeFilter
+ */
+ public FadeFilter() {
+ super("Fade In/Out");
+ }
+
+ /**
+ * Creates a FadeFilter with the given duration
+ * @param duration
+ */
+ public FadeFilter(float duration) {
+ this();
+ this.duration = duration;
+ }
+
+ @Override
+ protected Material getMaterial() {
+ material.setFloat("Value", value);
+ return material;
+ }
+
+ @Override
+ protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
+ material = new Material(manager, "Common/MatDefs/Post/Fade.j3md");
+ }
+
+ @Override
+ protected void preFrame(float tpf) {
+ if (playing) {
+ value += tpf * direction / duration;
+
+ if (direction > 0 && value > 1) {
+ value = 1;
+ playing = false;
+ setEnabled(false);
+ }
+ if (direction < 0 && value < 0) {
+ value = 0;
+ playing = false;
+ setEnabled(false);
+ }
+ }
+ }
+
+ /**
+ * returns the duration of the effect
+ * @return
+ */
+ public float getDuration() {
+ return duration;
+ }
+
+ /**
+ * Sets the duration of the filter default is 1 second
+ * @param duration
+ */
+ public void setDuration(float duration) {
+ this.duration = duration;
+ }
+
+ /**
+ * fades the scene in (black to scene)
+ */
+ public void fadeIn() {
+ setEnabled(true);
+ direction = 1;
+ playing = true;
+ }
+
+ /**
+ * fades the scene out (scene to black)
+ */
+ public void fadeOut() {
+ setEnabled(true);
+ direction = -1;
+ playing = true;
+
+ }
+
+ public void pause() {
+ playing = false;
+ }
+
+ @Override
+ public void write(JmeExporter ex) throws IOException {
+ super.write(ex);
+ OutputCapsule oc = ex.getCapsule(this);
+ oc.write(duration, "duration", 1);
+ }
+
+ @Override
+ public void read(JmeImporter im) throws IOException {
+ super.read(im);
+ InputCapsule ic = im.getCapsule(this);
+ duration = ic.readFloat("duration", 1);
+ }
+
+ /**
+ * return the current value of the fading
+ * can be used to chack if fade is complete (eg value=1)
+ * @return
+ */
+ public float getValue() {
+ return value;
+ }
+
+ /**
+ * sets the fade value
+ * can be used to force complete black or compete scene
+ * @param value
+ */
+ public void setValue(float value) {
+ this.value = value;
+ if (material != null) {
+ material.setFloat("Value", value);
+ }
+ }
+}
diff --git a/engine/src/core-effects/com/jme3/post/filters/FogFilter.java b/engine/src/core-effects/com/jme3/post/filters/FogFilter.java
new file mode 100644
index 0000000..c1df3b7
--- /dev/null
+++ b/engine/src/core-effects/com/jme3/post/filters/FogFilter.java
@@ -0,0 +1,172 @@
+/*
+ * Copyright (c) 2009-2012 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.jme3.post.filters;
+
+import com.jme3.asset.AssetManager;
+import com.jme3.export.InputCapsule;
+import com.jme3.export.JmeExporter;
+import com.jme3.export.JmeImporter;
+import com.jme3.export.OutputCapsule;
+import com.jme3.material.Material;
+import com.jme3.math.ColorRGBA;
+import com.jme3.post.Filter;
+import com.jme3.renderer.RenderManager;
+import com.jme3.renderer.ViewPort;
+import java.io.IOException;
+
+/**
+ * A filter to render a fog effect
+ * @author Rémy Bouquet aka Nehon
+ */
+public class FogFilter extends Filter {
+
+ private ColorRGBA fogColor = ColorRGBA.White.clone();
+ private float fogDensity = 0.7f;
+ private float fogDistance = 1000;
+
+ /**
+ * Creates a FogFilter
+ */
+ public FogFilter() {
+ super("FogFilter");
+ }
+
+ /**
+ * Create a fog filter
+ * @param fogColor the color of the fog (default is white)
+ * @param fogDensity the density of the fog (default is 0.7)
+ * @param fogDistance the distance of the fog (default is 1000)
+ */
+ public FogFilter(ColorRGBA fogColor, float fogDensity, float fogDistance) {
+ this();
+ this.fogColor = fogColor;
+ this.fogDensity = fogDensity;
+ this.fogDistance = fogDistance;
+ }
+
+ @Override
+ protected boolean isRequiresDepthTexture() {
+ return true;
+ }
+
+ @Override
+ protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
+ material = new Material(manager, "Common/MatDefs/Post/Fog.j3md");
+ material.setColor("FogColor", fogColor);
+ material.setFloat("FogDensity", fogDensity);
+ material.setFloat("FogDistance", fogDistance);
+ }
+
+ @Override
+ protected Material getMaterial() {
+
+ return material;
+ }
+
+
+ /**
+ * returns the fog color
+ * @return
+ */
+ public ColorRGBA getFogColor() {
+ return fogColor;
+ }
+
+ /**
+ * Sets the color of the fog
+ * @param fogColor
+ */
+ public void setFogColor(ColorRGBA fogColor) {
+ if (material != null) {
+ material.setColor("FogColor", fogColor);
+ }
+ this.fogColor = fogColor;
+ }
+
+ /**
+ * returns the fog density
+ * @return
+ */
+ public float getFogDensity() {
+ return fogDensity;
+ }
+
+ /**
+ * Sets the density of the fog, a high value gives a thick fog
+ * @param fogDensity
+ */
+ public void setFogDensity(float fogDensity) {
+ if (material != null) {
+ material.setFloat("FogDensity", fogDensity);
+ }
+ this.fogDensity = fogDensity;
+ }
+
+ /**
+ * returns the fog distance
+ * @return
+ */
+ public float getFogDistance() {
+ return fogDistance;
+ }
+
+ /**
+ * the distance of the fog. the higer the value the distant the fog looks
+ * @param fogDistance
+ */
+ public void setFogDistance(float fogDistance) {
+ if (material != null) {
+ material.setFloat("FogDistance", fogDistance);
+ }
+ this.fogDistance = fogDistance;
+ }
+
+ @Override
+ public void write(JmeExporter ex) throws IOException {
+ super.write(ex);
+ OutputCapsule oc = ex.getCapsule(this);
+ oc.write(fogColor, "fogColor", ColorRGBA.White.clone());
+ oc.write(fogDensity, "fogDensity", 0.7f);
+ oc.write(fogDistance, "fogDistance", 1000);
+ }
+
+ @Override
+ public void read(JmeImporter im) throws IOException {
+ super.read(im);
+ InputCapsule ic = im.getCapsule(this);
+ fogColor = (ColorRGBA) ic.readSavable("fogColor", ColorRGBA.White.clone());
+ fogDensity = ic.readFloat("fogDensity", 0.7f);
+ fogDistance = ic.readFloat("fogDistance", 1000);
+ }
+
+
+}
diff --git a/engine/src/core-effects/com/jme3/post/filters/GammaCorrectionFilter.java b/engine/src/core-effects/com/jme3/post/filters/GammaCorrectionFilter.java
new file mode 100644
index 0000000..9e283ca
--- /dev/null
+++ b/engine/src/core-effects/com/jme3/post/filters/GammaCorrectionFilter.java
@@ -0,0 +1,78 @@
+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;
+
+/**
+ *
+ * @author Phate666
+ * @version 1.0 initial version
+ * @version 1.1 added luma
+ */
+public class GammaCorrectionFilter extends Filter
+{
+ private float gamma = 2.0f;
+ private boolean computeLuma = false;
+
+ public GammaCorrectionFilter()
+ {
+ super("GammaCorrectionFilter");
+ }
+
+ public GammaCorrectionFilter(float gamma)
+ {
+ this();
+ this.setGamma(gamma);
+ }
+
+ @Override
+ protected Material getMaterial()
+ {
+ return material;
+ }
+
+ @Override
+ protected void initFilter(AssetManager manager,
+ RenderManager renderManager, ViewPort vp, int w, int h)
+ {
+ material = new Material(manager,
+ "Common/MatDefs/Post/GammaCorrection.j3md");
+ material.setFloat("gamma", gamma);
+ material.setBoolean("computeLuma", computeLuma);
+ }
+
+ public float getGamma()
+ {
+ return gamma;
+ }
+
+ /**
+ * set to 0.0 to disable gamma correction
+ * @param gamma
+ */
+ public void setGamma(float gamma)
+ {
+ if (material != null)
+ {
+ material.setFloat("gamma", gamma);
+ }
+ this.gamma = gamma;
+ }
+
+ public boolean isComputeLuma()
+ {
+ return computeLuma;
+ }
+
+ public void setComputeLuma(boolean computeLuma)
+ {
+ if (material != null)
+ {
+ material.setBoolean("computeLuma", computeLuma);
+ }
+ this.computeLuma = computeLuma;
+ }
+}
diff --git a/engine/src/core-effects/com/jme3/post/filters/LightScatteringFilter.java b/engine/src/core-effects/com/jme3/post/filters/LightScatteringFilter.java
new file mode 100644
index 0000000..953f10a
--- /dev/null
+++ b/engine/src/core-effects/com/jme3/post/filters/LightScatteringFilter.java
@@ -0,0 +1,243 @@
+/*
+ * Copyright (c) 2009-2010 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.jme3.post.filters;
+
+import com.jme3.asset.AssetManager;
+import com.jme3.export.InputCapsule;
+import com.jme3.export.JmeExporter;
+import com.jme3.export.JmeImporter;
+import com.jme3.export.OutputCapsule;
+import com.jme3.material.Material;
+import com.jme3.math.Vector3f;
+import com.jme3.post.Filter;
+import com.jme3.renderer.Camera;
+import com.jme3.renderer.RenderManager;
+import com.jme3.renderer.ViewPort;
+import java.io.IOException;
+
+/**
+ * LightScattering filters creates rays comming from a light sources
+ * This is often reffered as god rays.
+ *
+ * @author Rémy Bouquet aka Nehon
+ */
+public class LightScatteringFilter extends Filter {
+
+ private Vector3f lightPosition;
+ private Vector3f screenLightPos = new Vector3f();
+ private int nbSamples = 50;
+ private float blurStart = 0.02f;
+ private float blurWidth = 0.9f;
+ private float lightDensity = 1.4f;
+ private boolean adaptative = true;
+ Vector3f viewLightPos = new Vector3f();
+ private boolean display = true;
+ private float innerLightDensity;
+
+ /**
+ * creates a lightScaterring filter
+ */
+ public LightScatteringFilter() {
+ super("Light Scattering");
+ }
+
+ /**
+ * Creates a lightScatteringFilter
+ * @param lightPosition
+ */
+ public LightScatteringFilter(Vector3f lightPosition) {
+ this();
+ this.lightPosition = lightPosition;
+ }
+
+ @Override
+ protected boolean isRequiresDepthTexture() {
+ return true;
+ }
+
+ @Override
+ protected Material getMaterial() {
+ material.setVector3("LightPosition", screenLightPos);
+ material.setInt("NbSamples", nbSamples);
+ material.setFloat("BlurStart", blurStart);
+ material.setFloat("BlurWidth", blurWidth);
+ material.setFloat("LightDensity", innerLightDensity);
+ material.setBoolean("Display", display);
+ return material;
+ }
+
+ @Override
+ protected void postQueue(RenderManager renderManager, ViewPort viewPort) {
+ getClipCoordinates(lightPosition, screenLightPos, viewPort.getCamera());
+ // screenLightPos.x = screenLightPos.x / viewPort.getCamera().getWidth();
+ // screenLightPos.y = screenLightPos.y / viewPort.getCamera().getHeight();
+
+ viewPort.getCamera().getViewMatrix().mult(lightPosition, viewLightPos);
+ //System.err.println("viewLightPos "+viewLightPos);
+ display = screenLightPos.x < 1.6f && screenLightPos.x > -0.6f && screenLightPos.y < 1.6f && screenLightPos.y > -0.6f && viewLightPos.z < 0;
+//System.err.println("camdir "+viewPort.getCamera().getDirection());
+//System.err.println("lightPos "+lightPosition);
+//System.err.println("screenLightPos "+screenLightPos);
+ if (adaptative) {
+ innerLightDensity = Math.max(lightDensity - Math.max(screenLightPos.x, screenLightPos.y), 0.0f);
+ } else {
+ innerLightDensity = lightDensity;
+ }
+ }
+
+ private Vector3f getClipCoordinates(Vector3f worldPosition, Vector3f store, Camera cam) {
+
+ float w = cam.getViewProjectionMatrix().multProj(worldPosition, store);
+ store.divideLocal(w);
+
+ store.x = ((store.x + 1f) * (cam.getViewPortRight() - cam.getViewPortLeft()) / 2f + cam.getViewPortLeft());
+ store.y = ((store.y + 1f) * (cam.getViewPortTop() - cam.getViewPortBottom()) / 2f + cam.getViewPortBottom());
+ store.z = (store.z + 1f) / 2f;
+
+ return store;
+ }
+
+ @Override
+ protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
+ material = new Material(manager, "Common/MatDefs/Post/LightScattering.j3md");
+ }
+
+ /**
+ * returns the blur start of the scattering
+ * see {@link setBlurStart(float blurStart)}
+ * @return
+ */
+ public float getBlurStart() {
+ return blurStart;
+ }
+
+ /**
+ * sets the blur start<br>
+ * at which distance from the light source the effect starts default is 0.02
+ * @param blurStart
+ */
+ public void setBlurStart(float blurStart) {
+ this.blurStart = blurStart;
+ }
+
+ /**
+ * returns the blur width<br>
+ * see {@link setBlurWidth(float blurWidth)}
+ * @return
+ */
+ public float getBlurWidth() {
+ return blurWidth;
+ }
+
+ /**
+ * sets the blur width default is 0.9
+ * @param blurWidth
+ */
+ public void setBlurWidth(float blurWidth) {
+ this.blurWidth = blurWidth;
+ }
+
+ /**
+ * retiurns the light density<br>
+ * see {@link setLightDensity(float lightDensity)}
+ *
+ * @return
+ */
+ public float getLightDensity() {
+ return lightDensity;
+ }
+
+ /**
+ * sets how much the effect is visible over the rendered scene default is 1.4
+ * @param lightDensity
+ */
+ public void setLightDensity(float lightDensity) {
+ this.lightDensity = lightDensity;
+ }
+
+ /**
+ * returns the light position
+ * @return
+ */
+ public Vector3f getLightPosition() {
+ return lightPosition;
+ }
+
+ /**
+ * sets the light position
+ * @param lightPosition
+ */
+ public void setLightPosition(Vector3f lightPosition) {
+ this.lightPosition = lightPosition;
+ }
+
+ /**
+ * returns the nmber of samples for the radial blur
+ * @return
+ */
+ public int getNbSamples() {
+ return nbSamples;
+ }
+
+ /**
+ * sets the number of samples for the radial blur default is 50
+ * the higher the value the higher the quality, but the slower the performances.
+ * @param nbSamples
+ */
+ public void setNbSamples(int nbSamples) {
+ this.nbSamples = nbSamples;
+ }
+
+ @Override
+ public void write(JmeExporter ex) throws IOException {
+ super.write(ex);
+ OutputCapsule oc = ex.getCapsule(this);
+ oc.write(lightPosition, "lightPosition", Vector3f.ZERO);
+ oc.write(nbSamples, "nbSamples", 50);
+ oc.write(blurStart, "blurStart", 0.02f);
+ oc.write(blurWidth, "blurWidth", 0.9f);
+ oc.write(lightDensity, "lightDensity", 1.4f);
+ oc.write(adaptative, "adaptative", true);
+ }
+
+ @Override
+ public void read(JmeImporter im) throws IOException {
+ super.read(im);
+ InputCapsule ic = im.getCapsule(this);
+ lightPosition = (Vector3f) ic.readSavable("lightPosition", Vector3f.ZERO);
+ nbSamples = ic.readInt("nbSamples", 50);
+ blurStart = ic.readFloat("blurStart", 0.02f);
+ blurWidth = ic.readFloat("blurWidth", 0.9f);
+ lightDensity = ic.readFloat("lightDensity", 1.4f);
+ adaptative = ic.readBoolean("adaptative", true);
+ }
+}
diff --git a/engine/src/core-effects/com/jme3/post/filters/PosterizationFilter.java b/engine/src/core-effects/com/jme3/post/filters/PosterizationFilter.java
new file mode 100644
index 0000000..c980eda
--- /dev/null
+++ b/engine/src/core-effects/com/jme3/post/filters/PosterizationFilter.java
@@ -0,0 +1,147 @@
+/*
+ * Copyright (c) 2009-2010 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+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 Post Processing filter to change colors appear with sharp edges as if the
+ * available amount of colors available was not enough to draw the true image.
+ * Possibly useful in cartoon styled games. Use the strength variable to lessen
+ * influence of this filter on the total result. Values from 0.2 to 0.7 appear
+ * to give nice results.
+ *
+ * Based on an article from Geeks3D:
+ * <a href="http://www.geeks3d.com/20091027/shader-library-posterization-post-processing-effect-glsl/" rel="nofollow">http://www.geeks3d.com/20091027/shader-library-posterization-post-processing-effect-glsl/</a>
+ *
+ * @author: Roy Straver a.k.a. Baal Garnaal
+ */
+public class PosterizationFilter extends Filter {
+
+ private int numColors = 8;
+ private float gamma = 0.6f;
+ private float strength = 1.0f;
+
+ /**
+ * Creates a posterization Filter
+ */
+ public PosterizationFilter() {
+ super("PosterizationFilter");
+ }
+
+ /**
+ * Creates a posterization Filter with the given number of colors
+ * @param numColors
+ */
+ public PosterizationFilter(int numColors) {
+ this();
+ this.numColors = numColors;
+ }
+
+ /**
+ * Creates a posterization Filter with the given number of colors and gamma
+ * @param numColors
+ * @param gamma
+ */
+ public PosterizationFilter(int numColors, float gamma) {
+ this(numColors);
+ this.gamma = gamma;
+ }
+
+ @Override
+ protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
+ material = new Material(manager, "Common/MatDefs/Post/Posterization.j3md");
+ material.setInt("NumColors", numColors);
+ material.setFloat("Gamma", gamma);
+ material.setFloat("Strength", strength);
+ }
+
+ @Override
+ protected Material getMaterial() {
+ return material;
+ }
+
+ /**
+ * Sets number of color levels used to draw the screen
+ */
+ public void setNumColors(int numColors) {
+ this.numColors = numColors;
+ if (material != null) {
+ material.setInt("NumColors", numColors);
+ }
+ }
+
+ /**
+ * Sets gamma level used to enhange visual quality
+ */
+ public void setGamma(float gamma) {
+ this.gamma = gamma;
+ if (material != null) {
+ material.setFloat("Gamma", gamma);
+ }
+ }
+
+ /**
+ * Sets urrent strength value, i.e. influence on final image
+ */
+ public void setStrength(float strength) {
+ this.strength = strength;
+ if (material != null) {
+ material.setFloat("Strength", strength);
+ }
+ }
+
+ /**
+ * Returns number of color levels used
+ */
+ public int getNumColors() {
+ return numColors;
+ }
+
+ /**
+ * Returns current gamma value
+ */
+ public float getGamma() {
+ return gamma;
+ }
+
+ /**
+ * Returns current strength value, i.e. influence on final image
+ */
+ public float getStrength() {
+ return strength;
+ }
+} \ No newline at end of file
diff --git a/engine/src/core-effects/com/jme3/post/filters/RadialBlurFilter.java b/engine/src/core-effects/com/jme3/post/filters/RadialBlurFilter.java
new file mode 100644
index 0000000..0bcae5f
--- /dev/null
+++ b/engine/src/core-effects/com/jme3/post/filters/RadialBlurFilter.java
@@ -0,0 +1,156 @@
+/*
+ * Copyright (c) 2009-2012 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.jme3.post.filters;
+
+import com.jme3.asset.AssetManager;
+import com.jme3.export.InputCapsule;
+import com.jme3.export.JmeExporter;
+import com.jme3.export.JmeImporter;
+import com.jme3.export.OutputCapsule;
+import com.jme3.material.Material;
+import com.jme3.post.Filter;
+import com.jme3.renderer.RenderManager;
+import com.jme3.renderer.ViewPort;
+import com.jme3.shader.VarType;
+import java.io.IOException;
+
+/**
+ * Radially blurs the scene from the center of it
+ * @author Rémy Bouquet aka Nehon
+ */
+public class RadialBlurFilter extends Filter {
+
+ private float sampleDist = 1.0f;
+ private float sampleStrength = 2.2f;
+ private float[] samples = {-0.08f, -0.05f, -0.03f, -0.02f, -0.01f, 0.01f, 0.02f, 0.03f, 0.05f, 0.08f};
+
+ /**
+ * Creates a RadialBlurFilter
+ */
+ public RadialBlurFilter() {
+ super("Radial blur");
+ }
+
+ /**
+ * Creates a RadialBlurFilter
+ * @param sampleDist the distance between samples
+ * @param sampleStrength the strenght of each sample
+ */
+ public RadialBlurFilter(float sampleDist, float sampleStrength) {
+ this();
+ this.sampleDist = sampleDist;
+ this.sampleStrength = sampleStrength;
+ }
+
+ @Override
+ protected Material getMaterial() {
+
+ material.setFloat("SampleDist", sampleDist);
+ material.setFloat("SampleStrength", sampleStrength);
+ material.setParam("Samples", VarType.FloatArray, samples);
+
+ return material;
+ }
+
+ /**
+ * return the sample distance
+ * @return
+ */
+ public float getSampleDistance() {
+ return sampleDist;
+ }
+
+ /**
+ * sets the samples distances default is 1
+ * @param sampleDist
+ */
+ public void setSampleDistance(float sampleDist) {
+ this.sampleDist = sampleDist;
+ }
+
+ /**
+ *
+ * @return
+ * @deprecated use {@link #getSampleDistance()}
+ */
+ @Deprecated
+ public float getSampleDist() {
+ return sampleDist;
+ }
+
+ /**
+ *
+ * @param sampleDist
+ * @deprecated use {@link #setSampleDistance(float sampleDist)}
+ */
+ @Deprecated
+ public void setSampleDist(float sampleDist) {
+ this.sampleDist = sampleDist;
+ }
+
+ /**
+ * Returns the sample Strength
+ * @return
+ */
+ public float getSampleStrength() {
+ return sampleStrength;
+ }
+
+ /**
+ * sets the sample streanght default is 2.2
+ * @param sampleStrength
+ */
+ public void setSampleStrength(float sampleStrength) {
+ this.sampleStrength = sampleStrength;
+ }
+
+ @Override
+ protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
+ material = new Material(manager, "Common/MatDefs/Blur/RadialBlur.j3md");
+ }
+
+ @Override
+ public void write(JmeExporter ex) throws IOException {
+ super.write(ex);
+ OutputCapsule oc = ex.getCapsule(this);
+ oc.write(sampleDist, "sampleDist", 1.0f);
+ oc.write(sampleStrength, "sampleStrength", 2.2f);
+ }
+
+ @Override
+ public void read(JmeImporter im) throws IOException {
+ super.read(im);
+ InputCapsule ic = im.getCapsule(this);
+ sampleDist = ic.readFloat("sampleDist", 1.0f);
+ sampleStrength = ic.readFloat("sampleStrength", 2.2f);
+ }
+}
diff --git a/engine/src/core-effects/com/jme3/post/filters/TranslucentBucketFilter.java b/engine/src/core-effects/com/jme3/post/filters/TranslucentBucketFilter.java
new file mode 100644
index 0000000..47be413
--- /dev/null
+++ b/engine/src/core-effects/com/jme3/post/filters/TranslucentBucketFilter.java
@@ -0,0 +1,80 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.jme3.post.filters;
+
+import com.jme3.asset.AssetManager;
+import com.jme3.material.Material;
+import com.jme3.math.ColorRGBA;
+import com.jme3.post.Filter;
+import com.jme3.renderer.RenderManager;
+import com.jme3.renderer.Renderer;
+import com.jme3.renderer.ViewPort;
+import com.jme3.renderer.queue.RenderQueue;
+import com.jme3.texture.FrameBuffer;
+import com.jme3.texture.Texture2D;
+
+/**
+ * A filter to handle translucent objects when rendering a scene with filters that uses depth like WaterFilter and SSAOFilter
+ * just create a TranslucentBucketFilter and add it to the Filter list of a FilterPostPorcessor
+ * @author Nehon
+ */
+public final class TranslucentBucketFilter extends Filter {
+
+ private RenderManager renderManager;
+
+ @Override
+ protected void initFilter(AssetManager manager, RenderManager rm, ViewPort vp, int w, int h) {
+ this.renderManager = rm;
+ material = new Material(manager, "Common/MatDefs/Post/Overlay.j3md");
+ material.setColor("Color", ColorRGBA.White);
+ Texture2D tex = processor.getFilterTexture();
+ material.setTexture("Texture", tex);
+ if (tex.getImage().getMultiSamples() > 1) {
+ material.setInt("NumSamples", tex.getImage().getMultiSamples());
+ } else {
+ material.clearParam("NumSamples");
+ }
+ renderManager.setHandleTranslucentBucket(false);
+ }
+
+ /**
+ * Override this method and return false if your Filter does not need the scene texture
+ * @return
+ */
+ @Override
+ protected boolean isRequiresSceneTexture() {
+ return false;
+ }
+
+ @Override
+ protected void postFrame(RenderManager renderManager, ViewPort viewPort, FrameBuffer prevFilterBuffer, FrameBuffer sceneBuffer) {
+ renderManager.setCamera(viewPort.getCamera(), false);
+ if (prevFilterBuffer != sceneBuffer) {
+ renderManager.getRenderer().copyFrameBuffer(prevFilterBuffer, sceneBuffer, false);
+ }
+ renderManager.getRenderer().setFrameBuffer(sceneBuffer);
+ viewPort.getQueue().renderQueue(RenderQueue.Bucket.Translucent, renderManager, viewPort.getCamera());
+ }
+
+ @Override
+ protected void cleanUpFilter(Renderer r) {
+ if (renderManager != null) {
+ renderManager.setHandleTranslucentBucket(true);
+ }
+ }
+
+ @Override
+ protected Material getMaterial() {
+ return material;
+ }
+
+ @Override
+ public void setEnabled(boolean enabled) {
+ super.setEnabled(enabled);
+ if (renderManager != null) {
+ renderManager.setHandleTranslucentBucket(!enabled);
+ }
+ }
+}