- FilterPostProcessor no longer use a different camera to render the fulscreen quad. This greatly simplify the multiviewport filtering handling and global uniform matrix will now be usable in fliter's shaders, because it uses the same cam as the back buffer scene.

- Changed the post.vert and post15.vert to do a very basic projection to screen, saves a 16 float uniform and replace 4 matrices multiplication with 4 MAD operations per filter.
- Used ResolutionInverse instead of Resolution in FXAA to multiply instead of dividing once per pixel
- Same in CartoonEdge
- LightScattering now uses the standard post.vert and post15.vert
- Various cleanups in SSAO


git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10750 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
experimental
rem..om 12 years ago
parent 0bb9822322
commit afa9376b26
  1. 1
      engine/src/core-data/Common/MatDefs/Blur/HGaussianBlur.j3md
  2. 2
      engine/src/core-data/Common/MatDefs/Blur/RadialBlur.j3md
  3. 1
      engine/src/core-data/Common/MatDefs/Blur/VGaussianBlur.j3md
  4. 2
      engine/src/core-effects/Common/MatDefs/Post/BloomExtract.j3md
  5. 2
      engine/src/core-effects/Common/MatDefs/Post/BloomFinal.j3md
  6. 4
      engine/src/core-effects/Common/MatDefs/Post/CartoonEdge.frag
  7. 6
      engine/src/core-effects/Common/MatDefs/Post/CartoonEdge.j3md
  8. 4
      engine/src/core-effects/Common/MatDefs/Post/CartoonEdge15.frag
  9. 2
      engine/src/core-effects/Common/MatDefs/Post/Compose.j3md
  10. 1
      engine/src/core-effects/Common/MatDefs/Post/CrossHatch.j3md
  11. 1
      engine/src/core-effects/Common/MatDefs/Post/DepthOfField.j3md
  12. 6
      engine/src/core-effects/Common/MatDefs/Post/FXAA.frag
  13. 3
      engine/src/core-effects/Common/MatDefs/Post/FXAA.j3md
  14. 7
      engine/src/core-effects/Common/MatDefs/Post/FXAA.vert
  15. 2
      engine/src/core-effects/Common/MatDefs/Post/Fade.j3md
  16. 2
      engine/src/core-effects/Common/MatDefs/Post/Fog.j3md
  17. 2
      engine/src/core-effects/Common/MatDefs/Post/GammaCorrection.j3md
  18. 6
      engine/src/core-effects/Common/MatDefs/Post/LightScattering.frag
  19. 10
      engine/src/core-effects/Common/MatDefs/Post/LightScattering.j3md
  20. 14
      engine/src/core-effects/Common/MatDefs/Post/LightScattering.vert
  21. 11
      engine/src/core-effects/Common/MatDefs/Post/LightScattering15.frag
  22. 6
      engine/src/core-effects/Common/MatDefs/Post/LightScattering15.vert
  23. 4
      engine/src/core-effects/Common/MatDefs/Post/Overlay.j3md
  24. 7
      engine/src/core-effects/Common/MatDefs/Post/Post.vert
  25. 4
      engine/src/core-effects/Common/MatDefs/Post/Post15.vert
  26. 4
      engine/src/core-effects/Common/MatDefs/Post/Posterization.j3md
  27. 7
      engine/src/core-effects/Common/MatDefs/SSAO/ssao.frag
  28. 5
      engine/src/core-effects/Common/MatDefs/SSAO/ssao.j3md
  29. 8
      engine/src/core-effects/Common/MatDefs/SSAO/ssao15.frag
  30. 7
      engine/src/core-effects/Common/MatDefs/SSAO/ssaoBlur.j3md
  31. 28
      engine/src/core-effects/Common/MatDefs/SSAO/ssaoBlur15.frag
  32. 2
      engine/src/core-effects/Common/MatDefs/Water/Water.j3md
  33. 61
      engine/src/core/com/jme3/post/FilterPostProcessor.java

@ -12,7 +12,6 @@ MaterialDef Bloom {
FragmentShader GLSL100: Common/MatDefs/Blur/HGaussianBlur.frag FragmentShader GLSL100: Common/MatDefs/Blur/HGaussianBlur.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
} }
} }
} }

@ -14,7 +14,6 @@ MaterialDef Radial Blur {
FragmentShader GLSL150: Common/MatDefs/Blur/RadialBlur15.frag FragmentShader GLSL150: Common/MatDefs/Blur/RadialBlur15.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
} }
Defines { Defines {
@ -27,7 +26,6 @@ MaterialDef Radial Blur {
FragmentShader GLSL120: Common/MatDefs/Blur/RadialBlur.frag FragmentShader GLSL120: Common/MatDefs/Blur/RadialBlur.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
} }
} }
} }

@ -12,7 +12,6 @@ MaterialDef Bloom {
FragmentShader GLSL100: Common/MatDefs/Blur/VGaussianBlur.frag FragmentShader GLSL100: Common/MatDefs/Blur/VGaussianBlur.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
} }
} }
} }

@ -14,7 +14,6 @@ MaterialDef Bloom {
FragmentShader GLSL150: Common/MatDefs/Post/bloomExtract15.frag FragmentShader GLSL150: Common/MatDefs/Post/bloomExtract15.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
} }
Defines { Defines {
@ -29,7 +28,6 @@ MaterialDef Bloom {
FragmentShader GLSL100: Common/MatDefs/Post/bloomExtract.frag FragmentShader GLSL100: Common/MatDefs/Post/bloomExtract.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
} }
Defines { Defines {

@ -12,7 +12,6 @@ MaterialDef Bloom Final {
FragmentShader GLSL150: Common/MatDefs/Post/bloomFinal15.frag FragmentShader GLSL150: Common/MatDefs/Post/bloomFinal15.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
} }
Defines { Defines {
@ -25,7 +24,6 @@ MaterialDef Bloom Final {
FragmentShader GLSL100: Common/MatDefs/Post/bloomFinal.frag FragmentShader GLSL100: Common/MatDefs/Post/bloomFinal.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
} }
} }
} }

@ -15,7 +15,7 @@ uniform sampler2D m_Texture;
uniform sampler2D m_NormalsTexture; uniform sampler2D m_NormalsTexture;
uniform sampler2D m_DepthTexture; uniform sampler2D m_DepthTexture;
uniform vec2 g_Resolution; uniform vec2 g_ResolutionInverse;
vec4 fetchNormalDepth(vec2 tc){ vec4 fetchNormalDepth(vec2 tc){
vec4 nd; vec4 nd;
@ -27,7 +27,7 @@ vec4 fetchNormalDepth(vec2 tc){
void main(){ void main(){
vec3 color = texture2D(m_Texture, texCoord).rgb; vec3 color = texture2D(m_Texture, texCoord).rgb;
vec2 edgeOffset = vec2(m_EdgeWidth) / g_Resolution; vec2 edgeOffset = vec2(m_EdgeWidth) * g_ResolutionInverse;
vec4 n1 = fetchNormalDepth(texCoord + vec2(-1.0, -1.0) * edgeOffset); vec4 n1 = fetchNormalDepth(texCoord + vec2(-1.0, -1.0) * edgeOffset);
vec4 n2 = fetchNormalDepth(texCoord + vec2( 1.0, 1.0) * edgeOffset); vec4 n2 = fetchNormalDepth(texCoord + vec2( 1.0, 1.0) * edgeOffset);

@ -20,9 +20,8 @@ MaterialDef Cartoon Edge {
FragmentShader GLSL150: Common/MatDefs/Post/CartoonEdge15.frag FragmentShader GLSL150: Common/MatDefs/Post/CartoonEdge15.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
WorldViewMatrix WorldViewMatrix
Resolution ResolutionInverse
} }
Defines { Defines {
@ -37,9 +36,8 @@ MaterialDef Cartoon Edge {
FragmentShader GLSL100: Common/MatDefs/Post/CartoonEdge.frag FragmentShader GLSL100: Common/MatDefs/Post/CartoonEdge.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
WorldViewMatrix WorldViewMatrix
Resolution ResolutionInverse
} }
} }
} }

@ -4,7 +4,7 @@ uniform COLORTEXTURE m_Texture;
uniform DEPTHTEXTURE m_DepthTexture; uniform DEPTHTEXTURE m_DepthTexture;
uniform sampler2D m_NormalsTexture; uniform sampler2D m_NormalsTexture;
uniform vec2 g_Resolution; uniform vec2 g_ResolutionInverse;
uniform vec4 m_EdgeColor; uniform vec4 m_EdgeColor;
@ -30,7 +30,7 @@ vec4 fetchNormalDepth(vec2 tc){
void main(){ void main(){
vec3 color = getColor(m_Texture, texCoord).rgb; vec3 color = getColor(m_Texture, texCoord).rgb;
vec2 edgeOffset = vec2(m_EdgeWidth) / textureSize(m_NormalsTexture, 0); vec2 edgeOffset = vec2(m_EdgeWidth) * g_ResolutionInverse;
vec4 n1 = fetchNormalDepth(texCoord + vec2(-1.0, -1.0) * edgeOffset); vec4 n1 = fetchNormalDepth(texCoord + vec2(-1.0, -1.0) * edgeOffset);
vec4 n2 = fetchNormalDepth(texCoord + vec2( 1.0, 1.0) * edgeOffset); vec4 n2 = fetchNormalDepth(texCoord + vec2( 1.0, 1.0) * edgeOffset);
vec4 n3 = fetchNormalDepth(texCoord + vec2(-1.0, 1.0) * edgeOffset); vec4 n3 = fetchNormalDepth(texCoord + vec2(-1.0, 1.0) * edgeOffset);

@ -12,7 +12,6 @@ MaterialDef Default GUI {
FragmentShader GLSL150: Common/MatDefs/Post/Compose15.frag FragmentShader GLSL150: Common/MatDefs/Post/Compose15.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
} }
Defines { Defines {
@ -26,7 +25,6 @@ MaterialDef Default GUI {
FragmentShader GLSL100: Common/MatDefs/Post/Compose.frag FragmentShader GLSL100: Common/MatDefs/Post/Compose.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
} }
} }

@ -22,7 +22,6 @@ MaterialDef CrossHatch {
FragmentShader GLSL150: Common/MatDefs/Post/CrossHatch15.frag FragmentShader GLSL150: Common/MatDefs/Post/CrossHatch15.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
} }
} }

@ -16,7 +16,6 @@ MaterialDef Depth Of Field {
FragmentShader GLSL100: Common/MatDefs/Post/DepthOfField.frag FragmentShader GLSL100: Common/MatDefs/Post/DepthOfField.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
} }
} }
} }

@ -1,7 +1,7 @@
#extension GL_EXT_gpu_shader4 : enable #extension GL_EXT_gpu_shader4 : enable
uniform sampler2D m_Texture; uniform sampler2D m_Texture;
uniform vec2 g_Resolution; uniform vec2 g_ResolutionInverse;
uniform float m_VxOffset; uniform float m_VxOffset;
uniform float m_SpanMax; uniform float m_SpanMax;
@ -83,6 +83,6 @@ vec3 FxaaPixelShader(
void main() void main()
{ {
vec2 rcpFrame = vec2(1.0) / g_Resolution;
gl_FragColor = vec4(FxaaPixelShader(posPos, m_Texture, rcpFrame), 1.0); gl_FragColor = vec4(FxaaPixelShader(posPos, m_Texture, g_ResolutionInverse), 1.0);
} }

@ -11,8 +11,7 @@ MaterialDef FXAA {
VertexShader GLSL100: Common/MatDefs/Post/FXAA.vert VertexShader GLSL100: Common/MatDefs/Post/FXAA.vert
FragmentShader GLSL100: Common/MatDefs/Post/FXAA.frag FragmentShader GLSL100: Common/MatDefs/Post/FXAA.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix ResolutionInverse
Resolution
} }
} }
} }

@ -1,5 +1,5 @@
uniform mat4 g_WorldViewProjectionMatrix; uniform mat4 g_WorldViewProjectionMatrix;
uniform vec2 g_Resolution; uniform vec2 g_ResolutionInverse;
uniform float m_SubPixelShift; uniform float m_SubPixelShift;
@ -12,8 +12,7 @@ varying vec4 posPos;
void main() { void main() {
vec2 pos = (g_WorldViewProjectionMatrix * inPosition).xy; vec2 pos = (g_WorldViewProjectionMatrix * inPosition).xy;
gl_Position = vec4(pos, 0.0, 1.0); gl_Position = vec4(pos, 0.0, 1.0);
texCoord = inTexCoord; texCoord = inTexCoord;
vec2 rcpFrame = vec2(1.0) / g_Resolution;
posPos.xy = inTexCoord.xy; posPos.xy = inTexCoord.xy;
posPos.zw = inTexCoord.xy - (rcpFrame * vec2(0.5 + m_SubPixelShift)); posPos.zw = inTexCoord.xy - (g_ResolutionInverse * vec2(0.5 + m_SubPixelShift));
} }

@ -11,7 +11,6 @@ MaterialDef Fade {
FragmentShader GLSL150: Common/MatDefs/Post/Fade15.frag FragmentShader GLSL150: Common/MatDefs/Post/Fade15.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
} }
Defines { Defines {
@ -24,7 +23,6 @@ MaterialDef Fade {
FragmentShader GLSL100: Common/MatDefs/Post/Fade.frag FragmentShader GLSL100: Common/MatDefs/Post/Fade.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
} }
} }
} }

