correct core comments and standardize line endings as discussed at http://hub.jmonkeyengine.org/forum/topic/typos-in-com-jme3-mathrendererpost/
parent
a2855c1cf0
commit
98ffe52c77
File diff suppressed because it is too large
Load Diff
@ -1,164 +1,165 @@ |
|||||||
/* |
/* |
||||||
* Copyright (c) 2009-2012 jMonkeyEngine |
* Copyright (c) 2009-2012 jMonkeyEngine |
||||||
* All rights reserved. |
* All rights reserved. |
||||||
* |
* |
||||||
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
||||||
* modification, are permitted provided that the following conditions are |
* modification, are permitted provided that the following conditions are |
||||||
* met: |
* met: |
||||||
* |
* |
||||||
* * Redistributions of source code must retain the above copyright |
* * Redistributions of source code must retain the above copyright |
||||||
* notice, this list of conditions and the following disclaimer. |
* notice, this list of conditions and the following disclaimer. |
||||||
* |
* |
||||||
* * Redistributions in binary form must reproduce the above copyright |
* * Redistributions in binary form must reproduce the above copyright |
||||||
* notice, this list of conditions and the following disclaimer in the |
* notice, this list of conditions and the following disclaimer in the |
||||||
* documentation and/or other materials provided with the distribution. |
* documentation and/or other materials provided with the distribution. |
||||||
* |
* |
||||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
||||||
* may be used to endorse or promote products derived from this software |
* may be used to endorse or promote products derived from this software |
||||||
* without specific prior written permission. |
* without specific prior written permission. |
||||||
* |
* |
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
||||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
||||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
||||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||||
*/ |
*/ |
||||||
package com.jme3.math; |
package com.jme3.math; |
||||||
|
|
||||||
import com.jme3.math.Spline.SplineType; |
import com.jme3.math.Spline.SplineType; |
||||||
import java.util.List; |
import java.util.List; |
||||||
|
|
||||||
/** |
/** |
||||||
* This class offers methods to help with curves and surfaces calculations. |
* This class offers methods to help with curves and surfaces calculations. |
||||||
* @author Marcin Roguski (Kealthas) |
* @author Marcin Roguski (Kealthas) |
||||||
*/ |
*/ |
||||||
public class CurveAndSurfaceMath { |
public class CurveAndSurfaceMath { |
||||||
private static final float KNOTS_MINIMUM_DELTA = 0.0001f; |
private static final float KNOTS_MINIMUM_DELTA = 0.0001f; |
||||||
|
|
||||||
/** |
/** |
||||||
* A private constructor is defined to avoid instatiation of this class. |
* A private constructor is defined to avoid instantiation of this |
||||||
*/ |
* class. |
||||||
private CurveAndSurfaceMath() {} |
*/ |
||||||
|
private CurveAndSurfaceMath() {} |
||||||
/** |
|
||||||
* This method interpolates tha data for the nurbs curve. |
/** |
||||||
* @param u |
* This method interpolates the data for the nurbs curve. |
||||||
* the u value |
* @param u |
||||||
* @param nurbSpline |
* the u value |
||||||
* the nurbs spline definition |
* @param nurbSpline |
||||||
* @param store |
* the nurbs spline definition |
||||||
* the resulting point in 3D space |
* @param store |
||||||
*/ |
* the resulting point in 3D space |
||||||
public static void interpolateNurbs(float u, Spline nurbSpline, Vector3f store) { |
*/ |
||||||
if (nurbSpline.getType() != SplineType.Nurb) { |
public static void interpolateNurbs(float u, Spline nurbSpline, Vector3f store) { |
||||||
throw new IllegalArgumentException("Given spline is not of a NURB type!"); |
if (nurbSpline.getType() != SplineType.Nurb) { |
||||||
} |
throw new IllegalArgumentException("Given spline is not of a NURB type!"); |
||||||
List<Vector3f> controlPoints = nurbSpline.getControlPoints(); |
} |
||||||
float[] weights = nurbSpline.getWeights(); |
List<Vector3f> controlPoints = nurbSpline.getControlPoints(); |
||||||
List<Float> knots = nurbSpline.getKnots(); |
float[] weights = nurbSpline.getWeights(); |
||||||
int controlPointAmount = controlPoints.size(); |
List<Float> knots = nurbSpline.getKnots(); |
||||||
|
int controlPointAmount = controlPoints.size(); |
||||||
store.set(Vector3f.ZERO); |
|
||||||
float delimeter = 0; |
store.set(Vector3f.ZERO); |
||||||
for (int i = 0; i < controlPointAmount; ++i) { |
float delimeter = 0; |
||||||
float val = weights[i] * CurveAndSurfaceMath.computeBaseFunctionValue(i, nurbSpline.getBasisFunctionDegree(), u, knots); |
for (int i = 0; i < controlPointAmount; ++i) { |
||||||
store.addLocal(nurbSpline.getControlPoints().get(i) |
float val = weights[i] * CurveAndSurfaceMath.computeBaseFunctionValue(i, nurbSpline.getBasisFunctionDegree(), u, knots); |
||||||
.mult(val)); |
store.addLocal(nurbSpline.getControlPoints().get(i) |
||||||
delimeter += val; |
.mult(val)); |
||||||
} |
delimeter += val; |
||||||
store.divideLocal(delimeter); |
} |
||||||
} |
store.divideLocal(delimeter); |
||||||
|
} |
||||||
/** |
|
||||||
* This method interpolates tha data for the nurbs surface. |
/** |
||||||
* |
* This method interpolates the data for the nurbs surface. |
||||||
* @param u |
* |
||||||
* the u value |
* @param u |
||||||
* @param v |
* the u value |
||||||
* the v value |
* @param v |
||||||
* @param controlPoints |
* the v value |
||||||
* the nurbs' control points |
* @param controlPoints |
||||||
* @param knots |
* the nurbs' control points |
||||||
* the nurbs' knots |
* @param knots |
||||||
* @param basisUFunctionDegree |
* the nurbs' knots |
||||||
* the degree of basis U function |
* @param basisUFunctionDegree |
||||||
* @param basisVFunctionDegree |
* the degree of basis U function |
||||||
* the degree of basis V function |
* @param basisVFunctionDegree |
||||||
* @param store |
* the degree of basis V function |
||||||
* the resulting point in 3D space |
* @param store |
||||||
*/ |
* the resulting point in 3D space |
||||||
public static void interpolate(float u, float v, List<List<Vector4f>> controlPoints, List<Float>[] knots, |
*/ |
||||||
int basisUFunctionDegree, int basisVFunctionDegree, Vector3f store) { |
public static void interpolate(float u, float v, List<List<Vector4f>> controlPoints, List<Float>[] knots, |
||||||
store.set(Vector3f.ZERO); |
int basisUFunctionDegree, int basisVFunctionDegree, Vector3f store) { |
||||||
float delimeter = 0; |
store.set(Vector3f.ZERO); |
||||||
int vControlPointsAmount = controlPoints.size(); |
float delimeter = 0; |
||||||
int uControlPointsAmount = controlPoints.get(0).size(); |
int vControlPointsAmount = controlPoints.size(); |
||||||
for (int i = 0; i < vControlPointsAmount; ++i) { |
int uControlPointsAmount = controlPoints.get(0).size(); |
||||||
for (int j = 0; j < uControlPointsAmount; ++j) { |
for (int i = 0; i < vControlPointsAmount; ++i) { |
||||||
Vector4f controlPoint = controlPoints.get(i).get(j); |
for (int j = 0; j < uControlPointsAmount; ++j) { |
||||||
float val = controlPoint.w |
Vector4f controlPoint = controlPoints.get(i).get(j); |
||||||
* CurveAndSurfaceMath.computeBaseFunctionValue(i, basisVFunctionDegree, v, knots[1]) |
float val = controlPoint.w |
||||||
* CurveAndSurfaceMath.computeBaseFunctionValue(j, basisUFunctionDegree, u, knots[0]); |
* CurveAndSurfaceMath.computeBaseFunctionValue(i, basisVFunctionDegree, v, knots[1]) |
||||||
store.addLocal(controlPoint.x * val, controlPoint.y * val, controlPoint.z * val); |
* CurveAndSurfaceMath.computeBaseFunctionValue(j, basisUFunctionDegree, u, knots[0]); |
||||||
delimeter += val; |
store.addLocal(controlPoint.x * val, controlPoint.y * val, controlPoint.z * val); |
||||||
} |
delimeter += val; |
||||||
} |
} |
||||||
store.divideLocal(delimeter); |
} |
||||||
} |
store.divideLocal(delimeter); |
||||||
|
} |
||||||
/** |
|
||||||
* This method prepares the knots to be used. If the knots represent non-uniform B-splines (first and last knot values are being |
/** |
||||||
* repeated) it leads to NaN results during calculations. This method adds a small number to each of such knots to avoid NaN's. |
* This method prepares the knots to be used. If the knots represent non-uniform B-splines (first and last knot values are being |
||||||
* @param knots |
* repeated) it leads to NaN results during calculations. This method adds a small number to each of such knots to avoid NaN's. |
||||||
* the knots to be prepared to use |
* @param knots |
||||||
* @param basisFunctionDegree |
* the knots to be prepared to use |
||||||
* the degree of basis function |
* @param basisFunctionDegree |
||||||
*/ |
* the degree of basis function |
||||||
// TODO: improve this; constant delta may lead to errors if the difference between tha last repeated
|
*/ |
||||||
// point and the following one is lower than it
|
// TODO: improve this; constant delta may lead to errors if the difference between tha last repeated
|
||||||
public static void prepareNurbsKnots(List<Float> knots, int basisFunctionDegree) { |
// point and the following one is lower than it
|
||||||
float delta = KNOTS_MINIMUM_DELTA; |
public static void prepareNurbsKnots(List<Float> knots, int basisFunctionDegree) { |
||||||
float prevValue = knots.get(0).floatValue(); |
float delta = KNOTS_MINIMUM_DELTA; |
||||||
for(int i=1;i<knots.size();++i) { |
float prevValue = knots.get(0).floatValue(); |
||||||
float value = knots.get(i).floatValue(); |
for(int i=1;i<knots.size();++i) { |
||||||
if(value<=prevValue) { |
float value = knots.get(i).floatValue(); |
||||||
value += delta; |
if(value<=prevValue) { |
||||||
knots.set(i, Float.valueOf(value)); |
value += delta; |
||||||
delta += KNOTS_MINIMUM_DELTA; |
knots.set(i, Float.valueOf(value)); |
||||||
} else { |
delta += KNOTS_MINIMUM_DELTA; |
||||||
delta = KNOTS_MINIMUM_DELTA;//reset the delta's value
|
} else { |
||||||
} |
delta = KNOTS_MINIMUM_DELTA;//reset the delta's value
|
||||||
|
} |
||||||
prevValue = value; |
|
||||||
} |
prevValue = value; |
||||||
} |
} |
||||||
|
} |
||||||
/** |
|
||||||
* This method computes the base function value for the NURB curve. |
/** |
||||||
* @param i |
* This method computes the base function value for the NURB curve. |
||||||
* the knot index |
* @param i |
||||||
* @param k |
* the knot index |
||||||
* the base function degree |
* @param k |
||||||
* @param t |
* the base function degree |
||||||
* the knot value |
* @param t |
||||||
* @param knots |
* the knot value |
||||||
* the knots' values |
* @param knots |
||||||
* @return the base function value |
* the knots' values |
||||||
*/ |
* @return the base function value |
||||||
private static float computeBaseFunctionValue(int i, int k, float t, List<Float> knots) { |
*/ |
||||||
if (k == 1) { |
private static float computeBaseFunctionValue(int i, int k, float t, List<Float> knots) { |
||||||
return knots.get(i) <= t && t < knots.get(i + 1) ? 1.0f : 0.0f; |
if (k == 1) { |
||||||
} else { |
return knots.get(i) <= t && t < knots.get(i + 1) ? 1.0f : 0.0f; |
||||||
return (t - knots.get(i)) / (knots.get(i + k - 1) - knots.get(i)) * |
} else { |
||||||
CurveAndSurfaceMath.computeBaseFunctionValue(i, k - 1, t, knots) |
return (t - knots.get(i)) / (knots.get(i + k - 1) - knots.get(i)) * |
||||||
+ (knots.get(i + k) - t) / (knots.get(i + k) - knots.get(i + 1)) * |
CurveAndSurfaceMath.computeBaseFunctionValue(i, k - 1, t, knots) |
||||||
CurveAndSurfaceMath.computeBaseFunctionValue(i + 1, k - 1, t, knots); |
+ (knots.get(i + k) - t) / (knots.get(i + k) - knots.get(i + 1)) * |
||||||
} |
CurveAndSurfaceMath.computeBaseFunctionValue(i + 1, k - 1, t, knots); |
||||||
} |
} |
||||||
} |
} |
||||||
|
} |
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,456 +1,456 @@ |
|||||||
/* |
/* |
||||||
* Copyright (c) 2009-2012 jMonkeyEngine |
* Copyright (c) 2009-2012 jMonkeyEngine |
||||||
* All rights reserved. |
* All rights reserved. |
||||||
* |
* |
||||||
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
||||||
* modification, are permitted provided that the following conditions are |
* modification, are permitted provided that the following conditions are |
||||||
* met: |
* met: |
||||||
* |
* |
||||||
* * Redistributions of source code must retain the above copyright |
* * Redistributions of source code must retain the above copyright |
||||||
* notice, this list of conditions and the following disclaimer. |
* notice, this list of conditions and the following disclaimer. |
||||||
* |
* |
||||||
* * Redistributions in binary form must reproduce the above copyright |
* * Redistributions in binary form must reproduce the above copyright |
||||||
* notice, this list of conditions and the following disclaimer in the |
* notice, this list of conditions and the following disclaimer in the |
||||||
* documentation and/or other materials provided with the distribution. |
* documentation and/or other materials provided with the distribution. |
||||||
* |
* |
||||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
||||||
* may be used to endorse or promote products derived from this software |
* may be used to endorse or promote products derived from this software |
||||||
* without specific prior written permission. |
* without specific prior written permission. |
||||||
* |
* |
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
||||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
||||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
||||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||||
*/ |
*/ |
||||||
package com.jme3.post; |
package com.jme3.post; |
||||||
|
|
||||||
import com.jme3.asset.AssetManager; |
import com.jme3.asset.AssetManager; |
||||||
import com.jme3.export.*; |
import com.jme3.export.*; |
||||||
import com.jme3.material.Material; |
import com.jme3.material.Material; |
||||||
import com.jme3.renderer.Caps; |
import com.jme3.renderer.Caps; |
||||||
import com.jme3.renderer.RenderManager; |
import com.jme3.renderer.RenderManager; |
||||||
import com.jme3.renderer.Renderer; |
import com.jme3.renderer.Renderer; |
||||||
import com.jme3.renderer.ViewPort; |
import com.jme3.renderer.ViewPort; |
||||||
import com.jme3.renderer.queue.RenderQueue; |
import com.jme3.renderer.queue.RenderQueue; |
||||||
import com.jme3.texture.FrameBuffer; |
import com.jme3.texture.FrameBuffer; |
||||||
import com.jme3.texture.Image.Format; |
import com.jme3.texture.Image.Format; |
||||||
import com.jme3.texture.Texture; |
import com.jme3.texture.Texture; |
||||||
import com.jme3.texture.Texture2D; |
import com.jme3.texture.Texture2D; |
||||||
import java.io.IOException; |
import java.io.IOException; |
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
import java.util.Iterator; |
import java.util.Iterator; |
||||||
import java.util.List; |
import java.util.List; |
||||||
|
|
||||||
/** |
/** |
||||||
* Filters are 2D effects applied to the rendered scene.<br> |
* Filters are 2D effects applied to the rendered scene.<br> |
||||||
* The filter is fed with the rendered scene image rendered in an offscreen frame buffer.<br> |
* The filter is fed with the rendered scene image rendered in an offscreen frame buffer.<br> |
||||||
* This texture is applied on a fullscreen quad, with a special material.<br> |
* This texture is applied on a full-screen quad with a special material.<br> |
||||||
* This material uses a shader that aplly the desired effect to the scene texture.<br> |
* This material uses a shader that applies the desired effect to the scene texture.<br> |
||||||
* <br> |
* <br> |
||||||
* This class is abstract, any Filter must extend it.<br> |
* This class is abstract, any Filter must extend it.<br> |
||||||
* Any filter holds a frameBuffer and a texture<br> |
* Any filter holds a frameBuffer and a texture<br> |
||||||
* The getMaterial must return a Material that use a GLSL shader immplementing the desired effect<br> |
* The getMaterial must return a Material that use a GLSL shader implementing the desired effect<br> |
||||||
* |
* |
||||||
* @author Rémy Bouquet aka Nehon |
* @author Rémy Bouquet aka Nehon |
||||||
*/ |
*/ |
||||||
public abstract class Filter implements Savable { |
public abstract class Filter implements Savable { |
||||||
|
|
||||||
|
|
||||||
private String name; |
private String name; |
||||||
protected Pass defaultPass; |
protected Pass defaultPass; |
||||||
protected List<Pass> postRenderPasses; |
protected List<Pass> postRenderPasses; |
||||||
protected Material material; |
protected Material material; |
||||||
protected boolean enabled = true; |
protected boolean enabled = true; |
||||||
protected FilterPostProcessor processor; |
protected FilterPostProcessor processor; |
||||||
|
|
||||||
public Filter(String name) { |
public Filter(String name) { |
||||||
this.name = name; |
this.name = name; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* Inner class Pass |
* Inner class Pass |
||||||
* Pass are like filters in filters. |
* Pass are like filters in filters. |
||||||
* Some filters will need multiple passes before the final render |
* Some filters will need multiple passes before the final render |
||||||
*/ |
*/ |
||||||
public class Pass { |
public class Pass { |
||||||
|
|
||||||
protected FrameBuffer renderFrameBuffer; |
protected FrameBuffer renderFrameBuffer; |
||||||
protected Texture2D renderedTexture; |
protected Texture2D renderedTexture; |
||||||
protected Texture2D depthTexture; |
protected Texture2D depthTexture; |
||||||
protected Material passMaterial; |
protected Material passMaterial; |
||||||
|
|
||||||
/** |
/** |
||||||
* init the pass called internally |
* init the pass called internally |
||||||
* @param renderer |
* @param renderer |
||||||
* @param width |
* @param width |
||||||
* @param height |
* @param height |
||||||
* @param textureFormat |
* @param textureFormat |
||||||
* @param depthBufferFormat |
* @param depthBufferFormat |
||||||
* @param numSamples |
* @param numSamples |
||||||
*/ |
*/ |
||||||
public void init(Renderer renderer, int width, int height, Format textureFormat, Format depthBufferFormat, int numSamples, boolean renderDepth) { |
public void init(Renderer renderer, int width, int height, Format textureFormat, Format depthBufferFormat, int numSamples, boolean renderDepth) { |
||||||
Collection<Caps> caps = renderer.getCaps(); |
Collection<Caps> caps = renderer.getCaps(); |
||||||
if (numSamples > 1 && caps.contains(Caps.FrameBufferMultisample) && caps.contains(Caps.OpenGL31)) { |
if (numSamples > 1 && caps.contains(Caps.FrameBufferMultisample) && caps.contains(Caps.OpenGL31)) { |
||||||
renderFrameBuffer = new FrameBuffer(width, height, numSamples); |
renderFrameBuffer = new FrameBuffer(width, height, numSamples); |
||||||
renderedTexture = new Texture2D(width, height, numSamples, textureFormat); |
renderedTexture = new Texture2D(width, height, numSamples, textureFormat); |
||||||
renderFrameBuffer.setDepthBuffer(depthBufferFormat); |
renderFrameBuffer.setDepthBuffer(depthBufferFormat); |
||||||
if (renderDepth) { |
if (renderDepth) { |
||||||
depthTexture = new Texture2D(width, height, numSamples, depthBufferFormat); |
depthTexture = new Texture2D(width, height, numSamples, depthBufferFormat); |
||||||
renderFrameBuffer.setDepthTexture(depthTexture); |
renderFrameBuffer.setDepthTexture(depthTexture); |
||||||
} |
} |
||||||
} else { |
} else { |
||||||
renderFrameBuffer = new FrameBuffer(width, height, 1); |
renderFrameBuffer = new FrameBuffer(width, height, 1); |
||||||
renderedTexture = new Texture2D(width, height, textureFormat); |
renderedTexture = new Texture2D(width, height, textureFormat); |
||||||
renderFrameBuffer.setDepthBuffer(depthBufferFormat); |
renderFrameBuffer.setDepthBuffer(depthBufferFormat); |
||||||
if (renderDepth) { |
if (renderDepth) { |
||||||
depthTexture = new Texture2D(width, height, depthBufferFormat); |
depthTexture = new Texture2D(width, height, depthBufferFormat); |
||||||
renderFrameBuffer.setDepthTexture(depthTexture); |
renderFrameBuffer.setDepthTexture(depthTexture); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
renderFrameBuffer.setColorTexture(renderedTexture); |
renderFrameBuffer.setColorTexture(renderedTexture); |
||||||
|
|
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* init the pass called internally |
* init the pass called internally |
||||||
* @param renderer |
* @param renderer |
||||||
* @param width |
* @param width |
||||||
* @param height |
* @param height |
||||||
* @param textureFormat |
* @param textureFormat |
||||||
* @param depthBufferFormat |
* @param depthBufferFormat |
||||||
*/ |
*/ |
||||||
public void init(Renderer renderer, int width, int height, Format textureFormat, Format depthBufferFormat) { |
public void init(Renderer renderer, int width, int height, Format textureFormat, Format depthBufferFormat) { |
||||||
init(renderer, width, height, textureFormat, depthBufferFormat, 1); |
init(renderer, width, height, textureFormat, depthBufferFormat, 1); |
||||||
} |
} |
||||||
|
|
||||||
public void init(Renderer renderer, int width, int height, Format textureFormat, Format depthBufferFormat, int numSamples) { |
public void init(Renderer renderer, int width, int height, Format textureFormat, Format depthBufferFormat, int numSamples) { |
||||||
init(renderer, width, height, textureFormat, depthBufferFormat, numSamples, false); |
init(renderer, width, height, textureFormat, depthBufferFormat, numSamples, false); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* init the pass called internally |
* init the pass called internally |
||||||
* @param renderer |
* @param renderer |
||||||
* @param width |
* @param width |
||||||
* @param height |
* @param height |
||||||
* @param textureFormat |
* @param textureFormat |
||||||
* @param depthBufferFormat |
* @param depthBufferFormat |
||||||
* @param numSample |
* @param numSample |
||||||
* @param material |
* @param material |
||||||
*/ |
*/ |
||||||
public void init(Renderer renderer, int width, int height, Format textureFormat, Format depthBufferFormat, int numSample, Material material) { |
public void init(Renderer renderer, int width, int height, Format textureFormat, Format depthBufferFormat, int numSample, Material material) { |
||||||
init(renderer, width, height, textureFormat, depthBufferFormat, numSample); |
init(renderer, width, height, textureFormat, depthBufferFormat, numSample); |
||||||
passMaterial = material; |
passMaterial = material; |
||||||
} |
} |
||||||
|
|
||||||
public boolean requiresSceneAsTexture() { |
public boolean requiresSceneAsTexture() { |
||||||
return false; |
return false; |
||||||
} |
} |
||||||
|
|
||||||
public boolean requiresDepthAsTexture() { |
public boolean requiresDepthAsTexture() { |
||||||
return false; |
return false; |
||||||
} |
} |
||||||
|
|
||||||
public void beforeRender() { |
public void beforeRender() { |
||||||
} |
} |
||||||
|
|
||||||
public FrameBuffer getRenderFrameBuffer() { |
public FrameBuffer getRenderFrameBuffer() { |
||||||
return renderFrameBuffer; |
return renderFrameBuffer; |
||||||
} |
} |
||||||
|
|
||||||
public void setRenderFrameBuffer(FrameBuffer renderFrameBuffer) { |
public void setRenderFrameBuffer(FrameBuffer renderFrameBuffer) { |
||||||
this.renderFrameBuffer = renderFrameBuffer; |
this.renderFrameBuffer = renderFrameBuffer; |
||||||
} |
} |
||||||
|
|
||||||
public Texture2D getDepthTexture() { |
public Texture2D getDepthTexture() { |
||||||
return depthTexture; |
return depthTexture; |
||||||
} |
} |
||||||
|
|
||||||
public Texture2D getRenderedTexture() { |
public Texture2D getRenderedTexture() { |
||||||
return renderedTexture; |
return renderedTexture; |
||||||
} |
} |
||||||
|
|
||||||
public void setRenderedTexture(Texture2D renderedTexture) { |
public void setRenderedTexture(Texture2D renderedTexture) { |
||||||
this.renderedTexture = renderedTexture; |
this.renderedTexture = renderedTexture; |
||||||
} |
} |
||||||
|
|
||||||
public Material getPassMaterial() { |
public Material getPassMaterial() { |
||||||
return passMaterial; |
return passMaterial; |
||||||
} |
} |
||||||
|
|
||||||
public void setPassMaterial(Material passMaterial) { |
public void setPassMaterial(Material passMaterial) { |
||||||
this.passMaterial = passMaterial; |
this.passMaterial = passMaterial; |
||||||
} |
} |
||||||
|
|
||||||
public void cleanup(Renderer r) { |
public void cleanup(Renderer r) { |
||||||
renderFrameBuffer.dispose(); |
renderFrameBuffer.dispose(); |
||||||
renderedTexture.getImage().dispose(); |
renderedTexture.getImage().dispose(); |
||||||
if(depthTexture!=null){ |
if(depthTexture!=null){ |
||||||
depthTexture.getImage().dispose(); |
depthTexture.getImage().dispose(); |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* returns the default pass texture format |
* returns the default pass texture format |
||||||
* @return |
* @return |
||||||
*/ |
*/ |
||||||
protected Format getDefaultPassTextureFormat() { |
protected Format getDefaultPassTextureFormat() { |
||||||
return Format.RGBA8; |
return Format.RGBA8; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* returns the default pass depth format |
* returns the default pass depth format |
||||||
* @return |
* @return |
||||||
*/ |
*/ |
||||||
protected Format getDefaultPassDepthFormat() { |
protected Format getDefaultPassDepthFormat() { |
||||||
return Format.Depth; |
return Format.Depth; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* contruct a Filter |
* construct a Filter |
||||||
*/ |
*/ |
||||||
protected Filter() { |
protected Filter() { |
||||||
this("filter"); |
this("filter"); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* initialize this filter |
* initialize this filter |
||||||
* use InitFilter for overriding filter initialization |
* use InitFilter for overriding filter initialization |
||||||
* @param manager the assetManager |
* @param manager the assetManager |
||||||
* @param renderManager the renderManager |
* @param renderManager the renderManager |
||||||
* @param vp the viewport |
* @param vp the viewport |
||||||
* @param w the width |
* @param w the width |
||||||
* @param h the height |
* @param h the height |
||||||
*/ |
*/ |
||||||
protected final void init(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) { |
protected final void init(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) { |
||||||
// cleanup(renderManager.getRenderer());
|
// cleanup(renderManager.getRenderer());
|
||||||
defaultPass = new Pass(); |
defaultPass = new Pass(); |
||||||
defaultPass.init(renderManager.getRenderer(), w, h, getDefaultPassTextureFormat(), getDefaultPassDepthFormat()); |
defaultPass.init(renderManager.getRenderer(), w, h, getDefaultPassTextureFormat(), getDefaultPassDepthFormat()); |
||||||
initFilter(manager, renderManager, vp, w, h); |
initFilter(manager, renderManager, vp, w, h); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* cleanup this filter |
* cleanup this filter |
||||||
* @param r |
* @param r |
||||||
*/ |
*/ |
||||||
protected final void cleanup(Renderer r) { |
protected final void cleanup(Renderer r) { |
||||||
processor = null; |
processor = null; |
||||||
if (defaultPass != null) { |
if (defaultPass != null) { |
||||||
defaultPass.cleanup(r); |
defaultPass.cleanup(r); |
||||||
} |
} |
||||||
if (postRenderPasses != null) { |
if (postRenderPasses != null) { |
||||||
for (Iterator<Pass> it = postRenderPasses.iterator(); it.hasNext();) { |
for (Iterator<Pass> it = postRenderPasses.iterator(); it.hasNext();) { |
||||||
Pass pass = it.next(); |
Pass pass = it.next(); |
||||||
pass.cleanup(r); |
pass.cleanup(r); |
||||||
} |
} |
||||||
} |
} |
||||||
cleanUpFilter(r); |
cleanUpFilter(r); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* Initialization of sub classes filters |
* Initialization of sub classes filters |
||||||
* This method is called once when the filter is added to the FilterPostProcessor |
* This method is called once when the filter is added to the FilterPostProcessor |
||||||
* It should contain Material initializations and extra passes initialization |
* It should contain Material initializations and extra passes initialization |
||||||
* @param manager the assetManager |
* @param manager the assetManager |
||||||
* @param renderManager the renderManager |
* @param renderManager the renderManager |
||||||
* @param vp the viewPort where this filter is rendered |
* @param vp the viewPort where this filter is rendered |
||||||
* @param w the width of the filter |
* @param w the width of the filter |
||||||
* @param h the height of the filter |
* @param h the height of the filter |
||||||
*/ |
*/ |
||||||
protected abstract void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h); |
protected abstract void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h); |
||||||
|
|
||||||
/** |
/** |
||||||
* override this method if you have some cleanup to do |
* override this method if you have some cleanup to do |
||||||
* @param r the renderer |
* @param r the renderer |
||||||
*/ |
*/ |
||||||
protected void cleanUpFilter(Renderer r) { |
protected void cleanUpFilter(Renderer r) { |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* Must return the material used for this filter. |
* Must return the material used for this filter. |
||||||
* this method is called every frame. |
* this method is called every frame. |
||||||
* |
* |
||||||
* @return the material used for this filter. |
* @return the material used for this filter. |
||||||
*/ |
*/ |
||||||
protected abstract Material getMaterial(); |
protected abstract Material getMaterial(); |
||||||
|
|
||||||
/** |
/** |
||||||
* Override if you want to do something special with the depth texture; |
* Override if you want to do something special with the depth texture; |
||||||
* @param depthTexture |
* @param depthTexture |
||||||
*/ |
*/ |
||||||
protected void setDepthTexture(Texture depthTexture){ |
protected void setDepthTexture(Texture depthTexture){ |
||||||
getMaterial().setTexture("DepthTexture", depthTexture); |
getMaterial().setTexture("DepthTexture", depthTexture); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* Override this method if you want to make a pre pass, before the actual rendering of the frame |
* Override this method if you want to make a pre pass, before the actual rendering of the frame |
||||||
* @param queue |
* @param queue |
||||||
*/ |
*/ |
||||||
protected void postQueue(RenderQueue queue) { |
protected void postQueue(RenderQueue queue) { |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* Override this method if you want to modify parameters according to tpf before the rendering of the frame. |
* Override this method if you want to modify parameters according to tpf before the rendering of the frame. |
||||||
* This is usefull for animated filters |
* This is useful for animated filters |
||||||
* Also it can be the place to render pre passes |
* Also it can be the place to render pre passes |
||||||
* @param tpf the time used to render the previous frame |
* @param tpf the time used to render the previous frame |
||||||
*/ |
*/ |
||||||
protected void preFrame(float tpf) { |
protected void preFrame(float tpf) { |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* Override this method if you want to make a pass just after the frame has been rendered and just before the filter rendering |
* Override this method if you want to make a pass just after the frame has been rendered and just before the filter rendering |
||||||
* @param renderManager |
* @param renderManager |
||||||
* @param viewPort |
* @param viewPort |
||||||
* @param prevFilterBuffer |
* @param prevFilterBuffer |
||||||
* @param sceneBuffer |
* @param sceneBuffer |
||||||
*/ |
*/ |
||||||
protected void postFrame(RenderManager renderManager, ViewPort viewPort, FrameBuffer prevFilterBuffer, FrameBuffer sceneBuffer) { |
protected void postFrame(RenderManager renderManager, ViewPort viewPort, FrameBuffer prevFilterBuffer, FrameBuffer sceneBuffer) { |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* Override this method if you want to save extra properties when the filter is saved else only basic properties of the filter will be saved |
* Override this method if you want to save extra properties when the filter is saved else only basic properties of the filter will be saved |
||||||
* This method should always begin by super.write(ex); |
* This method should always begin by super.write(ex); |
||||||
* @param ex |
* @param ex |
||||||
* @throws IOException |
* @throws IOException |
||||||
*/ |
*/ |
||||||
public void write(JmeExporter ex) throws IOException { |
public void write(JmeExporter ex) throws IOException { |
||||||
OutputCapsule oc = ex.getCapsule(this); |
OutputCapsule oc = ex.getCapsule(this); |
||||||
oc.write(name, "name", ""); |
oc.write(name, "name", ""); |
||||||
oc.write(enabled, "enabled", true); |
oc.write(enabled, "enabled", true); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* Override this method if you want to load extra properties when the filter |
* Override this method if you want to load extra properties when the filter |
||||||
* is loaded else only basic properties of the filter will be loaded |
* is loaded else only basic properties of the filter will be loaded |
||||||
* This method should always begin by super.read(im); |
* This method should always begin by super.read(im); |
||||||
*/ |
*/ |
||||||
public void read(JmeImporter im) throws IOException { |
public void read(JmeImporter im) throws IOException { |
||||||
InputCapsule ic = im.getCapsule(this); |
InputCapsule ic = im.getCapsule(this); |
||||||
name = ic.readString("name", ""); |
name = ic.readString("name", ""); |
||||||
enabled = ic.readBoolean("enabled", true); |
enabled = ic.readBoolean("enabled", true); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* returns the name of the filter |
* returns the name of the filter |
||||||
* @return the Filter's name |
* @return the Filter's name |
||||||
*/ |
*/ |
||||||
public String getName() { |
public String getName() { |
||||||
return name; |
return name; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* Sets the name of the filter |
* Sets the name of the filter |
||||||
* @param name |
* @param name |
||||||
*/ |
*/ |
||||||
public void setName(String name) { |
public void setName(String name) { |
||||||
this.name = name; |
this.name = name; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* returns the default pass frame buffer |
* returns the default pass frame buffer |
||||||
* @return |
* @return |
||||||
*/ |
*/ |
||||||
protected FrameBuffer getRenderFrameBuffer() { |
protected FrameBuffer getRenderFrameBuffer() { |
||||||
return defaultPass.renderFrameBuffer; |
return defaultPass.renderFrameBuffer; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* sets the default pas frame buffer |
* sets the default pas frame buffer |
||||||
* @param renderFrameBuffer |
* @param renderFrameBuffer |
||||||
*/ |
*/ |
||||||
protected void setRenderFrameBuffer(FrameBuffer renderFrameBuffer) { |
protected void setRenderFrameBuffer(FrameBuffer renderFrameBuffer) { |
||||||
this.defaultPass.renderFrameBuffer = renderFrameBuffer; |
this.defaultPass.renderFrameBuffer = renderFrameBuffer; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* returns the rendered texture of this filter |
* returns the rendered texture of this filter |
||||||
* @return |
* @return |
||||||
*/ |
*/ |
||||||
protected Texture2D getRenderedTexture() { |
protected Texture2D getRenderedTexture() { |
||||||
return defaultPass.renderedTexture; |
return defaultPass.renderedTexture; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* sets the rendered texture of this filter |
* sets the rendered texture of this filter |
||||||
* @param renderedTexture |
* @param renderedTexture |
||||||
*/ |
*/ |
||||||
protected void setRenderedTexture(Texture2D renderedTexture) { |
protected void setRenderedTexture(Texture2D renderedTexture) { |
||||||
this.defaultPass.renderedTexture = renderedTexture; |
this.defaultPass.renderedTexture = renderedTexture; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* Override this method and return true if your Filter needs the depth texture |
* Override this method and return true if your Filter needs the depth texture |
||||||
* |
* |
||||||
* @return true if your Filter need the depth texture |
* @return true if your Filter need the depth texture |
||||||
*/ |
*/ |
||||||
protected boolean isRequiresDepthTexture() { |
protected boolean isRequiresDepthTexture() { |
||||||
return false; |
return false; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* Override this method and return false if your Filter does not need the scene texture |
* Override this method and return false if your Filter does not need the scene texture |
||||||
* |
* |
||||||
* @return false if your Filter does not need the scene texture |
* @return false if your Filter does not need the scene texture |
||||||
*/ |
*/ |
||||||
protected boolean isRequiresSceneTexture() { |
protected boolean isRequiresSceneTexture() { |
||||||
return true; |
return true; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* returns the list of the postRender passes |
* returns the list of the postRender passes |
||||||
* @return |
* @return |
||||||
*/ |
*/ |
||||||
protected List<Pass> getPostRenderPasses() { |
protected List<Pass> getPostRenderPasses() { |
||||||
return postRenderPasses; |
return postRenderPasses; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* Enable or disable this filter |
* Enable or disable this filter |
||||||
* @param enabled true to enable |
* @param enabled true to enable |
||||||
*/ |
*/ |
||||||
public void setEnabled(boolean enabled) { |
public void setEnabled(boolean enabled) { |
||||||
if (processor != null) { |
if (processor != null) { |
||||||
processor.setFilterState(this, enabled); |
processor.setFilterState(this, enabled); |
||||||
} else { |
} else { |
||||||
this.enabled = enabled; |
this.enabled = enabled; |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* returns ttrue if the filter is enabled |
* returns true if the filter is enabled |
||||||
* @return enabled |
* @return enabled |
||||||
*/ |
*/ |
||||||
public boolean isEnabled() { |
public boolean isEnabled() { |
||||||
return enabled; |
return enabled; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* sets a reference to the FilterPostProcessor ti which this filter is attached |
* sets a reference to the FilterPostProcessor ti which this filter is attached |
||||||
* @param proc |
* @param proc |
||||||
*/ |
*/ |
||||||
protected void setProcessor(FilterPostProcessor proc) { |
protected void setProcessor(FilterPostProcessor proc) { |
||||||
processor = proc; |
processor = proc; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* This method is called right after the filter has been rendered to the |
* This method is called right after the filter has been rendered to the |
||||||
* framebuffer. |
* framebuffer. |
||||||
* Note that buffer will be null if the filter is the last one in the stack |
* Note that buffer will be null if the filter is the last one in the stack |
||||||
* and has been rendered to screen |
* and has been rendered to screen |
||||||
* @param r the renderer |
* @param r the renderer |
||||||
* @param buffer the framebuffer on hich the filtre has been rendered. |
* @param buffer the framebuffer on which the filter has been rendered. |
||||||
*/ |
*/ |
||||||
protected void postFilter(Renderer r, FrameBuffer buffer){ |
protected void postFilter(Renderer r, FrameBuffer buffer){ |
||||||
} |
} |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue