# Not Quite "Real Time" Ambient Oclussion!!! Help!!!!!

## Recommended Posts

rohith291991    114
struct ZVertexToPixel
{
float4 Position     : POSITION;
float4 Position2D    : TEXCOORD0;
};

struct ZPixelToFrame
{
float4 Color : COLOR0;
};

struct AOVertexToPixel
{
float4 Position     : POSITION;
float4 Position2D    : TEXCOORD0;
};

struct AOPixelToFrame
{
float4 Color : COLOR0;
};

float4x4 xViewProjection;
Texture xFrame;
Texture xRand;
float xMaxDepth=40.0f;

sampler ColoredTextureSampler = sampler_state { texture = <xFrame> ; magfilter

mirror;};

sampler Rand = sampler_state { texture = <xRand> ; magfilter = POINT;

ZVertexToPixel Z_VS( float4 inPos : POSITION)
{
ZVertexToPixel Output = (ZVertexToPixel)0;
Output.Position = mul(inPos, xViewProjection);
Output.Position2D = Output.Position;

return Output;
}

ZPixelToFrame Z_PS(ZVertexToPixel PSIn)
{
ZPixelToFrame Output = (ZPixelToFrame)0;

Output.Color = PSIn.Position2D.w/xMaxDepth;

return Output;
}

AOVertexToPixel AO_VS( float4 inPos : POSITION)
{
AOVertexToPixel Output = (AOVertexToPixel)0;
Output.Position = mul(inPos, xViewProjection);
Output.Position2D = Output.Position;

return Output;
}

AOPixelToFrame AO_PS(AOVertexToPixel PSIn)
{
AOPixelToFrame Output = (AOPixelToFrame)0;
float2 ProjectedTexCoords;
ProjectedTexCoords.x = PSIn.Position2D.x/PSIn.Position2D.w/2.0f +0.5f;
ProjectedTexCoords.y= -PSIn.Position2D.y/PSIn.Position2D.w/2.0f +0.5f;
float4 Temp=0;
int i;
int j;
float2 Temp2;
Temp2=ProjectedTexCoords;

float4 b=tex2D(ColoredTextureSampler,ProjectedTexCoords);

for(i=-1;i<2;i++)
{
for(j=-1;j<2;j++)
{
Temp2.y+=i*fmod(tex2D(Rand,ProjectedTexCoords+i*cos(i)*0.233),0.04);
Temp2.x+=j*fmod(tex2D(Rand,ProjectedTexCoords+i/sin(j*0.3455)),0.04);
float a=length(b)-(length(tex2D(ColoredTextureSampler,Temp2)));
if(a>0.001&&a<0.27)
Temp+=b-tex2D(ColoredTextureSampler,Temp2);
}

}
Temp2=ProjectedTexCoords;

for(i=-1;i<2;i++)
{
for(j=-1;j<2;j++)
{
Temp2.y+=2*i*fmod(tex2D(Rand,ProjectedTexCoords+i*cos(i)*0.233),0.04);
Temp2.x+=2*j*fmod(tex2D(Rand,ProjectedTexCoords+i/sin(j*0.3455)),0.04);
float a=length(b)-(length(tex2D(ColoredTextureSampler,Temp2)));
if(a>0.002&&a<0.4)
Temp+=b-tex2D(ColoredTextureSampler,Temp2);
}

}

Output.Color = 1-Temp/1.4;
return Output;
}

technique RTAO
{
pass Pass0
{
}
pass Pass1
{
}

}


here are some pics: without double radius samples: (only 4 samples) <br /><br /> <br /><br /> <br /><br /> <br /><br /> With the double radius samples : (4+4=8 samples) <br /><br /> <br /><br /> with 8 samples plus selective gaussian blur in GIMP(probably what it would look like after a blur pass) <br /><br /> PS: Im running this on a geforce 6600 vanilla... what kind of performance can i expect from it anyway??

##### Share on other sites
rohith291991    114

##### Share on other sites
rohith291991    114
Come on guys !!! PLzz help!!

##### Share on other sites
phresnel    953
I think with your childish "OMFG hlepz pls!!one" and your try to raise attention by posting that every hour you just disqualified yourself. The probable reason why nobody helps at the moment is that, voila, nobody *can* help at the moment (maybe asleep, at work, or, as for me, lack of knowledge).

Bump your threads, if you want. But then just every 1-3 days, otherwise most people get pissed off, especially because of style of writing.

##### Share on other sites
rohith291991    114
um i think u saw the times but not the date... those two messages were posted more than just an "hour" apart... as for the childish tone ,well i aint exactly 40 am i?? anyway will try to post better..

##### Share on other sites
phresnel    953
Quote:
 um i think u saw the times but not the date...
Quote:
 Posted - 12/17/2008 3:32:24 PM
Quote:
 Posted - 12/17/2008 4:47:05 PM

--

Quote:
 well i aint exactly 40 am i??

I guessed so.

Some hints:

u -> you
!!!!one -> !
?????// -> ?
Thanks in forward! -> <nothing> (it implies you are not going to answer replies)

As a rule of thumb, start sentences with uppercase letters (though this is not a deep requirement). Never write ALL CAPS ON (it's like yelling). A good alternative is to write in italics, or to make something more outstanding, in bold letters.

But: You're already doing good with the paragraphs.

Fear not, worse examples exist ;)

##### Share on other sites
FeverGames    126
Also if you are new to DirectX and have only been learning and trying for about 11 days I'd suggest reading a bit more about DirectX itself and learning more about it's internal workings before heading to more difficult subjects such as SSAO and other kinds of shader techniques. But that's just my opinion.

##### Share on other sites
chris_e    122
Quote:
 Original post by rohith291991...i first load the depth map into a texture and then on a subsequent pass with i sample the z values of the surrounding pixels with a particular radius and calculaate their effects(4 samples for this) and then i subsequently double the radius and again randomly sample 4 pixels with slightly different settings as to how they affect the shade of this pixel. hence a total of 4+4 = 8 samples per pixel... for the randomness of the sampling i use a random noise texture created in GIMP.. to ensure that the values are within a definite radius i use fmod.....With the double radius samples : (4+4=8 samples)PS: Im running this on a geforce 6600 vanilla... what kind of performance can i expect from it anyway??

There are two loops, each samples texture 3-4 times in inner loop thus giving you total number of samples much higher than 8.

// 3 times
for(i=-1;i<2;i++)
{
// 3 times
for(j=-1;j<2;j++)
{
// 2 texture lookups
Temp2.y+=i*fmod(tex2D(Rand,ProjectedTexCoords+i*cos(i)*0.233),0.04);
Temp2.x+=j*fmod(tex2D(Rand,ProjectedTexCoords+i/sin(j*0.3455)),0.04);

// one more texture lookup
float a=length(b)-(length(tex2D(ColoredTextureSampler,Temp2)));

// and even one more
if(a>0.001&&a<0.27)
Temp+=b-tex2D(ColoredTextureSampler,Temp2);
}
}

So basically, you have 3x3 iterations, 3-4 samples per iteration ~= 27-36 samples, two times... which is somewhere between 54 and 72 tex2Ds per pixel!

chris

##### Share on other sites
And those samples are complex dependent reads... on an ancient card like GeForce 6 this shader is a recipe for slowness(it would be slow on anything though), unless you minimize the sample numbers.. most SSAO methods only do about 8-16 samples.

##### Share on other sites
Jason Z    6436
If you are interested in SSAO, take a look at the environmental section of the D3D10 book linked in my signature. There is a chapter on SSAO, with a sample implementation provided for you to reference and compare with your own.