From 961219a091640f3afd03ad8c8eb74fa8c4b1ebbf Mon Sep 17 00:00:00 2001 From: Frederic Bouvier Date: Wed, 9 May 2012 23:52:26 +0200 Subject: [PATCH] Add ambient occlusion to default pipeline --- Effects/ambient.eff | 10 ++++++ Effects/default-pipeline.xml | 69 ++++++++++++++++++++++++++++++++++++ Effects/display.eff | 10 ++++++ Shaders/ambient.frag | 8 ++--- Shaders/display.frag | 4 ++- 5 files changed, 96 insertions(+), 5 deletions(-) diff --git a/Effects/ambient.eff b/Effects/ambient.eff index 4ead836b6..e7ccbb428 100644 --- a/Effects/ambient.eff +++ b/Effects/ambient.eff @@ -31,6 +31,11 @@ buffer spec-emis + + 4 + buffer + ao-3 + Shaders/ambient.vert Shaders/ambient.frag @@ -55,6 +60,11 @@ sampler-2d 3 + + ao_tex + sampler-2d + 4 + geometry + 0 depth depth @@ -86,13 +117,49 @@ shadow + 1 depth shadow + + ssao-1 + fullscreen + 2 + Effects/ssao + true + 0.25 + + color0 + ao-1 + + + + ssao-2 + fullscreen + 3 + Effects/ssao-blur-1 + 0.25 + + color0 + ao-2 + + + + ssao-3 + fullscreen + 4 + Effects/ssao-blur-2 + 0.25 + + color0 + ao-3 + + lighting + 50 depth depth @@ -104,5 +171,7 @@ display + 99 + Effects/display diff --git a/Effects/display.eff b/Effects/display.eff index 3ab968dc5..facd16743 100644 --- a/Effects/display.eff +++ b/Effects/display.eff @@ -36,6 +36,11 @@ buffer lighting + + 5 + buffer + ao-3 + Shaders/display.vert Shaders/display.frag @@ -65,6 +70,11 @@ sampler-2d 4 + + ao_tex + sampler-2d + 5 + exposure float diff --git a/Shaders/ambient.frag b/Shaders/ambient.frag index d6596a1d9..4d7c669a2 100644 --- a/Shaders/ambient.frag +++ b/Shaders/ambient.frag @@ -1,5 +1,5 @@ uniform sampler2D color_tex; -//uniform sampler2D ao_tex; +uniform sampler2D ao_tex; uniform sampler2D normal_tex; uniform sampler2D spec_emis_tex; uniform vec4 fg_SunAmbientColor; @@ -9,7 +9,7 @@ void main() { if ( initialized < 0.1 ) discard; vec3 tcolor = texture2D( color_tex, coords ).rgb; -// float ao = texture2D( ao_tex, coords ).r; -// gl_FragColor = vec4(tcolor*fg_SunAmbientColor.rgb*ao, 1.0); - gl_FragColor = vec4(tcolor*fg_SunAmbientColor.rgb, 1.0); + float ao = texture2D( ao_tex, coords ).r; + gl_FragColor = vec4(tcolor*fg_SunAmbientColor.rgb*ao, 1.0); +// gl_FragColor = vec4(tcolor*fg_SunAmbientColor.rgb, 1.0); } diff --git a/Shaders/display.frag b/Shaders/display.frag index acb54c65e..8501d340c 100644 --- a/Shaders/display.frag +++ b/Shaders/display.frag @@ -4,7 +4,7 @@ uniform sampler2D color_tex; uniform sampler2D specular_tex; uniform sampler2D lighting_tex; //uniform sampler2D bloom_tex; -//uniform sampler2D ao_tex; +uniform sampler2D ao_tex; uniform float exposure; uniform bool showBuffers; uniform bool fg_DepthInColor; @@ -29,6 +29,8 @@ void main() { color = texture2D( color_tex, (coords - vec2( 0.8, 0.0 )) * 5.0 ); } else if (coords.x < 0.2 && coords.y >= 0.8 && fg_DepthInColor) { color = texture2D( depth_tex, (coords - vec2( 0.0, 0.8 )) * 5.0 ); + } else if (coords.x < 0.2 && coords.y >= 0.8) { + color = texture2D( ao_tex, (coords - vec2( 0.0, 0.8 )) * 5.0 ); } else { color = texture2D( lighting_tex, coords ) /* + texture2D( bloom_tex, coords ) */; //color = vec4( HDR( color.rgb ), 1.0 );