|
|
@ -51,8 +51,12 @@ import java.io.IOException; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
|
|
|
|
* SSAO stands for screen space ambient occlusion |
|
|
|
|
|
|
|
* It's a technique that fake ambient lighting by computind shadows that near by objects would casts on each others |
|
|
|
|
|
|
|
* under the effect of an ambient light |
|
|
|
|
|
|
|
* more info on this in this blog post http://jmonkeyengine.org/2010/08/16/screen-space-ambient-occlusion-for-jmonkeyengine-3-0/
|
|
|
|
* |
|
|
|
* |
|
|
|
* @author nehon |
|
|
|
* @author Rémy Bouquet aka Nehon |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class SSAOFilter extends Filter { |
|
|
|
public class SSAOFilter extends Filter { |
|
|
|
|
|
|
|
|
|
|
@ -68,8 +72,8 @@ public class SSAOFilter extends Filter { |
|
|
|
private boolean useAo = true; |
|
|
|
private boolean useAo = true; |
|
|
|
private Material ssaoMat; |
|
|
|
private Material ssaoMat; |
|
|
|
private Pass ssaoPass; |
|
|
|
private Pass ssaoPass; |
|
|
|
private Material downSampleMat; |
|
|
|
// private Material downSampleMat;
|
|
|
|
private Pass downSamplePass; |
|
|
|
// private Pass downSamplePass;
|
|
|
|
private float downSampleFactor = 1f; |
|
|
|
private float downSampleFactor = 1f; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -80,12 +84,11 @@ public class SSAOFilter extends Filter { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* |
|
|
|
* Create a Screen Space Ambiant Occlusion Filter |
|
|
|
* @param vp |
|
|
|
* @param sampleRadius The radius of the area where random samples will be picked. default 5.1f |
|
|
|
* @param sampleRadius |
|
|
|
* @param intensity intensity of the resulting AO. default 1.2f |
|
|
|
* @param intensity |
|
|
|
* @param scale distance between occluders and occludee. default 0.2f |
|
|
|
* @param scale |
|
|
|
* @param bias the width of the occlusion cone considered by the occludee. default 0.1f |
|
|
|
* @param bias |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public SSAOFilter(float sampleRadius, float intensity, float scale, float bias) { |
|
|
|
public SSAOFilter(float sampleRadius, float intensity, float scale, float bias) { |
|
|
|
this(); |
|
|
|
this(); |
|
|
@ -123,7 +126,7 @@ public class SSAOFilter extends Filter { |
|
|
|
postRenderPasses = new ArrayList<Pass>(); |
|
|
|
postRenderPasses = new ArrayList<Pass>(); |
|
|
|
|
|
|
|
|
|
|
|
normalPass = new Pass(); |
|
|
|
normalPass = new Pass(); |
|
|
|
normalPass.init(renderManager.getRenderer(), (int)(screenWidth / downSampleFactor), (int)(screenHeight / downSampleFactor), Format.RGBA8, Format.Depth); |
|
|
|
normalPass.init(renderManager.getRenderer(), (int) (screenWidth / downSampleFactor), (int) (screenHeight / downSampleFactor), Format.RGBA8, Format.Depth); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
frustumNearFar = new Vector2f(); |
|
|
|
frustumNearFar = new Vector2f(); |
|
|
@ -153,7 +156,7 @@ public class SSAOFilter extends Filter { |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
ssaoPass.init(renderManager.getRenderer(), (int)(screenWidth / downSampleFactor), (int)(screenHeight / downSampleFactor), Format.RGBA8, Format.Depth, 1, ssaoMat); |
|
|
|
ssaoPass.init(renderManager.getRenderer(), (int) (screenWidth / downSampleFactor), (int) (screenHeight / downSampleFactor), Format.RGBA8, Format.Depth, 1, ssaoMat); |
|
|
|
ssaoPass.getRenderedTexture().setMinFilter(Texture.MinFilter.Trilinear); |
|
|
|
ssaoPass.getRenderedTexture().setMinFilter(Texture.MinFilter.Trilinear); |
|
|
|
ssaoPass.getRenderedTexture().setMagFilter(Texture.MagFilter.Bilinear); |
|
|
|
ssaoPass.getRenderedTexture().setMagFilter(Texture.MagFilter.Bilinear); |
|
|
|
postRenderPasses.add(ssaoPass); |
|
|
|
postRenderPasses.add(ssaoPass); |
|
|
@ -180,10 +183,19 @@ public class SSAOFilter extends Filter { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Return the bias<br> |
|
|
|
|
|
|
|
* see {@link setBias(float bias)} |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
public float getBias() { |
|
|
|
public float getBias() { |
|
|
|
return bias; |
|
|
|
return bias; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Sets the the width of the occlusion cone considered by the occludee default is 0.1f |
|
|
|
|
|
|
|
* @param bias |
|
|
|
|
|
|
|
*/ |
|
|
|
public void setBias(float bias) { |
|
|
|
public void setBias(float bias) { |
|
|
|
this.bias = bias; |
|
|
|
this.bias = bias; |
|
|
|
if (ssaoMat != null) { |
|
|
|
if (ssaoMat != null) { |
|
|
@ -191,10 +203,18 @@ public class SSAOFilter extends Filter { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* returns the ambient occlusion intensity |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
public float getIntensity() { |
|
|
|
public float getIntensity() { |
|
|
|
return intensity; |
|
|
|
return intensity; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Sets the Ambient occlusion intensity default is 1.2f |
|
|
|
|
|
|
|
* @param intensity |
|
|
|
|
|
|
|
*/ |
|
|
|
public void setIntensity(float intensity) { |
|
|
|
public void setIntensity(float intensity) { |
|
|
|
this.intensity = intensity; |
|
|
|
this.intensity = intensity; |
|
|
|
if (ssaoMat != null) { |
|
|
|
if (ssaoMat != null) { |
|
|
@ -203,10 +223,19 @@ public class SSAOFilter extends Filter { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* returns the sample radius<br> |
|
|
|
|
|
|
|
* see {link setSampleRadius(float sampleRadius)} |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
public float getSampleRadius() { |
|
|
|
public float getSampleRadius() { |
|
|
|
return sampleRadius; |
|
|
|
return sampleRadius; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Sets the radius of the area where random samples will be picked dafault 5.1f |
|
|
|
|
|
|
|
* @param sampleRadius |
|
|
|
|
|
|
|
*/ |
|
|
|
public void setSampleRadius(float sampleRadius) { |
|
|
|
public void setSampleRadius(float sampleRadius) { |
|
|
|
this.sampleRadius = sampleRadius; |
|
|
|
this.sampleRadius = sampleRadius; |
|
|
|
if (ssaoMat != null) { |
|
|
|
if (ssaoMat != null) { |
|
|
@ -215,22 +244,39 @@ public class SSAOFilter extends Filter { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* returns the scale<br> |
|
|
|
|
|
|
|
* see {@link setScale(float scale)} |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
public float getScale() { |
|
|
|
public float getScale() { |
|
|
|
return scale; |
|
|
|
return scale; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* Returns the distance between occluders and occludee. dafault 0.2f |
|
|
|
|
|
|
|
* @param scale |
|
|
|
|
|
|
|
*/ |
|
|
|
public void setScale(float scale) { |
|
|
|
public void setScale(float scale) { |
|
|
|
this.scale = scale; |
|
|
|
this.scale = scale; |
|
|
|
if (ssaoMat != null) { |
|
|
|
if (ssaoMat != null) { |
|
|
|
ssaoMat.setFloat("Scale", scale); |
|
|
|
ssaoMat.setFloat("Scale", scale); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* debugging only , will be removed |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
public boolean isUseAo() { |
|
|
|
public boolean isUseAo() { |
|
|
|
return useAo; |
|
|
|
return useAo; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* debugging only , will be removed |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
public void setUseAo(boolean useAo) { |
|
|
|
public void setUseAo(boolean useAo) { |
|
|
|
this.useAo = useAo; |
|
|
|
this.useAo = useAo; |
|
|
|
if (material != null) { |
|
|
|
if (material != null) { |
|
|
@ -239,10 +285,18 @@ public class SSAOFilter extends Filter { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* debugging only , will be removed |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
public boolean isUseOnlyAo() { |
|
|
|
public boolean isUseOnlyAo() { |
|
|
|
return useOnlyAo; |
|
|
|
return useOnlyAo; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* debugging only , will be removed |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
public void setUseOnlyAo(boolean useOnlyAo) { |
|
|
|
public void setUseOnlyAo(boolean useOnlyAo) { |
|
|
|
this.useOnlyAo = useOnlyAo; |
|
|
|
this.useOnlyAo = useOnlyAo; |
|
|
|
if (material != null) { |
|
|
|
if (material != null) { |
|
|
@ -269,6 +323,4 @@ public class SSAOFilter extends Filter { |
|
|
|
scale = ic.readFloat("scale", 0.2f); |
|
|
|
scale = ic.readFloat("scale", 0.2f); |
|
|
|
bias = ic.readFloat("bias", 0.1f); |
|
|
|
bias = ic.readFloat("bias", 0.1f); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|