@ -15,7 +15,6 @@ MaterialDef Fade {
FragmentShader GLSL150: Common/MatDefs/Post/Fog15.frag FragmentShader GLSL150: Common/MatDefs/Post/Fog15.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
} }
Defines { Defines {
@ -29,7 +28,6 @@ MaterialDef Fade {
FragmentShader GLSL100: Common/MatDefs/Post/Fog.frag FragmentShader GLSL100: Common/MatDefs/Post/Fog.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
} }
} }
} }

@ -12,7 +12,6 @@ MaterialDef GammaCorrection {
FragmentShader GLSL150: Common/MatDefs/Post/GammaCorrection15.frag FragmentShader GLSL150: Common/MatDefs/Post/GammaCorrection15.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
} }
Defines { Defines {
@ -25,7 +24,6 @@ MaterialDef GammaCorrection {
FragmentShader GLSL100: Common/MatDefs/Post/GammaCorrection.frag FragmentShader GLSL100: Common/MatDefs/Post/GammaCorrection.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
} }
Defines { Defines {

@ -5,8 +5,8 @@ uniform float m_BlurStart;
uniform float m_BlurWidth; uniform float m_BlurWidth;
uniform float m_LightDensity; uniform float m_LightDensity;
uniform bool m_Display; uniform bool m_Display;
uniform vec3 m_LightPosition;
varying vec2 lightPos;
varying vec2 texCoord; varying vec2 texCoord;
void main(void) void main(void)
@ -16,12 +16,12 @@ void main(void)
vec4 colorRes= texture2D(m_Texture,texCoord); vec4 colorRes= texture2D(m_Texture,texCoord);
float factor=(m_BlurWidth/float(m_NbSamples-1.0)); float factor=(m_BlurWidth/float(m_NbSamples-1.0));
float scale; float scale;
vec2 texCoo=texCoord-lightPos; vec2 texCoo=texCoord - m_LightPosition.xy;
vec2 scaledCoord; vec2 scaledCoord;
vec4 res = vec4(0.0); vec4 res = vec4(0.0);
for(int i=0; i<m_NbSamples; i++) { for(int i=0; i<m_NbSamples; i++) {
scale = i * factor + m_BlurStart ; scale = i * factor + m_BlurStart ;
scaledCoord=texCoo*scale+lightPos; scaledCoord=texCoo*scale + m_LightPosition.xy;
if(texture2D(m_DepthTexture,scaledCoord).r==1.0){ if(texture2D(m_DepthTexture,scaledCoord).r==1.0){
res += texture2D(m_Texture,scaledCoord); res += texture2D(m_Texture,scaledCoord);
} }

@ -14,11 +14,10 @@ MaterialDef Light Scattering {
} }
Technique { Technique {
VertexShader GLSL150: Common/MatDefs/Post/LightScattering15.vert VertexShader GLSL150: Common/MatDefs/Post/Post15.vert
FragmentShader GLSL150: Common/MatDefs/Post/LightScattering15.frag FragmentShader GLSL150: Common/MatDefs/Post/LightScattering15.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
} }
Defines { Defines {
@ -28,11 +27,10 @@ MaterialDef Light Scattering {
} }
Technique { Technique {
VertexShader GLSL120: Common/MatDefs/Post/LightScattering.vert VertexShader GLSL120: Common/MatDefs/Post/Post.vert
FragmentShader GLSL120: Common/MatDefs/Post/LightScattering.frag FragmentShader GLSL120: Common/MatDefs/Post/LightScattering.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
} }
} }
} }

@ -1,14 +0,0 @@
uniform mat4 g_WorldViewProjectionMatrix;
uniform vec3 m_LightPosition;
attribute vec4 inPosition;
attribute vec2 inTexCoord;
varying vec2 texCoord;
varying vec2 lightPos;
void main() {
vec2 pos = (g_WorldViewProjectionMatrix * inPosition).xy;
gl_Position = vec4(pos, 0.0, 1.0);
lightPos=m_LightPosition.xy;
texCoord = inTexCoord;
}

@ -8,9 +8,10 @@ uniform float m_BlurStart;
uniform float m_BlurWidth; uniform float m_BlurWidth;
uniform float m_LightDensity; uniform float m_LightDensity;
uniform bool m_Display; uniform bool m_Display;
uniform vec3 m_LightPosition;
in vec2 lightPos;
in vec2 texCoord; in vec2 texCoord;
out vec4 fragColor;
void main(void) void main(void)
{ {
@ -19,12 +20,12 @@ void main(void)
vec4 colorRes= getColor(m_Texture,texCoord); vec4 colorRes= getColor(m_Texture,texCoord);
float factor=(m_BlurWidth/float(m_NbSamples-1.0)); float factor=(m_BlurWidth/float(m_NbSamples-1.0));
float scale; float scale;
vec2 texCoo=texCoord-lightPos; vec2 texCoo=texCoord - m_LightPosition.xy;
vec2 scaledCoord; vec2 scaledCoord;
vec4 res = vec4(0.0); vec4 res = vec4(0.0);
for(int i=0; i<m_NbSamples; i++) { for(int i=0; i<m_NbSamples; i++) {
scale = i * factor + m_BlurStart ; scale = i * factor + m_BlurStart ;
scaledCoord=texCoo*scale+lightPos; scaledCoord=texCoo*scale + m_LightPosition.xy;
if(fetchTextureSample(m_DepthTexture, scaledCoord,0).r==1.0){ if(fetchTextureSample(m_DepthTexture, scaledCoord,0).r==1.0){
res += fetchTextureSample(m_Texture,scaledCoord,0); res += fetchTextureSample(m_Texture,scaledCoord,0);
} }
@ -32,8 +33,8 @@ void main(void)
res /= m_NbSamples; res /= m_NbSamples;
//Blend the original color with the averaged pixels //Blend the original color with the averaged pixels
gl_FragColor =mix( colorRes, res, m_LightDensity); fragColor = mix( colorRes, res, m_LightDensity);
}else{ }else{
gl_FragColor= getColor(m_Texture,texCoord); fragColor = getColor(m_Texture,texCoord);
} }
} }

@ -1,4 +1,6 @@
uniform mat4 g_WorldViewProjectionMatrix; //uniform mat4 g_WorldViewProjectionMatrix;
uniform vec2 g_Resolution;
uniform vec4 g_ViewPort;
uniform vec3 m_LightPosition; uniform vec3 m_LightPosition;
in vec4 inPosition; in vec4 inPosition;
@ -7,7 +9,7 @@ out vec2 texCoord;
out vec2 lightPos; out vec2 lightPos;
void main() { void main() {
vec2 pos = (g_WorldViewProjectionMatrix * inPosition).xy; vec2 pos = inPosition.xy* 2.0 - 1.0;
gl_Position = vec4(pos, 0.0, 1.0); gl_Position = vec4(pos, 0.0, 1.0);
lightPos=m_LightPosition.xy; lightPos=m_LightPosition.xy;
texCoord = inTexCoord; texCoord = inTexCoord;

@ -12,7 +12,6 @@ MaterialDef Default GUI {
FragmentShader GLSL150: Common/MatDefs/Post/Overlay15.frag FragmentShader GLSL150: Common/MatDefs/Post/Overlay15.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
} }
Defines { Defines {
@ -25,8 +24,7 @@ MaterialDef Default GUI {
VertexShader GLSL100: Common/MatDefs/Post/Post.vert VertexShader GLSL100: Common/MatDefs/Post/Post.vert
FragmentShader GLSL100: Common/MatDefs/Post/Overlay.frag FragmentShader GLSL100: Common/MatDefs/Post/Overlay.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
} }
} }

@ -1,11 +1,10 @@
uniform mat4 g_WorldViewProjectionMatrix;
attribute vec4 inPosition; attribute vec4 inPosition;
attribute vec2 inTexCoord; attribute vec2 inTexCoord;
varying vec2 texCoord; varying vec2 texCoord;
void main() { void main() {
vec2 pos = (g_WorldViewProjectionMatrix * inPosition).xy; vec2 pos = inPosition.xy * 2.0 - 1.0;
gl_Position = vec4(pos, 0.0, 1.0); gl_Position = vec4(pos, 0.0, 1.0);
texCoord = inTexCoord; texCoord = inTexCoord;
} }

@ -1,12 +1,10 @@
uniform mat4 g_WorldViewProjectionMatrix;
in vec4 inPosition; in vec4 inPosition;
in vec2 inTexCoord; in vec2 inTexCoord;
out vec2 texCoord; out vec2 texCoord;
void main() { void main() {
vec2 pos = (g_WorldViewProjectionMatrix * inPosition).xy; vec2 pos = inPosition.xy * 2.0 - 1.0;
gl_Position = vec4(pos, 0.0, 1.0); gl_Position = vec4(pos, 0.0, 1.0);
texCoord = inTexCoord; texCoord = inTexCoord;
} }

@ -13,7 +13,6 @@ MaterialDef Posterization {
FragmentShader GLSL150: Common/MatDefs/Post/Posterization15.frag FragmentShader GLSL150: Common/MatDefs/Post/Posterization15.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
} }
} }
@ -21,8 +20,7 @@ MaterialDef Posterization {
VertexShader GLSL100: Common/MatDefs/Post/Post.vert VertexShader GLSL100: Common/MatDefs/Post/Post.vert
FragmentShader GLSL100: Common/MatDefs/Post/Posterization.frag FragmentShader GLSL100: Common/MatDefs/Post/Posterization.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
} }
} }
} }

