1
0
Fork 0

Add ambient occlusion to default pipeline

This commit is contained in:
Frederic Bouvier 2012-05-09 23:52:26 +02:00
parent 140263d611
commit 961219a091
5 changed files with 96 additions and 5 deletions

View file

@ -31,6 +31,11 @@
<type>buffer</type> <type>buffer</type>
<name>spec-emis</name> <name>spec-emis</name>
</texture-unit> </texture-unit>
<texture-unit>
<unit>4</unit>
<type>buffer</type>
<name>ao-3</name>
</texture-unit>
<program> <program>
<vertex-shader>Shaders/ambient.vert</vertex-shader> <vertex-shader>Shaders/ambient.vert</vertex-shader>
<fragment-shader>Shaders/ambient.frag</fragment-shader> <fragment-shader>Shaders/ambient.frag</fragment-shader>
@ -55,6 +60,11 @@
<type>sampler-2d</type> <type>sampler-2d</type>
<value type="int">3</value> <value type="int">3</value>
</uniform> </uniform>
<uniform>
<name>ao_tex</name>
<type>sampler-2d</type>
<value type="int">4</value>
</uniform>
<!-- The following uniforms are automatically defined and initialized : <!-- The following uniforms are automatically defined and initialized :
- fg_SunAmbientColor - fg_SunAmbientColor
- fg_SunDiffuseColor - fg_SunDiffuseColor

View file

@ -53,6 +53,36 @@
<scale-factor>1.0</scale-factor> <scale-factor>1.0</scale-factor>
<wrap-mode>clamp-to-border</wrap-mode> <wrap-mode>clamp-to-border</wrap-mode>
</buffer> </buffer>
<buffer>
<name>ao-1</name>
<internal-format>rgba8</internal-format>
<source-format>rgba</source-format>
<source-type>unsigned-byte</source-type>
<width>screen</width>
<height>screen</height>
<scale-factor>0.25</scale-factor>
<wrap-mode>clamp-to-border</wrap-mode>
</buffer>
<buffer>
<name>ao-2</name>
<internal-format>rgba8</internal-format>
<source-format>rgba</source-format>
<source-type>unsigned-byte</source-type>
<width>screen</width>
<height>screen</height>
<scale-factor>0.25</scale-factor>
<wrap-mode>clamp-to-border</wrap-mode>
</buffer>
<buffer>
<name>ao-3</name>
<internal-format>rgba8</internal-format>
<source-format>rgba</source-format>
<source-type>unsigned-byte</source-type>
<width>screen</width>
<height>screen</height>
<scale-factor>0.25</scale-factor>
<wrap-mode>clamp-to-border</wrap-mode>
</buffer>
<buffer> <buffer>
<name>lighting</name> <name>lighting</name>
<internal-format>rgba8</internal-format> <internal-format>rgba8</internal-format>
@ -67,6 +97,7 @@
<!-- STAGES --> <!-- STAGES -->
<stage> <stage>
<name>geometry</name> <name>geometry</name>
<order-num>0</order-num>
<attachment> <attachment>
<component>depth</component> <component>depth</component>
<buffer>depth</buffer> <buffer>depth</buffer>
@ -86,13 +117,49 @@
</stage> </stage>
<stage> <stage>
<name>shadow</name> <name>shadow</name>
<order-num>1</order-num>
<attachment> <attachment>
<component>depth</component> <component>depth</component>
<buffer>shadow</buffer> <buffer>shadow</buffer>
</attachment> </attachment>
</stage> </stage>
<stage>
<name>ssao-1</name>
<type>fullscreen</type>
<order-num>2</order-num>
<effect>Effects/ssao</effect>
<needs-du-dv>true</needs-du-dv>
<scale-factor>0.25</scale-factor>
<attachment>
<component>color0</component>
<buffer>ao-1</buffer>
</attachment>
</stage>
<stage>
<name>ssao-2</name>
<type>fullscreen</type>
<order-num>3</order-num>
<effect>Effects/ssao-blur-1</effect>
<scale-factor>0.25</scale-factor>
<attachment>
<component>color0</component>
<buffer>ao-2</buffer>
</attachment>
</stage>
<stage>
<name>ssao-3</name>
<type>fullscreen</type>
<order-num>4</order-num>
<effect>Effects/ssao-blur-2</effect>
<scale-factor>0.25</scale-factor>
<attachment>
<component>color0</component>
<buffer>ao-3</buffer>
</attachment>
</stage>
<stage> <stage>
<name>lighting</name> <name>lighting</name>
<order-num>50</order-num>
<attachment> <attachment>
<component>depth</component> <component>depth</component>
<buffer>depth</buffer> <buffer>depth</buffer>
@ -104,5 +171,7 @@
</stage> </stage>
<stage> <stage>
<name>display</name> <name>display</name>
<order-num>99</order-num>
<effect>Effects/display</effect>
</stage> </stage>
</PropertyList> </PropertyList>

