Ambient occlusion for dummies
category: code [glöplog]
kb_: You're right. I initially jacked this code from somewhere else, and this is indeed not an axial projection. My bad, and thanks for the correction.
So let's try that again, this time with kb's correction:
Code:
vec3 randomSpherePoint()
{
float s = random() * 3.1415926 * 2.0;
float t = random() * 2.0 - 1.0;
return vec3(vec2(sin(s), cos(s)) * sqrt(1.0 - t * t), t);
}
vec3 randomHemispherePoint(vec3 dir)
{
vec3 v = randomSpherePoint();
return v * sign(dot(v, dir))
}
Btw, I didn't actually read the paper, I just asked a co-worker that was a bit more math-savvy than me when I needed it. Clearly I missed an important detail. Seems my test-case for this wasn't too good :P
Tigrou: I'm not sure if you're talking about a screen space AO or not, but if you do, I have implemented a SSAO based on this in my demo. I actually created a youtube that shows the SSAO render stage by itself.
Few things:
Ping me if you need help.
Few things:
- The basic method that is used in the sample is very different from what you have suggested. It is more about sampling the normals around the target fragment.
- There are more modern ways to compute SSAO. mostly, the difference between the methods is the required number of samples per pixel for achieving a good result.
- The parameters values used in the example are really bad. You should really understand what each of those parameters is suppose to do and tweak it until you're happy.
Ping me if you need help.
Nah, this is about proper AO, not screen-space hacks ;)
@TML : no, this is not SSAO. I am playing with a ray tracer. Thanks anyway .
oups, didn't see kusma answer :)
again, please keep in mind that the simple formulas posted here only give half of the solution: you still have to orient the hemisphere (i.e. the resulting vector) according to the surface normal!
spike: No, that's already taken care of by "v * sign(dot(v, dir))". In fact, that's the whole point of randomHemispherePoint rather than just randomSpherePoint.
sin and cos? is that expensive? i read it's micro coded in the gpu but it's looks expensive.
i thought about adding 2d scattering to the normal and renormalize the result. looks like this is what uniform hemisperical described. the distribution is a lil uneven and it's a lil lost in space. it's "a normal relative" space (whatever that is called). i dunno how this transforms into screen or whatever space.
other idea was to add a uniform noise [-1,1] cubic in 3d and add the normal again to kill the backfacing directions? and renormalize as the expensive operation in it tho. i'm not sure if that works either.
just stupid ideas. :)
i thought about adding 2d scattering to the normal and renormalize the result. looks like this is what uniform hemisperical described. the distribution is a lil uneven and it's a lil lost in space. it's "a normal relative" space (whatever that is called). i dunno how this transforms into screen or whatever space.
other idea was to add a uniform noise [-1,1] cubic in 3d and add the normal again to kill the backfacing directions? and renormalize as the expensive operation in it tho. i'm not sure if that works either.
just stupid ideas. :)
Just some buzzwords & resources you might want to have a look at:
Cosine hemisphere sampling (just google it.)
Orthonormal_basis (ONB)
Lots of integrals.
And this might be exactly what you are looking for.
IIRC in NV OptiX is even a AO sample using cosine hemisphere sampling for AO with source.
Cosine hemisphere sampling (just google it.)
Orthonormal_basis (ONB)
Lots of integrals.
And this might be exactly what you are looking for.
IIRC in NV OptiX is even a AO sample using cosine hemisphere sampling for AO with source.