@ -2,6 +2,7 @@ uniform vec2 g_Resolution;
uniform vec2 m_FrustumNearFar; uniform vec2 m_FrustumNearFar;
uniform sampler2D m_Texture; uniform sampler2D m_Texture;
uniform sampler2D m_Normals; uniform sampler2D m_Normals;
uniform sampler2D m_RandomMap;
uniform sampler2D m_DepthTexture; uniform sampler2D m_DepthTexture;
uniform vec3 m_FrustumCorner; uniform vec3 m_FrustumCorner;
uniform float m_SampleRadius; uniform float m_SampleRadius;
@ -32,9 +33,9 @@ vec3 getNormal(in vec2 uv){
return normalize(texture2D(m_Normals, uv).xyz * 2.0 - 1.0); return normalize(texture2D(m_Normals, uv).xyz * 2.0 - 1.0);
} }
vec2 getRandom(in vec2 uv){ vec2 getRandom(in vec2 uv){
float rand=(fract(uv.x*(g_Resolution.x/2.0))*0.25)+(fract(uv.y*(g_Resolution.y/2.0))*0.5); vec4 rand=texture2D(m_RandomMap,g_Resolution.zw * uv / 128.0 * 3.0)*2.0 -1.0;
return normalize(vec2(rand,rand)); return normalize(rand.xy);
} }
float doAmbientOcclusion(in vec2 tc, in vec3 pos, in vec3 norm){ float doAmbientOcclusion(in vec2 tc, in vec3 pos, in vec3 norm){

@ -20,8 +20,7 @@ MaterialDef SSAO {
VertexShader GLSL150: Common/MatDefs/Post/Post15.vert VertexShader GLSL150: Common/MatDefs/Post/Post15.vert
FragmentShader GLSL150: Common/MatDefs/SSAO/ssao15.frag FragmentShader GLSL150: Common/MatDefs/SSAO/ssao15.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
WorldViewMatrix WorldViewMatrix
Resolution Resolution
} }
@ -37,10 +36,8 @@ MaterialDef SSAO {
FragmentShader GLSL120: Common/MatDefs/SSAO/ssao.frag FragmentShader GLSL120: Common/MatDefs/SSAO/ssao.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
WorldViewMatrix WorldViewMatrix
Resolution Resolution
} }
} }
} }