View file

@ -36,6 +36,11 @@
<type>buffer</type> <type>buffer</type>
<name>lighting</name> <name>lighting</name>
</texture-unit> </texture-unit>
<texture-unit>
<unit>5</unit>
<type>buffer</type>
<name>ao-3</name>
</texture-unit>
<program> <program>
<vertex-shader>Shaders/display.vert</vertex-shader> <vertex-shader>Shaders/display.vert</vertex-shader>
<fragment-shader>Shaders/display.frag</fragment-shader> <fragment-shader>Shaders/display.frag</fragment-shader>
@ -65,6 +70,11 @@
<type>sampler-2d</type> <type>sampler-2d</type>
<value type="int">4</value> <value type="int">4</value>
</uniform> </uniform>
<uniform>
<name>ao_tex</name>
<type>sampler-2d</type>
<value type="int">5</value>
</uniform>
<uniform> <uniform>
<name>exposure</name> <name>exposure</name>
<type>float</type> <type>float</type>

View file

@ -1,5 +1,5 @@
uniform sampler2D color_tex; uniform sampler2D color_tex;
//uniform sampler2D ao_tex; uniform sampler2D ao_tex;
uniform sampler2D normal_tex; uniform sampler2D normal_tex;
uniform sampler2D spec_emis_tex; uniform sampler2D spec_emis_tex;
uniform vec4 fg_SunAmbientColor; uniform vec4 fg_SunAmbientColor;
@ -9,7 +9,7 @@ void main() {
if ( initialized < 0.1 ) if ( initialized < 0.1 )
discard; discard;
vec3 tcolor = texture2D( color_tex, coords ).rgb; vec3 tcolor = texture2D( color_tex, coords ).rgb;
// float ao = texture2D( ao_tex, coords ).r; float ao = texture2D( ao_tex, coords ).r;
// gl_FragColor = vec4(tcolor*fg_SunAmbientColor.rgb*ao, 1.0); gl_FragColor = vec4(tcolor*fg_SunAmbientColor.rgb*ao, 1.0);
gl_FragColor = vec4(tcolor*fg_SunAmbientColor.rgb, 1.0); // gl_FragColor = vec4(tcolor*fg_SunAmbientColor.rgb, 1.0);
} }

View file

@ -4,7 +4,7 @@ uniform sampler2D color_tex;
uniform sampler2D specular_tex; uniform sampler2D specular_tex;
uniform sampler2D lighting_tex; uniform sampler2D lighting_tex;
//uniform sampler2D bloom_tex; //uniform sampler2D bloom_tex;
//uniform sampler2D ao_tex; uniform sampler2D ao_tex;
uniform float exposure; uniform float exposure;
uniform bool showBuffers; uniform bool showBuffers;
uniform bool fg_DepthInColor; uniform bool fg_DepthInColor;
@ -29,6 +29,8 @@ void main() {
color = texture2D( color_tex, (coords - vec2( 0.8, 0.0 )) * 5.0 ); color = texture2D( color_tex, (coords - vec2( 0.8, 0.0 )) * 5.0 );
} else if (coords.x < 0.2 && coords.y >= 0.8 && fg_DepthInColor) { } else if (coords.x < 0.2 && coords.y >= 0.8 && fg_DepthInColor) {
color = texture2D( depth_tex, (coords - vec2( 0.0, 0.8 )) * 5.0 ); 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 { } else {
color = texture2D( lighting_tex, coords ) /* + texture2D( bloom_tex, coords ) */; color = texture2D( lighting_tex, coords ) /* + texture2D( bloom_tex, coords ) */;
//color = vec4( HDR( color.rgb ), 1.0 ); //color = vec4( HDR( color.rgb ), 1.0 );