pouët.net

Go to bottom

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.
added on the 2013-10-02 14:26:18 by kusma kusma
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)) }
added on the 2013-10-02 14:31:15 by kusma kusma
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
added on the 2013-10-02 14:33:59 by kusma kusma
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:

  1. 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.
  2. 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.
  3. 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.
added on the 2013-10-02 14:54:02 by TLM TLM
Nah, this is about proper AO, not screen-space hacks ;)
added on the 2013-10-02 15:16:03 by kusma kusma
@TML : no, this is not SSAO. I am playing with a ray tracer. Thanks anyway .
added on the 2013-10-02 15:29:35 by Tigrou Tigrou
oups, didn't see kusma answer :)
added on the 2013-10-02 15:39:32 by Tigrou Tigrou
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!
added on the 2013-10-02 15:49:57 by arm1n arm1n
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.
added on the 2013-10-02 17:48:22 by kusma kusma
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. :)
added on the 2013-10-02 18:27:29 by yumeji yumeji
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.
added on the 2013-10-02 19:06:14 by las las

login

Go to top