@ -16,6 +16,8 @@ uniform vec2[4] m_Samples;
in vec2 texCoord; in vec2 texCoord;
out vec4 fragColor;
float depthv; float depthv;
vec3 getPosition(in vec2 uv){ vec3 getPosition(in vec2 uv){
@ -36,7 +38,7 @@ vec3 getNormal(in vec2 uv){
vec2 getRandom(in vec2 uv){ vec2 getRandom(in vec2 uv){
//float rand=(fract(uv.x*(g_Resolution.x/2.0))*0.25)+(fract(uv.y*(g_Resolution.y/2.0))*0.5); //float rand=(fract(uv.x*(g_Resolution.x/2.0))*0.25)+(fract(uv.y*(g_Resolution.y/2.0))*0.5);
vec4 rand=texture2D(m_RandomMap,g_Resolution * uv / 128.0 * 3.0)*2.0 -1.0; vec4 rand=texture2D(m_RandomMap, g_Resolution * uv / 128.0 * 3.0)*2.0 -1.0;
return normalize(rand.xy); return normalize(rand.xy);
} }
@ -64,7 +66,7 @@ void main(){
vec3 position = getPosition(texCoord); vec3 position = getPosition(texCoord);
//optimization, do not calculate AO if depth is 1 //optimization, do not calculate AO if depth is 1
if(depthv==1.0){ if(depthv==1.0){
gl_FragColor=vec4(1.0); fragColor = vec4(1.0);
return; return;
} }
vec3 normal = getNormal(texCoord); vec3 normal = getNormal(texCoord);
@ -88,6 +90,6 @@ void main(){
ao /= float(iterations) * 4.0; ao /= float(iterations) * 4.0;
result = 1.0-ao; result = 1.0-ao;
gl_FragColor=vec4(result,result,result, 1.0); fragColor = vec4(result,result,result, 1.0);
} }

@ -18,9 +18,7 @@ MaterialDef SSAOBlur {
FragmentShader GLSL150: Common/MatDefs/SSAO/ssaoBlur15.frag FragmentShader GLSL150: Common/MatDefs/SSAO/ssaoBlur15.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
WorldViewMatrix WorldViewMatrix
Resolution
} }
Defines { Defines {
@ -35,11 +33,8 @@ MaterialDef SSAOBlur {
VertexShader GLSL120: Common/MatDefs/Post/Post.vert VertexShader GLSL120: Common/MatDefs/Post/Post.vert
FragmentShader GLSL120: Common/MatDefs/SSAO/ssaoBlur.frag FragmentShader GLSL120: Common/MatDefs/SSAO/ssaoBlur.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
WorldViewMatrix WorldViewMatrix
Resolution
} }
Defines { Defines {

@ -3,7 +3,6 @@
uniform COLORTEXTURE m_Texture; uniform COLORTEXTURE m_Texture;
uniform DEPTHTEXTURE m_DepthTexture; uniform DEPTHTEXTURE m_DepthTexture;
uniform sampler2D m_SSAOMap; uniform sampler2D m_SSAOMap;
uniform vec2 g_Resolution;
uniform bool m_UseOnlyAo; uniform bool m_UseOnlyAo;
uniform bool m_UseAo; uniform bool m_UseAo;
uniform float m_XScale; uniform float m_XScale;
@ -33,33 +32,6 @@ float readDepth(in vec2 uv){
const float epsilon = 0.005; 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 convolutionFilter(){
vec4 sum = vec4(0.0); vec4 sum = vec4(0.0);

@ -56,7 +56,6 @@ MaterialDef Advanced Water {
FragmentShader GLSL150 : Common/MatDefs/Water/Water15.frag FragmentShader GLSL150 : Common/MatDefs/Water/Water15.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
} }
Defines { Defines {
@ -78,7 +77,6 @@ MaterialDef Advanced Water {
FragmentShader GLSL120 : Common/MatDefs/Water/Water.frag FragmentShader GLSL120 : Common/MatDefs/Water/Water.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix
} }
Defines { Defines {
ENABLE_RIPPLES : UseRipples ENABLE_RIPPLES : UseRipples

@ -63,8 +63,7 @@ public class FilterPostProcessor implements SceneProcessor, Savable {
private Texture2D filterTexture; private Texture2D filterTexture;
private Texture2D depthTexture; private Texture2D depthTexture;
private List<Filter> filters = new ArrayList<Filter>(); private List<Filter> filters = new ArrayList<Filter>();
private AssetManager assetManager; private AssetManager assetManager;
private Camera filterCam = new Camera(1, 1);
private Picture fsQuad; private Picture fsQuad;
private boolean computeDepth = false; private boolean computeDepth = false;
private FrameBuffer outputBuffer; private FrameBuffer outputBuffer;
@ -78,7 +77,7 @@ public class FilterPostProcessor implements SceneProcessor, Savable {
private int originalHeight; private int originalHeight;
private int lastFilterIndex = -1; private int lastFilterIndex = -1;
private boolean cameraInit = false; private boolean cameraInit = false;
private boolean clearColor= true; private boolean multiView = false;
/** /**
* Create a FilterProcessor * Create a FilterProcessor
@ -135,7 +134,9 @@ public class FilterPostProcessor implements SceneProcessor, Savable {
renderer = rm.getRenderer(); renderer = rm.getRenderer();
viewPort = vp; viewPort = vp;
fsQuad = new Picture("filter full screen quad"); fsQuad = new Picture("filter full screen quad");
fsQuad.setWidth(1);
fsQuad.setHeight(1);
Camera cam = vp.getCamera(); Camera cam = vp.getCamera();
//save view port diensions //save view port diensions
@ -176,29 +177,23 @@ public class FilterPostProcessor implements SceneProcessor, Savable {
* @param mat * @param mat
*/ */
private void renderProcessing(Renderer r, FrameBuffer buff, Material mat) { private void renderProcessing(Renderer r, FrameBuffer buff, Material mat) {
if (buff == outputBuffer) { if (buff == outputBuffer && multiView) {
fsQuad.setWidth(width); viewPort.getCamera().resize(originalWidth, originalHeight, false);
fsQuad.setHeight(height); viewPort.getCamera().setViewPort(left, right, bottom, top);
filterCam.resize(originalWidth, originalHeight, true); viewPort.getCamera().update();
fsQuad.setPosition(left * originalWidth, bottom * originalHeight); renderManager.setCamera( viewPort.getCamera(), false);
} else {
fsQuad.setWidth(buff.getWidth());
fsQuad.setHeight(buff.getHeight());
filterCam.resize(buff.getWidth(), buff.getHeight(), true);
fsQuad.setPosition(0, 0);
} }
if (mat.getAdditionalRenderState().isDepthWrite()) { if (mat.getAdditionalRenderState().isDepthWrite()) {
mat.getAdditionalRenderState().setDepthTest(false); mat.getAdditionalRenderState().setDepthTest(false);
mat.getAdditionalRenderState().setDepthWrite(false); mat.getAdditionalRenderState().setDepthWrite(false);
} }
fsQuad.setMaterial(mat); fsQuad.setMaterial(mat);
fsQuad.updateGeometricState(); fsQuad.updateGeometricState();
renderManager.setCamera(filterCam, true);
r.setFrameBuffer(buff); r.setFrameBuffer(buff);
r.clearBuffers(clearColor, true, true); r.clearBuffers(true, true, true);
renderManager.renderGeometry(fsQuad); renderManager.renderGeometry(fsQuad);
} }
@ -216,8 +211,7 @@ public class FilterPostProcessor implements SceneProcessor, Savable {
} }
} }
} }
Picture pic = new Picture("debug");
/** /**
* iterate through the filter list and renders filters * iterate through the filter list and renders filters
@ -317,11 +311,14 @@ public class FilterPostProcessor implements SceneProcessor, Savable {
} else { } else {
viewPort.setOutputFrameBuffer(renderFrameBuffer); viewPort.setOutputFrameBuffer(renderFrameBuffer);
} }
//init of the camera if it wasn't already //if we are ina multiview situation we need to resize the camera
if (!cameraInit) { //to the viewportsize so that the backbuffer is rendered correctly
viewPort.getCamera().resize(width, height, true); if (multiView) {
viewPort.getCamera().resize(width, height, false);
viewPort.getCamera().setViewPort(0, 1, 0, 1); viewPort.getCamera().setViewPort(0, 1, 0, 1);
} viewPort.getCamera().update();
renderManager.setCamera(viewPort.getCamera(), false);
}
} }
for (Iterator<Filter> it = filters.iterator(); it.hasNext();) { for (Iterator<Filter> it = filters.iterator(); it.hasNext();) {
@ -376,8 +373,8 @@ public class FilterPostProcessor implements SceneProcessor, Savable {
} }
public void reshape(ViewPort vp, int w, int h) { public void reshape(ViewPort vp, int w, int h) {
//this has no effect at first init but is useful when resizing the canvas with multi views
Camera cam = vp.getCamera(); Camera cam = vp.getCamera();
//this has no effect at first init but is useful when resizing the canvas with multi views
cam.setViewPort(left, right, bottom, top); cam.setViewPort(left, right, bottom, top);
//resizing the camera to fit the new viewport and saving original dimensions //resizing the camera to fit the new viewport and saving original dimensions
cam.resize(w, h, false); cam.resize(w, h, false);
@ -387,24 +384,20 @@ public class FilterPostProcessor implements SceneProcessor, Savable {
bottom = cam.getViewPortBottom(); bottom = cam.getViewPortBottom();
originalWidth = w; originalWidth = w;
originalHeight = h; originalHeight = h;
cam.setViewPort(0, 1, 0, 1);
//computing real dimension of the viewport and resizing he camera //computing real dimension of the viewport and resizing the camera
width = (int) (w * (Math.abs(right - left))); width = (int) (w * (Math.abs(right - left)));
height = (int) (h * (Math.abs(bottom - top))); height = (int) (h * (Math.abs(bottom - top)));
width = Math.max(1, width); width = Math.max(1, width);
height = Math.max(1, height); height = Math.max(1, height);
//Testing original versus actual viewport dimension. //Testing original versus actual viewport dimension.
//If they are different we are in a multiview situation and color from other view port must not be cleared. //If they are different we are in a multiview situation and
//However, not clearing the color can cause issues when AlphaToCoverage is active on the renderer. //camera must be handled differently
if(originalWidth!=width || originalHeight!=height){ if(originalWidth!=width || originalHeight!=height){
clearColor = false; multiView = true;
}else{
clearColor = true;
} }
cam.resize(width, height, false);
cameraInit = true; cameraInit = true;
computeDepth = false; computeDepth = false;

Loading…
Cancel
Save