SSAOFilter can now be multi sampled

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7007 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 14 years ago
parent 656783476e
commit 6e76c602e4
  1. 11
      engine/src/core-data/Common/MatDefs/SSAO/ssaoBlur.frag
  2. 41
      engine/src/core-data/Common/MatDefs/SSAO/ssaoBlur.j3md
  3. 160
      engine/src/core-data/Common/MatDefs/SSAO/ssaoBlur15.frag

@ -12,14 +12,15 @@ varying vec2 texCoord;
vec4 getColor(vec4 color){
if(m_UseOnlyAo){
#ifdef USE_ONLY_AO
return color;
}
if(m_UseAo){
#endif
#ifdef USE_AO
return texture2D(m_Texture,texCoord)* color;
}else{
#endif
return texture2D(m_Texture,texCoord);
}
}

@ -1,6 +1,8 @@
MaterialDef SSAOBlur {
MaterialParameters {
Int NumSamples
Int NumSamplesDepth
Texture2D Texture
Texture2D SSAOMap
Texture2D DepthTexture
@ -11,21 +13,23 @@ MaterialDef SSAOBlur {
Float YScale
}
// Technique {
// VertexShader GLSL150: Common/MatDefs/Post/Post15.vert
// FragmentShader GLSL150: Common/MatDefs/SSAO/ssaoBlur15.frag
//
// WorldParameters {
// WorldViewProjectionMatrix
// WorldViewMatrix
// Resolution
// }
//
// Defines {
// RESOLVE_MS : NumSamples
// RESOLVE_DEPTH_MS : NumSamplesDepth
// }
// }
Technique {
VertexShader GLSL150: Common/MatDefs/Post/Post15.vert
FragmentShader GLSL150: Common/MatDefs/SSAO/ssaoBlur15.frag
WorldParameters {
WorldViewProjectionMatrix
WorldViewMatrix
Resolution
}
Defines {
USE_AO : UseAo
USE_ONLY_AO : UseOnlyAo
RESOLVE_MS : NumSamples
RESOLVE_DEPTH_MS : NumSamplesDepth
}
}
Technique {
VertexShader GLSL120: Common/MatDefs/Post/Post.vert
@ -37,6 +41,13 @@ MaterialDef SSAOBlur {
Resolution
}
Defines {
USE_AO : UseAo
USE_ONLY_AO : UseOnlyAo
RESOLVE_MS : NumSamples
RESOLVE_DEPTH_MS : NumSamplesDepth
}
}

@ -0,0 +1,160 @@
#import "Common/ShaderLib/MultiSample.glsllib"
uniform COLORTEXTURE m_Texture;
uniform DEPTHTEXTURE m_DepthTexture;
uniform sampler2D m_SSAOMap;
uniform vec2 g_Resolution;
uniform bool m_UseOnlyAo;
uniform bool m_UseAo;
uniform float m_XScale;
uniform float m_YScale;
uniform vec2 m_FrustumNearFar;
varying vec2 texCoord;
vec4 getResult(vec4 color){
#ifdef USE_ONLY_AO
return color;
#endif
#ifdef USE_AO
return getColor(m_Texture,texCoord)* color;
#endif
return getColor(m_Texture,texCoord);
}
float readDepth(in vec2 uv){
float depthv =fetchTextureSample(m_DepthTexture,uv,0).r;
return (2.0 * m_FrustumNearFar.x) / (m_FrustumNearFar.y + m_FrustumNearFar.x - depthv* (m_FrustumNearFar.y-m_FrustumNearFar.x));
}
const float epsilon = 0.005;
/*
const int kernelSize=7;
vec4 bilateralFilter() {
vec4 color = vec4(0.0);
vec2 sample;
float sum = 0.0;
float coefZ;
float Zp = readDepth(texCoord);
for(int i = -(kernelSize-1); i <= (kernelSize-1); i+=2) {
for(int j = -(kernelSize-1); j <= (kernelSize-1); j+=2) {
sample = texCoord + vec2(i,j) / g_Resolution;
float zTmp =readDepth(sample);
coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
sum += coefZ;
color += coefZ * texture2D(m_SSAOMap,sample);
}
}
return color / sum;
}
*/
vec4 convolutionFilter(){
vec4 sum = vec4(0.0);
float x = texCoord.x;
float y = texCoord.y;
float xScale = m_XScale;
float yScale = m_YScale;
float zsum = 1.0;
float Zp =readDepth(texCoord);
vec2 sample = vec2(x - 2.0 * xScale, y - 2.0 * yScale);
float zTmp =readDepth(sample);
float coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
zsum += coefZ;
sum += coefZ* texture2D( m_SSAOMap, sample);
sample = vec2(x - 0.0 * xScale, y - 2.0 * yScale);
zTmp =readDepth(sample);
coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
zsum += coefZ;
sum += coefZ* texture2D( m_SSAOMap, sample);
sample = vec2(x + 2.0 * xScale, y - 2.0 * yScale);
zTmp =readDepth(sample);
coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
zsum += coefZ;
sum += coefZ* texture2D( m_SSAOMap, sample);
sample = vec2(x - 1.0 * xScale, y - 1.0 * yScale);
zTmp =readDepth(sample);
coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
zsum += coefZ;
sum += coefZ* texture2D( m_SSAOMap, sample);
sample = vec2(x + 1.0 * xScale, y - 1.0 * yScale);
zTmp =readDepth(sample);
coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
zsum += coefZ;
sum += coefZ* texture2D( m_SSAOMap, sample);
sample = vec2(x - 2.0 * xScale, y - 0.0 * yScale);
zTmp =readDepth(sample);
coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
zsum += coefZ;
sum += coefZ* texture2D( m_SSAOMap, sample);
sample = vec2(x + 2.0 * xScale, y - 0.0 * yScale);
zTmp =readDepth(sample);
coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
zsum += coefZ;
sum += coefZ* texture2D( m_SSAOMap, sample);
sample = vec2(x - 1.0 * xScale, y + 1.0 * yScale);
zTmp =readDepth(sample);
coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
zsum += coefZ;
sum += coefZ* texture2D( m_SSAOMap, sample);
sample = vec2(x + 1.0 * xScale, y + 1.0 * yScale);
zTmp =readDepth(sample);
coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
zsum += coefZ;
sum += coefZ* texture2D( m_SSAOMap, sample);
sample = vec2(x - 2.0 * xScale, y + 2.0 * yScale);
zTmp =readDepth(sample);
coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
zsum += coefZ;
sum += coefZ* texture2D( m_SSAOMap, sample);
sample = vec2(x - 0.0 * xScale, y + 2.0 * yScale);
zTmp =readDepth(sample);
coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
zsum += coefZ;
sum += coefZ* texture2D( m_SSAOMap, sample);
sample = vec2(x + 2.0 * xScale, y + 2.0 * yScale);
zTmp =readDepth(sample);
coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
zsum += coefZ;
sum += coefZ* texture2D( m_SSAOMap, sample);
return sum / zsum;
}
void main(){
// float depth =texture2D(m_DepthTexture,uv).r;
gl_FragColor=getResult(convolutionFilter());
// gl_FragColor=getResult(bilateralFilter());
// gl_FragColor=getColor(m_SSAOMap,texCoord);
}
Loading…
Cancel
Save