Page 1 of 3 1 2 3 >
Topic Options
Rate This Topic
#236698 - 04/05/08 06:05 PM Screen-Space Ambient Occlusion
Leadwerks Offline
Regular Contributor
***

Registered: 03/11/07
Posts: 410
Loc: California
The results of this effect are pretty awesome, and it seems like a self-contained post-processing effect. Has anyone done any work with this, or are there any GLSL examples around?:
http://www.gamedev.net/community/forums/topic.asp?topic_id=463075

Top
#236700 - 04/05/08 06:34 PM Re: Screen-Space Ambient Occlusion [Re: Leadwerks]
sqrt[-1] Offline
Frequent Contributor
*****

Registered: 06/05/02
Posts: 910
Loc: Australia
Also read this for lots of useful links:
http://levelofdetail.wordpress.com/2008/02/10/2007-the-year-ssao-broke/

You can have a look at the Crysis Cg shader source if you have the game (or demo)

Top
#236702 - 04/05/08 11:32 PM Re: Screen-Space Ambient Occlusion [Re: sqrt[-1]]
havokentity Offline
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
_________________________
-Rajesh
http://rajeshdmonte.blogspot.com/

Top
#236718 - 04/06/08 01:42 PM Re: Screen-Space Ambient Occlusion [Re: havokentity]
elvis Offline
Newbie

Registered: 03/11/08
Posts: 7
I've been made an implementation about this technique.
check out my blog:

http://gamedusa.blogspot.com

For 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]
elvis Offline
Newbie

Registered: 03/11/08
Posts: 7
I've been made an implementation about this technique.
check out my blog:

http://gamedusa.blogspot.com

For some GLSL code you can go to RGBA homepage of Iņigo Quilez.

Top
#236738 - 04/07/08 02:25 PM Re: Screen-Space Ambient Occlusion [Re: elvis]
Leadwerks Offline
Regular Contributor
***

Registered: 03/11/07
Posts: 410
Loc: California
Iņigo's code looks good, but he uses an extra render target to output a linear depth, which I think is completely unnecessary. I want to write a shader that will just work on any generic depth buffer...then people can just plug it into their engine, and BOOM! instant real-time GI (sort of). ;\)


Edited by Leadwerks (04/07/08 02:26 PM)

Top
#236743 - 04/07/08 02:45 PM Re: Screen-Space Ambient Occlusion [Re: Leadwerks]
Leadwerks Offline
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]
Leadwerks Offline
Regular Contributor
***

Registered: 03/11/07
Posts: 410
Loc: California
Well, right now this is basically just a soft outline shader:

 Code:
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]
Leadwerks Offline
Regular Contributor
***

Registered: 03/11/07
Posts: 410
Loc: California
Here is it, the shader you have been waiting for, perhaps dreaming of.


vert:
 Code:
varying vec2 texCoord;

void main(void) {
	gl_Position = ftransform();
	texCoord=gl_MultiTexCoord0.xy;
	gl_FrontColor = gl_Color;
}


frag:
 Code:
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]
Vexator Offline
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?
_________________________
www.wunderwerk.blogspot.com

Top
Page 1 of 3 1 2 3 >


Moderator:  Tom Nuydens, Zengar 
Who's Online
8 registered (peterfilm, Koter, marshats, AGL_Music, Abdallah DIB, rats_ogl, celtics, AstroBistro), 33 Guests and 93 Spiders online.
Key: Admin, Global Mod, Mod
Newest Members
Nonozor, Maire Nicolas, minakshee, Koter, pixelwrangler
24934 Registered Users
Top Posters (30 Days)
Alfonse Reinheart 152
ZbuffeR 92
Dark Photon 73
marshats 47
Brolingstanz 44
Ilian Dinev 41
Iulian B 38
Stephen A 37
Kip Warner 28
devdept 26
skynet 23
Pierre 23
igorgiv 23
DarkShadow44 23
Yann LE PETITCORPS 22
scratt 21
Abdallah DIB 21
Aleksandar 20
Pierre Boudier 19
mikeynovemberoscar 19
Forum Stats
24934 Members
12 Forums
52392 Topics
271545 Posts

Max Online: 482 @ 08/11/08 06:19 PM