#236702 - 04/05/08 11:32 PM
Re: Screen-Space Ambient Occlusion
[Re: sqrt[-1]]
|
Newbie
Registered: 10/31/05
Posts: 26
Loc: Chennai, Tamil Nadu, India
|
Yes, I've done some experimentation. I've got good results that work over 60 fps on a 8600 GT but with ugly outlines, so I stuck with the standard way of doing it. In my first experiment, I tried it with a gaussian blurred texture, taken from the bloom pass. If anyone has any success with a gaussian blurred texture without outlines of objects, please tell me how you removed the artifacts. I've posted a small post about SSAO on my blog: http://rajeshdmonte.blogspot.com/2008/04/experiments-with-ssao-screen-space.html
|
|
Top
|
|
|
|
#236718 - 04/06/08 01:42 PM
Re: Screen-Space Ambient Occlusion
[Re: havokentity]
|
Newbie
Registered: 03/11/08
Posts: 7
|
I've been made an implementation about this technique. check out my blog: http://gamedusa.blogspot.comFor some GLSL code you can go to RGBA homepage of Iņigo Quilez.
|
|
Top
|
|
|
|
#236719 - 04/06/08 01:43 PM
Re: Screen-Space Ambient Occlusion
[Re: havokentity]
|
Newbie
Registered: 03/11/08
Posts: 7
|
I've been made an implementation about this technique. check out my blog: http://gamedusa.blogspot.comFor some GLSL code you can go to RGBA homepage of Iņigo Quilez.
|
|
Top
|
|
|
|
#236743 - 04/07/08 02:45 PM
Re: Screen-Space Ambient Occlusion
[Re: Leadwerks]
|
Regular Contributor
 
Registered: 03/11/07
Posts: 410
Loc: California
|
Well, here's code to convert the exponential depth to a linear value (thanks Humus): // Convert exponential depth value to linear depth float f=1000.0; float n = 0.1; float z = (2 * n) / (f + n - texture2D( texture0, texCoord ).x * (f - n)); I am afraid I do not understand the rest of his shader...so it's either a matter of copying everything exactly, or implementing my own method from scratch. http://rgba.scenesp.org/iq/computer/articles/ssao/ssao.htm
Edited by Leadwerks (04/07/08 02:46 PM)
|
|
Top
|
|
|
|
#236746 - 04/07/08 04:11 PM
Re: Screen-Space Ambient Occlusion
[Re: Leadwerks]
|
Regular Contributor
 
Registered: 03/11/07
Posts: 410
Loc: California
|
Well, right now this is basically just a soft outline shader: uniform sampler2D texture0;
uniform vec2 camerarange;
varying vec2 texCoord;
float readDepth( in vec2 coord ) {
return (2.0 * camerarange.x) / (camerarange.y + camerarange.x - texture2D( texture0, coord ).x * (camerarange.y - camerarange.x));
}
void main(void)
{
float depth = readDepth( texCoord );
float d;
float pw = 1.0 / 800.0 * 2.0;
float ph = 1.0 / 600.0 * 2.0;
float ao = 0.0;
float aoMultiplier=1000.0;
float depthTolerance = 0.001;
d=readDepth( vec2(texCoord.x+pw,texCoord.y+ph));
ao+=max(0.0,d-depth-depthTolerance) * aoMultiplier;
d=readDepth( vec2(texCoord.x-pw,texCoord.y+ph));
ao+=max(0.0,d-depth-depthTolerance) * aoMultiplier;
d=readDepth( vec2(texCoord.x+pw,texCoord.y-ph));
ao+=max(0.0,d-depth-depthTolerance) * aoMultiplier;
d=readDepth( vec2(texCoord.x-pw,texCoord.y-ph));
ao+=max(0.0,d-depth-depthTolerance) * aoMultiplier;
ao/=4.0;
ao=min(ao,0.25);
gl_FragColor = vec4(1.0-ao);
} Here it is multiplied by 0.5. The problem is that in very corners, the sample right next to one surface is the same depth, so it doesn't detect a difference, and it makes the corner bright. 
Edited by Leadwerks (04/07/08 04:46 PM)
|
|
Top
|
|
|
|
#236751 - 04/07/08 08:21 PM
Re: Screen-Space Ambient Occlusion
[Re: Leadwerks]
|
Regular Contributor
 
Registered: 03/11/07
Posts: 410
Loc: California
|
Here is it, the shader you have been waiting for, perhaps dreaming of.  vert: varying vec2 texCoord;
void main(void) {
gl_Position = ftransform();
texCoord=gl_MultiTexCoord0.xy;
gl_FrontColor = gl_Color;
}frag: uniform sampler2D texture0;
uniform sampler2D texture1;
uniform vec2 camerarange;
uniform vec2 screensize;
varying vec2 texCoord;
float readDepth( in vec2 coord ) {
return (2.0 * camerarange.x) / (camerarange.y + camerarange.x - texture2D( texture0, coord ).x * (camerarange.y - camerarange.x));
}
void main(void)
{
float depth = readDepth( texCoord );
float d;
float pw = 1.0 / screensize.x;
float ph = 1.0 / screensize.y;
float aoCap = 1.0;
float ao = 0.0;
float aoMultiplier=1000.0;
float depthTolerance = 0.0001;
d=readDepth( vec2(texCoord.x+pw,texCoord.y+ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
d=readDepth( vec2(texCoord.x-pw,texCoord.y+ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
d=readDepth( vec2(texCoord.x+pw,texCoord.y-ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
d=readDepth( vec2(texCoord.x-pw,texCoord.y-ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
pw*=2.0;
ph*=2.0;
aoMultiplier/=2.0;
d=readDepth( vec2(texCoord.x+pw,texCoord.y+ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
d=readDepth( vec2(texCoord.x-pw,texCoord.y+ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
d=readDepth( vec2(texCoord.x+pw,texCoord.y-ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
d=readDepth( vec2(texCoord.x-pw,texCoord.y-ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
pw*=2.0;
ph*=2.0;
aoMultiplier/=2.0;
d=readDepth( vec2(texCoord.x+pw,texCoord.y+ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
d=readDepth( vec2(texCoord.x-pw,texCoord.y+ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
d=readDepth( vec2(texCoord.x+pw,texCoord.y-ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
d=readDepth( vec2(texCoord.x-pw,texCoord.y-ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
pw*=2.0;
ph*=2.0;
aoMultiplier/=2.0;
d=readDepth( vec2(texCoord.x+pw,texCoord.y+ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
d=readDepth( vec2(texCoord.x-pw,texCoord.y+ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
d=readDepth( vec2(texCoord.x+pw,texCoord.y-ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
d=readDepth( vec2(texCoord.x-pw,texCoord.y-ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);
ao/=16.0;
gl_FragColor = vec4(1.0-ao) * texture2D(texture1,texCoord);
}Uniforms: vec2 camerarange - near and far camera range vec2 screensize - screen width and height
Edited by Leadwerks (04/07/08 08:22 PM)
|
|
Top
|
|
|
|
#236786 - 04/08/08 10:55 AM
Re: Screen-Space Ambient Occlusion
[Re: Leadwerks]
|
Regular Contributor
Registered: 07/11/05
Posts: 274
Loc: Germany
|
mh all i get are black outlines around my meshes. how do you render texture0? i pass -(gl_ModelViewMatrix*gl_Vertex) to the fragment shader and output its length. what's texture1 supposed to be? the original scene? what about the normal map Quilez uses? do i need to perform a blur pass afterwards?
|
|
Top
|
|
|
|
|
|
8 registered (peterfilm, Koter, marshats, AGL_Music, Abdallah DIB, rats_ogl, celtics, AstroBistro),
33
Guests and
93
Spiders online. |
|
Key:
Admin,
Global Mod,
Mod
|
|
24934 Members
12 Forums
52392 Topics
271545 Posts
Max Online: 482 @ 08/11/08 06:19 PM
|
|
|